예제 #1
0
        private JArray _getTweetPieCount()
        {
            var attrArr = new JArray();
            var svc = new Twitterservice();

                IEnumerable<KeyValuePair<string, List<ITweet>>> results = _keys.Select(x => new KeyValuePair<string, List<ITweet>>(x, svc.GeTweetsByKeyWord(x)));

            int totalCount = results.Sum(x => x.Value.Count);

            Dictionary<string, double> data = results.ToDictionary(x => x.Key, x => (double) x.Value.Count/totalCount);

            int i = 0;
            foreach (var d in data)
            {
                attrArr.Add(new JObject
                           {
                               {"label", new JValue(d.Key)},
                               {"data", new JValue(d.Value)},
                               {"color", new JValue(Colors[i++ % Colors.Count])}
                           });
            }
            return attrArr;
        }
예제 #2
0
        public Ranking GetRanking(string searchkey)
        {
            var svc = new Twitterservice();

            var sems = new List<SemanticScoreData.SemanticElement>();

            List<ITweet> tweets = svc.GeTweetsByKeyWord(searchkey);
            sems.AddRange(tweets.Select(x => new SemanticScoreData.SemanticElement(searchkey, x)));
            var analysisData = _getSemanticDataForTweets(tweets);

            foreach (var sem in sems)
            {
                sem.SemanticData = analysisData.FirstOrDefault(x => x.Tag == sem.TweetData.IdStr);
            }
            var resultGroups = sems.GroupBy(x => x.ProductId);
            var grp = resultGroups.FirstOrDefault();
            var ranking = new Ranking();
            var count = sems.Count;
            var semData = sems.Where(x => x.SemanticData != null).ToList();
            double score=0.0;
            double index = 0.0;
            if (semData.Count>0){
                score =  semData.Sum(x => x.SemanticData.SentimentScore) /semData.Count;
                index = Math.Round(score/count*1000);
            }
            ranking = new Ranking()
                      {
                          Name = searchkey,
                          Score = Math.Round(score * 100),
                          Total = count,
                          Index = index
                      };
            return ranking;
        }