public async Task <ActionResult <ReturnJson> > GetSearchComments(string video_id, string search, string lang = "en", int count = 25)
        {
            //var uid = User.Claims.FirstOrDefault(c => c.Type == "uid")?.Value;
            //var role = await OktaClientHelper.GetProfileDetails(uid: uid).Result;
            //Console.WriteLine(userClaims.ToList());
            //var data = _db.SavedObjects.OrderBy(o => o.VideoId).First();

            try {
                var results = await YoutubeAPI.SearchComments(video_id : video_id, search : search, lang : lang, count : count, youtube_key : _configuration["youtube_key"]);

                var srm = await _db.SearchResultsMetadata.FirstAsync();

                srm.totalSearches         = srm.totalSearches + 1;
                srm.totalCommentsSearched = srm.totalCommentsSearched + results.count;
                await _db.SaveChangesAsync();

                return(Ok(new { documents = results.comments, metadata = new { count = results.count, search = results.search, video_id = results.video_id } }));
            } catch {
                return(BadRequest("Please enter a video id"));
            }
        }
Beispiel #2
0
        public async Task <ActionResult <IList> > PostActualizerSentimentAsync([FromBody] DocsWithTime json, string score_type = "compound", bool stopword = false)
        {
            if (null != json)
            {
                Docs jsonDoc = JsonSerializer.Deserialize <Docs>(JsonSerializer.Serialize(json));

                var vaders = await VaderSentiment.VaderSentimentAnalytics(json : jsonDoc, score_type : score_type, stopword : stopword);

                var srm = await _db.SearchResultsMetadata.FirstAsync();

                srm.sentimentAPIRequests = srm.sentimentAPIRequests + jsonDoc.documents.Count;
                await _db.SaveChangesAsync();

                var originaldocument = json.documents;

                var query = vaders.Join(originaldocument,
                                        s => s.id,
                                        o => o.id,
                                        (s, o) => new {
                    id        = s.id,
                    text      = o.text,
                    score     = s.score,
                    likeCount = o.likeCount,
                    date      = o.publishedAt,
                    dayName   = o.publishedAt.DayOfWeek.ToString(),
                    month     = o.publishedAt.Month.ToString()
                });

                var DayAggregate = query.GroupBy(d => d.dayName).Select(g => new {
                    Day = g.Key,
                    //SentimentScore = g.Select(s => s.score),
                    Avg = (g.Sum(g => g.score) / g.Select(s => s.score).Count())
                });

                var MonthAggregate = query.GroupBy(d => d.month).Select(g => new {
                    Month = g.Key,
                    // SentimentScores = g.Select(s => s.score),
                    Avg = (g.Sum(g => g.score) / g.Select(s => s.score).Count())
                });

                var LikeAggregate = query.Where(l => l.likeCount > 200)
                                    .GroupBy(l => l.likeCount)
                                    .Select(s => new {
                    LikeCount = s.Key,
                    Avg       = (s.Sum(s => s.score) / s.Select(s => s.score).Count())
                }).OrderBy(l => l.LikeCount);

                //buckets group by for scatter plot


                //time series chart for comments per day

                var hourAggregate = query.GroupBy(d => d.date.Hour).Select(g => new {
                    Hour  = g.Key,
                    Avg   = (g.Sum(g => g.score) / g.Select(s => s.score).Count()),
                    Count = g.Select(s => s.id).Count()
                }).OrderBy(h => h.Hour);


                return(Ok(
                           new {
                    textanalyticsbase = query.OrderBy(q => q.date).ToList(),
                    MonthAggregate,
                    DayAggregate,
                    LikeAggregate,
                    hourAggregate
                }));
            }
            return(BadRequest("json document is null"));
        }