/// <summary> /// Method that converts Business Logic Analysis Objects for API to Entity Analysis Objects for DB and vice versa /// </summary> /// <param name="sentimentAverage"></param> /// <param name="c"></param> /// <returns></returns> public async Task <Analysis1> ParseAnalysisAsync(BL.AverageSentiment sentimentAverage, BL.Creator c) { return(await Task.FromResult(new Analysis1() { Creatr = await GetCreatorByEmailAsync(c.Email), Vid = await GetVideoByURLAsync(sentimentAverage.VideoURL), AnalDate = DateTime.Now, SentAve = (decimal)sentimentAverage.AverageSentimentScore })); }
/// <summary> /// Method for adding analysis to the db /// </summary> /// <param name="sentimentAverage"></param> /// <param name="c"></param> public async Task AddAnalysisAsync(BL.AverageSentiment sentimentAverage, BL.Creator c) { if (await _context.Creator.FirstOrDefaultAsync(creator => creator.Email == c.Email) == null) { throw new CreatorDoesNotExistException(); } if (await _context.Video.FirstOrDefaultAsync(v => v.URL == sentimentAverage.VideoURL) == null) { await AddVideoAsync(sentimentAverage.VideoURL, c.ChannelName); } await _context.Analysis1.AddAsync(await _map.ParseAnalysisAsync(sentimentAverage, c)); await _context.SaveChangesAsync(); }
private static double ParseCommentThreadListResponse(CommentThreadListResponse commentThreadListResponse) { AverageSentiment averageScore = new AverageSentiment(); foreach (CommentThread commentThread in commentThreadListResponse.Items) { var comment = new YoutubeComment(); comment.AuthorName = commentThread.Snippet.TopLevelComment.Snippet.AuthorDisplayName; comment.Content = commentThread.Snippet.TopLevelComment.Snippet.TextDisplay; comment.SentimentScore = SentimentAnalysis.SelectComments(comment.Content); averageScore.CommentList.Add(comment); } averageScore.AverageSentimentScore = averageScore.CommentList.Average(c => c.SentimentScore); averageScore.VideoURL = commentThreadListResponse.Items[0].Snippet.VideoId; return(averageScore.AverageSentimentScore); }