public IActionResult AddHashtagHistory([FromBody] HashtagHistoryModel model)
        {
            var command = new AddHashtagHistoryCommand(model);

            _commandDispatcher.Execute(command);
            return(Ok());
        }
Example #2
0
        public IActionResult GetTweetsByLocationAsync([FromQuery] string hashtag, [FromQuery] int count, [FromQuery] double latitude, [FromQuery] double longitude)
        {
            //40.730610
            //-73.935242
            var tweets = Search.SearchTweets(new SearchTweetsParameters(hashtag)
            {
                SearchType             = SearchResultType.Recent,
                MaximumNumberOfResults = count,
                TweetSearchType        = TweetSearchType.All,
                GeoCode = new GeoCode(latitude, longitude, 50, DistanceMeasure.Kilometers)
            });

            var result = _twitterService.GetSentimentAnalysisForListOfTweetWithoutComments(tweets.ToList());

            if (result.Count != 0)
            {
                var neutral  = 0;
                var positive = 0;
                var negative = 0;

                foreach (var item in result)
                {
                    if (item.SentimentObjectModel.SentimentType.Equals("Neutral"))
                    {
                        neutral++;
                    }

                    if (item.SentimentObjectModel.SentimentType.Equals("Positive"))
                    {
                        positive++;
                    }

                    if (item.SentimentObjectModel.SentimentType.Equals("Negative"))
                    {
                        negative++;
                    }
                }
                var command = new AddHashtagHistoryCommand(new HashtagHistoryModel()
                {
                    HashtagValue             = hashtag,
                    NegativeSentimentCounter = negative,
                    PositiveSentimentCounter = positive,
                    NeutralSentimentCounter  = neutral
                });
                _commandDispatcher.Execute(command);
            }
            return(Ok(result));
        }
        public IActionResult GetTweetsByHashTag(string hashtag = null)
        {
            var tweets = _twitterService.GetTweetListByHashtag(hashtag);

            var isInDb = _queryDispatcher.Execute <IsInHashtagHistoryQuery, IsInHashtagHistoryQueryResult>(new IsInHashtagHistoryQuery(hashtag));

            var sentimentAnalysisLists = _twitterService.GetSentimentAnalysisForBubbleChart(tweets);

            var command = new AddHashtagHistoryCommand(new HashtagHistoryModel()
            {
                HashtagValue             = hashtag,
                NegativeSentimentCounter = sentimentAnalysisLists.BubbleChartNegative.Count,
                PositiveSentimentCounter = sentimentAnalysisLists.BubbleChartPositive.Count,
                NeutralSentimentCounter  = sentimentAnalysisLists.BubbleChartNeutral.Count
            });

            _commandDispatcher.Execute(command);

            sentimentAnalysisLists.IsInHashtagHistory = isInDb.IsInHashtagHistory;
            return(Ok(sentimentAnalysisLists));
        }