Пример #1
0
        public List <int> Test()
        {
            SongModel sharedSong  = new SongModel();
            SongModel privateSong = new SongModel();

            sharedSong.SongId  = 1000;
            privateSong.SongId = 500;

            PlaylistModel playlistModel = new PlaylistModel();

            playlistModel.PlaylistId = 1;
            playlistModel.Songs.Add(new Models.BridgeModel.PlaylistSongModel()
            {
                PlaylistId = playlistModel.PlaylistId, SongId = sharedSong.SongId
            });
            playlistModel.Songs.Add(new Models.BridgeModel.PlaylistSongModel()
            {
                PlaylistId = playlistModel.PlaylistId, SongId = privateSong.SongId
            });

            PlaylistModel secondPlaylistModel = new PlaylistModel();

            secondPlaylistModel.PlaylistId = 2;
            secondPlaylistModel.Songs.Add(new Models.BridgeModel.PlaylistSongModel()
            {
                PlaylistId = secondPlaylistModel.PlaylistId, SongId = sharedSong.SongId
            });
            secondPlaylistModel.Songs.Add(new Models.BridgeModel.PlaylistSongModel()
            {
                PlaylistId = secondPlaylistModel.PlaylistId, SongId = privateSong.SongId
            });

            PlaylistModel targetPlaylistModel = new PlaylistModel();

            targetPlaylistModel.PlaylistId = 3;
            targetPlaylistModel.Songs.Add(new Models.BridgeModel.PlaylistSongModel()
            {
                PlaylistId = targetPlaylistModel.PlaylistId, SongId = sharedSong.SongId
            });

            suggestionAlgorithm.Train(new List <PlaylistModel>()
            {
                playlistModel,
                secondPlaylistModel
            });

            List <int> songs = suggestionAlgorithm.Suggset(targetPlaylistModel);

            return(songs);
        }
        public IActionResult Suggest(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Display", "SongModels"));
            }

            PlaylistModel targetPlaylistModel = _context.Playlists.Where(p => p.PlaylistId == id.Value).FirstOrDefault();

            if (targetPlaylistModel == null)
            {
                return(NotFound());
            }

            _algo.Train(_context.Playlists.Where(p => p.PlaylistId != id.Value).ToList());
            List <int>       songList   = _algo.Suggset(targetPlaylistModel);
            List <SongModel> songModels = _context.Songs.Where(s => songList.Contains(s.SongId)).ToList();

            ViewData["SongList"] = songModels;
            ViewData["Target"]   = targetPlaylistModel;
            return(View("~/Views/PlaylistModels/SuggestView.cshtml"));
        }