public PlayerSongDto GetNextSong(NextSongDto songRequest, string username = null) { using (SmartPlayerEntities context = new SmartPlayerEntities()) { var selectedSong = GetNextSong(songRequest, username, context); var songUrl = ExtractSongUrl(selectedSong); PlayerSongDto song = ExtractSongResult(username, context, selectedSong, songUrl); return song; } }
public PlayerSongDto GetSong(int songId, string username) { using(SmartPlayerEntities context = new SmartPlayerEntities()) { MusicRepository repo = new MusicRepository(context); var requestedSong = repo.GetSongById(songId); var songUrl = ExtractSongUrl(requestedSong); PlayerSongDto song = ExtractSongResult(username, context, requestedSong, songUrl); return song; } }
public void RateSong(SongRatingDto rating, string userName) { using (SmartPlayerEntities context = new SmartPlayerEntities()) { UserRepository userRepo = new UserRepository(context); User currentUser = userRepo.GetAll().First(x => x.Email == userName); context.UserSongVotes.Add(new UserSongVote() { Rating = rating.Rating, SongId = rating.SongId, UserId = currentUser.Id }); context.SaveChanges(); } }
public List<SongDto> GetAllSongs() { using(SmartPlayerEntities context = new SmartPlayerEntities()) { MusicRepository repo = new MusicRepository(context); var allSongs = repo.GetAll() .Select(x => new SongDto { Id = x.Id, SongName = x.Name }) .ToList(); return allSongs; } }
public void Store(string originalFileName, string guid) { string mediaServerUrlBase = ConfigurationManager.AppSettings["MediaServerSaveBaseUrl"]; string fullName = Path.Combine(mediaServerUrlBase, guid); using(SmartPlayerEntities context = new SmartPlayerEntities()) { MusicRepository repo = new MusicRepository(context); var allSongs = repo.GetAll() .Select(x => new AnalyzableSong { Id = x.Id, PhysicalFileName = x.Guid }) .ToList(); allSongs.ForEach(x => x.PhysicalFileName = Path.Combine(mediaServerUrlBase, x.PhysicalFileName)); List<double> correlationCoefficients = Analyzer.GetCorreleationCoefficientsFor(fullName, allSongs); Song song = new Song() { Name = originalFileName, Guid = guid }; for(int i = 0; i < correlationCoefficients.Count; i++) { song.CorrelationsAsPrimary.Add(new SongSongCorrelation { SecondarySongId = allSongs[i].Id, CorrelationScore = correlationCoefficients[i] }); } repo.Create(song); } }
public List<SongDto> SearchSong(string query) { using(SmartPlayerEntities context = new SmartPlayerEntities()) { MusicRepository repo = new MusicRepository(context); var requestedSongs = repo.SearchByTerm(query); return requestedSongs.Select(x => new SongDto() { Id = x.Id, SongName = x.Name }).ToList(); } }
private int? GetUserRatingForSong(SmartPlayerEntities context, string username, Song song) { var currentUser = default(User); if (!string.IsNullOrWhiteSpace(username)) { var userRepo = new UserRepository(context); currentUser = userRepo.GetUserByUsername(username); } var songVote = default(int?); if (currentUser != null && song.UserSongVotes.Where(x => x.UserId == currentUser.Id).Any()) { songVote = song.UserSongVotes.First(x => x.UserId == currentUser.Id).Rating; } return songVote; }
private PlayerSongDto ExtractSongResult(string username, SmartPlayerEntities context, Song requestedSong, string songUrl) { PlayerSongDto song = new PlayerSongDto() { Id = requestedSong.Id, Name = requestedSong.Name, Url = songUrl, CurrentUserVote = GetUserRatingForSong(context, username, requestedSong) }; return song; }
private static List<Song> GetRecommendedSongsForUser(string username, SmartPlayerEntities context) { var recommendedSongs = new List<Song>(); if (username != null) { UserRepository userRepo = new UserRepository(context); var userId = userRepo.GetUserByUsername(username).Id; PearsonScoreCalculator calculator = new PearsonScoreCalculator(context); recommendedSongs = calculator.GetBestSongsForUser(userId); } return recommendedSongs; }
private static Song GetNextSong(NextSongDto songRequest, string username, SmartPlayerEntities context) { MusicRepository musicRepo = new MusicRepository(context); var excludedSongIdList = songRequest.PlayedSongIds; var recommendedSongs = GetRecommendedSongsForUser(username, context); recommendedSongs = recommendedSongs.Where(x => !excludedSongIdList.Contains(x.Id)).ToList(); var similarSongs = musicRepo.GetNextSongBasedOnUserAndGrade(songRequest.CurrentSongId); similarSongs = similarSongs.Where(x => !excludedSongIdList.Contains(x.Id)).ToList(); var safetySet = new Lazy<List<Song>>(() => musicRepo.GetNextSongBasedOnUserAndGrade(songRequest.CurrentSongId, excludedSongIdList)); var selectedSong = GetNextSong(recommendedSongs, similarSongs, safetySet); return selectedSong; }
public PearsonScoreCalculator(SmartPlayerEntities context) { _context = context; }
public BaseRepository(SmartPlayerEntities context) { _context = context; }