public OperationStatus StoreNew()
        {
            var keys = _unitOfWork.Tweets.GetUniqueKeys();
            var keyByLastTweetDate = keys.Select(key => Tuple.Create(key, _unitOfWork.Tweets.FindByKey(new TweetQuery(key)).Select(x => x.Date).Max()));
            var tweetsToAddition   = keyByLastTweetDate.Select(x =>
            {
                var apiResult     = _unitOfWork.ApiTweets.Get(new TweetQuery(x.Item1, x.Item2, 10000));
                var analyzeResult = _sentimentalAnalysisService.Analyze(apiResult);
                if (analyzeResult.IsSuccess)
                {
                    return(_unitOfWork.Tweets.AddRange(analyzeResult.Value));
                }
                return(OperationStatus.Error);
            }).ToList();

            return(tweetsToAddition.Any(x => x == OperationStatus.Error)
                ? OperationStatus.Error
                : OperationStatus.Succeed);
        }
示例#2
0
        public Result <AnalysisScore> GetTweetScoreByKey(string key)
        {
            var dbResult = _unitOfWork.Tweets.FindByKey(new TweetQuery(key, 100000)).ToList();

            if (dbResult.Count > 0)
            {
                return(Result <AnalysisScore> .Wrap(AnalysisScoreBuilder.AnalysisScore(dbResult, key).Build()));
            }

            var apiResult      = _unitOfWork.ApiTweets.Get(new TweetQuery(key));
            var analyzedTweets = _sentimentalAnalysisService.Analyze(apiResult);

            if (!analyzedTweets.IsSuccess)
            {
                return(Result <AnalysisScore> .Error());
            }

            _unitOfWork.Tweets.AddRange(analyzedTweets.Value);
            return(Result <AnalysisScore> .Wrap(AnalysisScoreBuilder.AnalysisScore(analyzedTweets.Value, key).Build()));
        }