Beispiel #1
0
 public void add_dictionaryToStatistic(DictionaryData dd)
 {
     this.dictionaries.Add(dd);
 }
Beispiel #2
0
        /// <summary>
        /// Transform the string from the enpoint into a list of WordStatistics objects
        /// </summary>
        /// <returns>List or error</returns>
        public dynamic GetDictionaryWordStatistics(bool getmonths = false)
        {
            List<WordStatisticsObject> results = new List<WordStatisticsObject>();
            string json = conn.GetDictionaryWordStatistics();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            try
            {
                var result = jss.Deserialize<JsonReturnedObj>(json);
                if (getmonths)
                {
                    List<KeyValuePair<DateTime, int>> monthList = new List<KeyValuePair<DateTime, int>>();
                    foreach (var dictionaryStat in result.result)
                    {
                        DateTime date = new DateTime();
                        if (!(DateTime.TryParseExact(dictionaryStat.Key, new[] { "yyyy-MM-dd", "MM/dd/yy", "dd-MMM-yy" }, null, DateTimeStyles.None, out date)))
                        {
                            monthList.Add(new KeyValuePair<DateTime, int>(DateTime.ParseExact(dictionaryStat.Key, "yyyy-MM", null), dictionaryStat.Value["total"]));
                        }
                    }
                    return monthList;
                }
                foreach (var dictionaryStat in result.result)
                {
                    WordStatisticsObject dicStat = new WordStatisticsObject();
                    DateTime date = new DateTime();
                    if (DateTime.TryParseExact(dictionaryStat.Key, new[] { "yyyy-MM-dd","MM/dd/yy","dd-MMM-yy"}, null, DateTimeStyles.None, out date))
                    {
                        foreach (var dictionary in dictionaryStat.Value)
                        {
                            {
                                DictionaryData dData = new DictionaryData();
                                dData.DictionaryInitials = dictionary.Key;
                                dData.DictionaryName = dictionary.Value["name"];
                                dData.NewWords = dictionary.Value["new_words"];
                                dicStat.add_dictionaryToStatistic(dData);
                            }
                        }
                        dicStat.StatDay = date;
                        dicStat.GetTotalWords();
                        results.Add(dicStat);
                    }
                }
            }
            catch (Exception)
            {

                Error error = new Error();
                error.Error_Msg = "Doesn't matter";
                error.Error_Number = -1;

                return error;
            }
            return results;
        }