private DateTime GetStartOfPeriod(DateTime date, StatisticsAggregationInterval interval) { switch (interval) { case StatisticsAggregationInterval.Day: return(date); case StatisticsAggregationInterval.Week: return(date.StartOfWeek(DayOfWeek.Monday)); case StatisticsAggregationInterval.Month: return(date.StartOfMonth()); case StatisticsAggregationInterval.Year: return(date.StartOfYear()); default: throw new ArgumentOutOfRangeException(nameof(interval), interval, null); } }
private string GetLabelForDate(DateTime date, StatisticsAggregationInterval interval) { switch (interval) { case StatisticsAggregationInterval.Day: return(date.ToString("dd/MM/yyyy")); case StatisticsAggregationInterval.Week: return(date.ToString("dd/MM/yyyy")); case StatisticsAggregationInterval.Month: return(date.ToString("Y")); case StatisticsAggregationInterval.Year: return(date.Year.ToString()); default: throw new ArgumentOutOfRangeException(nameof(interval), interval, null); } }
//private IEnumerable<IGrouping<DateTime, ThreadStatistics>> GroupStatistics(IReadOnlyCollection<ThreadStatistics> statistics, StatisticsAggregationInterval aggregationInterval) //{ // switch (aggregationInterval) // { // //Statistics are already grouped by day // case StatisticsAggregationInterval.Day: // return statistics.GroupBy(x => x.Timestamp.Date); // case StatisticsAggregationInterval.Week: // return statistics.GroupBy(x => x.Timestamp.StartOfWeek(DayOfWeek.Monday)); // case StatisticsAggregationInterval.Month: // return statistics.GroupBy(x => x.Timestamp.StartOfMonth()); // case StatisticsAggregationInterval.Year: // return statistics.GroupBy(x => x.Timestamp.StartOfYear()); // default: // throw new ArgumentOutOfRangeException(nameof(aggregationInterval), aggregationInterval, null); // } //} private DateTime GetStartDate(StatisticsAggregationInterval aggregationInterval) { switch (aggregationInterval) { case StatisticsAggregationInterval.Day: return(DateTime.UtcNow.AddDays(-NumberOfIntervalsToShow)); case StatisticsAggregationInterval.Week: return(DateTime.UtcNow.AddDays(-(7 * NumberOfIntervalsToShow))); case StatisticsAggregationInterval.Month: return(DateTime.UtcNow.AddMonths(-NumberOfIntervalsToShow)); case StatisticsAggregationInterval.Year: return(DateTime.UtcNow.AddYears(-NumberOfIntervalsToShow)); default: throw new ArgumentOutOfRangeException(nameof(aggregationInterval), aggregationInterval, null); } }