public IEnumerable <DisplayItem> GetTopCountries(TweetStorageSelectBy countType = TweetStorageSelectBy.All, int max = 10) { lock (_items) { var res = (from item in _items where SelectPredicate(countType)(item) && item.Country != TweetStorageItem.UnknownCountry group item by item.Country into grp orderby grp.Count() descending select new DisplayItem { Name = grp.Key, Value = grp.Count() }).Take(max); return(res.ToList()); } }
private Func <TweetStorageItem, bool> SelectPredicate(TweetStorageSelectBy type = TweetStorageSelectBy.SkipErrors) { switch (type) { case TweetStorageSelectBy.All: return((p) => true); case TweetStorageSelectBy.SkipErrors: return((p) => p.Status != TweetStorageItemStatus.Error); case TweetStorageSelectBy.Analysed: return((p) => p.Status == TweetStorageItemStatus.Analysed); case TweetStorageSelectBy.ToAnalyse: return((p) => p.Status == TweetStorageItemStatus.New); case TweetStorageSelectBy.Error: return((p) => p.Status == TweetStorageItemStatus.Error); case TweetStorageSelectBy.Positive: return((p) => p.Sentiment == AnalysisResultSentiment.Positive); case TweetStorageSelectBy.Negative: return((p) => p.Sentiment == AnalysisResultSentiment.Negative); case TweetStorageSelectBy.Neutral: return((p) => p.Sentiment == AnalysisResultSentiment.Neutral); case TweetStorageSelectBy.Involvement: return((p) => p.Sentiment != AnalysisResultSentiment.Neutral && p.Sentiment != AnalysisResultSentiment.Error); case TweetStorageSelectBy.PositiveAndNegative: return((p) => p.Sentiment == AnalysisResultSentiment.Positive || p.Sentiment == AnalysisResultSentiment.Negative); case TweetStorageSelectBy.PositiveAndNegativeAndNeutral: return((p) => p.Sentiment == AnalysisResultSentiment.Positive || p.Sentiment == AnalysisResultSentiment.Negative || p.Sentiment == AnalysisResultSentiment.Neutral); default: return((p) => false); } }
public int GetPercentage(TweetStorageSelectBy countType = TweetStorageSelectBy.Positive) { int all = 0; switch (countType) { case TweetStorageSelectBy.All: return(100); case TweetStorageSelectBy.SkipErrors: case TweetStorageSelectBy.Analysed: case TweetStorageSelectBy.ToAnalyse: case TweetStorageSelectBy.Error: all = CountTweets(TweetStorageSelectBy.All); break; case TweetStorageSelectBy.Positive: case TweetStorageSelectBy.Negative: all = CountTweets(TweetStorageSelectBy.PositiveAndNegative); break; case TweetStorageSelectBy.Neutral: case TweetStorageSelectBy.Involvement: case TweetStorageSelectBy.PositiveAndNegative: all = CountTweets(TweetStorageSelectBy.PositiveAndNegativeAndNeutral); break; case TweetStorageSelectBy.PositiveAndNegativeAndNeutral: return(100); default: return(0); } if (all <= 0) { return(0); } return(Convert.ToInt32(Math.Round((Convert.ToDouble(CountTweets(countType)) / all) * 100.0))); }
public int CountTweets(TweetStorageSelectBy type = TweetStorageSelectBy.SkipErrors) { lock (_items) { return(_items.Count(SelectPredicate(type))); } }