コード例 #1
0
        public async Task <IReadOnlyCollection <ThreadStatisticsResult> > Get(ThreadStatisticsRequest statisticsRequest)
        {
            string cacheKey = string.Format(
                StatisticsCacheKeyTemplate,
                statisticsRequest.ThreadId,
                statisticsRequest.AggregationInterval);

            IReadOnlyCollection <ThreadStatisticsResult> cachedStats = _cacheManager.Get <IReadOnlyCollection <ThreadStatisticsResult> >(cacheKey);

            if (cachedStats != null)
            {
                return(cachedStats);
            }


            DateTime startDate = GetStartDate(statisticsRequest.AggregationInterval);
            DateTime endDate   = DateTime.UtcNow;
            IReadOnlyCollection <ThreadStatistics> statistics = await _statisticsRepository.Get(statisticsRequest.ThreadId, startDate, endDate);

            IEnumerable <IGrouping <DateTime, ThreadStatistics> > grouppedByPeriod = statistics
                                                                                     .GroupBy(x => GetStartOfPeriod(x.Timestamp, statisticsRequest.AggregationInterval))
                                                                                     .OrderBy(x => x.Key.Date);

            List <ThreadStatisticsResult> results = new List <ThreadStatisticsResult>();

            foreach (IGrouping <DateTime, ThreadStatistics> periodGroup in grouppedByPeriod)
            {
                ThreadStatistics samplePoint = periodGroup.First();

                DateTime startOfPeriod    = GetStartOfPeriod(samplePoint.Timestamp, statisticsRequest.AggregationInterval);
                string   currentDateLabel = GetLabelForDate(startOfPeriod, statisticsRequest.AggregationInterval);

                ThreadStatisticsResult currentResult = new ThreadStatisticsResult
                {
                    Label = currentDateLabel
                };

                foreach (ThreadStatistics dataPoint in periodGroup)
                {
                    currentResult.AbsoluteHits += dataPoint.AbsoluteHits;
                    currentResult.Hits         += dataPoint.Hits;
                }

                results.Add(currentResult);
            }

            _cacheManager.Add(cacheKey, results, DateTime.UtcNow.AddDays(1));
            return(await Task.FromResult(results));
        }
コード例 #2
0
        static void GetData(int year, int month)
        {
            string        path = string.Format("{0:00}{1:00}", year % 100, month);
            DirectoryInfo di   = new DirectoryInfo(path);

            Console.Write("Processing {0}", path);
            if (di.Exists)
            {
                FileInfo[]       tcs = di.GetFiles();
                ThreadStatistics ts, tmp;
                DateTime         dt;
                foreach (var tc in tcs)
                {
                    Console.Write('.');
                    tmp = ts = new ThreadStatistics(year, month, tc.Name);
                    for (int i = 0; i < ts.Replies.Length; i++)
                    {
                        if (ts.Time.Year == workYear)
                        {
                            tmp.SpecificReply = ts.Replies[i];
                            if (i == 1)
                            {
                                if (tmp.Title.Contains('-'))
                                {
                                    tmp.Title = tmp.Title.Substring(0, 3);
                                }
                                tmp.Title += '\'';
                            }
                            data[ts.Time.Month - 1].Add(tmp);
                        }
                        ts.Time  = ts.Time.AddMonths(1);
                        tmp.Time = tmp.Time.AddYears(-1);
                    }
                }
            }
            Console.WriteLine();
        }