Example #1
0
        public static APIDataModel CollectRawValues(string keyword)
        {
            APIDataModel d = DatabaseAccessLayer.Instance.CollectRawData(keyword);

            d.keyword = keyword;

            List <int>    volume = new List <int>();
            int           pos;
            int           neg;
            double        tempAvg;
            List <double> avg = new List <double>();

            for (int i = 0; i < d.dates.Length; i++)
            {
                pos = d.posList[i];
                neg = d.negList[i];
                volume.Add(neg + pos);

                if (pos + neg > 0)
                {
                    tempAvg = ((double)pos - neg) / (pos + neg);
                }
                else
                {
                    tempAvg = 0;
                }

                avg.Add(tempAvg);
            }

            d.normalizedMood = avg.ToArray();
            d.totalHits      = volume.ToArray();

            return(d);
        }
Example #2
0
        public static APIDataModel CollectAverages(string keyword, int interval)
        {
            APIDataModel  d        = DatabaseAccessLayer.Instance.CollectRawData(keyword);
            DateTime      end      = DateTime.Today.AddDays(-1);
            List <double> avg      = new List <double>();
            List <int>    volume   = new List <int>();
            List <string> dates    = new List <string>(d.dates);
            List <int>    posCount = new List <int>(d.posList);
            List <int>    negCount = new List <int>(d.negList);

            if (String.IsNullOrEmpty(keyword))
            {
                keyword = Guid.NewGuid().ToString();
            }

            d.keyword = keyword;

            for (int i = 0; i < interval; i++)
            {
                avg.Add(0);
                volume.Add(0);
            }
            for (int i = interval; i < dates.Count; i++)
            {
                if (ValidRange(dates.GetRange(i - interval, interval)))
                {
                    avg.Add(Average(posCount.GetRange(i - interval, interval), negCount.GetRange(i - interval, interval)));
                    volume.Add(posCount[i] + negCount[i]);
                }
                else
                {
                    avg.Add(0);
                    volume.Add(0);
                }
            }
            d.normalizedMood = avg.ToArray();
            d.totalHits      = volume.ToArray();

            return(d);
        }
Example #3
0
        public APIDataModel Get(
            string request,
            string keyword = "",
            int runningAvg = 0,
            int interval   = 0,
            long sinceID   = 0,
            string id      = "",
            string unit    = "",
            string date    = "",
            string source  = ""
            )
        {
            int          keyID = -1;
            APIDataModel data  = new APIDataModel();

            if (request == "TOTAL")
            {
                if (runningAvg > 1)
                {
                    d = ChartManager.collectAverages(keyword, runningAvg);
                }
                else
                {
                    data          = ChartManager.CollectRawValues(keyword);
                    data.chartDiv = data.keyword.Replace(" ", String.Empty) + "ChartDiv";
                }
            }
            else if (request == "FIVE_MINUTES")
            {
                keyID = DatabaseAccessLayer.Instance.GetKeywordID(keyword);
                data  = DatabaseAccessLayer.Instance.Get5Min(keyID);
            }

            else if (request == "USER_INFO")
            {
                data.keywords    = AccountManager.GetUserKeywords(Guid.Parse(id));
                data.accounts    = new Account[1];
                data.accounts[0] = AccountManager.GetAccountInfo(Guid.Parse(id));
            }
            else if (request == "USER_LIST")
            {
                data.accounts = AccountManager.GetAccounts().ToArray();
            }
            else if (request == "CLASSIFY_SENTIMENT")
            {
                data.ourSentiment   = SentimentClassificationService.Instance.Classify(keyword);
                data.viralSentiment = "none";//json["mood"];
            }
            else if (request == "GET_ANNOTATIONS")
            {
                data = DatabaseAccessLayer.Instance.GetAnnotations(keyword);
            }
            else if (request == "TIME_RANGE")
            {
                keyID = DatabaseAccessLayer.Instance.GetKeywordID(keyword);
                if (unit == "5min")
                {
                    data = DatabaseAccessLayer.Instance.Get5Min(keyID);
                }
                else if (unit == "1min")
                {
                    d = DatabaseAccessLayer.Instance.GetLastMinute(keyID);
                }
                else if (unit == "10sec")
                {
                    data = DatabaseAccessLayer.Instance.GetTenSeconds(keyID, source);
                }
                else
                {
                    data = DatabaseAccessLayer.Instance.GetTimeRange(keyID, unit);
                    if (data.dates.Count() > 0)
                    {
                        data.sentimentList = DatabaseAccessLayer.Instance.GetHistoryPage(keyword, 0, DateTime.Parse(data.dates[0])).sentimentList;
                    }
                }
            }
            else if (request == "PAGE")
            {
                data = DatabaseAccessLayer.Instance.GetHistoryPage(keyword, interval - 1, DateTime.Parse(date));
            }
            else if (request == "DAY_VALUES")
            {
                data = DatabaseAccessLayer.Instance.GetDayValues(keyword, DateTime.Parse(date));
            }
            else if (request == "WIDGET")
            {
                data = DatabaseAccessLayer.Instance.GetWidgetData(keyword);
            }

            return(data);
        }
Example #4
0
        public static APIDataModel GetCSV(string keyword)
        {
            APIDataModel d = new APIDataModel();

            return(d);
        }