diff --git a/Statsman/ChartsService.cs b/Statsman/ChartsService.cs index 9d94371d4..84c3f6b06 100644 --- a/Statsman/ChartsService.cs +++ b/Statsman/ChartsService.cs @@ -23,10 +23,9 @@ public async Task GetImageStatisticsPerPeriod(IEnumerable x.Time.Start); var labels = statistics.Count() switch { - int x when x <= 1 => dates.Select(x => x.ToString("yyyy-MM-dd HH")), - int x when x <= 30 => dates.Select(x => x.ToString("yyyy-MM-dd")), - int x when x > 30 => dates.Select(x => x.ToString("yyyy-MM")), - _ => new List() + <= 2 => dates.Select(x => x.ToString("yyyy-MM-dd HH")), + <= 31 => dates.Select(x => x.ToString("yyyy-MM-dd")), + _ => dates.Select(x => x.ToString("yyyy-MM")) }; var chart = new Chart { diff --git a/Statsman/Core/TimeSplitting/PeriodStatisticsService.cs b/Statsman/Core/TimeSplitting/PeriodStatisticsService.cs index f02f4a603..0947c037c 100644 --- a/Statsman/Core/TimeSplitting/PeriodStatisticsService.cs +++ b/Statsman/Core/TimeSplitting/PeriodStatisticsService.cs @@ -27,7 +27,7 @@ public PeriodStatisticsService(ChartsService chartsService, StatisticsGroupingSe public Task<(Stream Chart, ResultMessage Message)> PerHour(StatisticsRequest request) { - return this.GetResult(request, DetailedPeriod.Minute, DateTime.Now); + return this.GetResult(request, DetailedPeriod.Hour, DateTime.Now); } public Task<(Stream Chart, ResultMessage Message)> PerDay(StatisticsRequest request) @@ -60,8 +60,12 @@ public PeriodStatisticsService(ChartsService chartsService, StatisticsGroupingSe private async Task<(Stream Chart, ResultMessage Message)> GetResult(StatisticsRequest request, DetailedPeriod period, DateTime startTimeRangeTimeOfDay) { - var timeRange = TimeRange.ToNow(startTimeRangeTimeOfDay.Add(request.TimeBehind)); - var statistics = await this._statisticsGroupingService.GetStatisticsGroupedPerDetailedPeriod(request, timeRange, period); + var timeRange = TimeRange.ToNow(startTimeRangeTimeOfDay.Add(-request.TimeBehind)); + var statistics = period switch + { + <= DetailedPeriod.Hour => await this._statisticsGroupingService.GetStatisticsGroupedPerDetailedPeriod(request, timeRange, period), + _ => await this._statisticsGroupingService.GetStatisticsGroupedPerDaysPeriod(request, timeRange, period) + }; return (Chart: await this._chartsService.GetImageStatisticsPerPeriod(statistics, $"Messages per {Enum.GetName(typeof(DetailedPeriod), period).ToLower()}"), Message: this.GetMessage(request.UserId, request.ChannelId, period, timeRange)); } diff --git a/Statsman/Core/TimeSplitting/Services/TimeSplittingService.cs b/Statsman/Core/TimeSplitting/Services/TimeSplittingService.cs index 78a4c5487..1935d3250 100644 --- a/Statsman/Core/TimeSplitting/Services/TimeSplittingService.cs +++ b/Statsman/Core/TimeSplitting/Services/TimeSplittingService.cs @@ -92,7 +92,7 @@ private IEnumerable FilterMessages(IEnumerable latestMessages, { return latestMessages; } - var latestTimeRange = perDay.OrderBy(x => x.TimeRange).First(); + var latestTimeRange = perDay.OrderBy(x => x.TimeRange.Start).First(); return latestMessages.Where(x => { if (x.SentAt.Date > latestTimeRange.TimeRange.End) //in newer day diff --git a/Watchman.Discord/Areas/Statistics/Controllers/StatisticsController.cs b/Watchman.Discord/Areas/Statistics/Controllers/StatisticsController.cs index b576bb43a..6a5fd55d1 100644 --- a/Watchman.Discord/Areas/Statistics/Controllers/StatisticsController.cs +++ b/Watchman.Discord/Areas/Statistics/Controllers/StatisticsController.cs @@ -63,8 +63,8 @@ public async Task Stats(StatsCommand command, Contexts contexts) var (chart, message) = await this.GetStatistics(command, contexts); if (command.Direct) { - await Task.Run(() => _directMessagesService.TrySendFile(contexts.User.Id, "Statistics.png", chart)) - .ContinueWith(x => _directMessagesService.TrySendEmbedMessage(contexts.User.Id, message.Title, string.Empty, message.GetArguments())); + await Task.Run(() => this._directMessagesService.TrySendFile(contexts.User.Id, "Statistics.png", chart)) + .ContinueWith(x => this._directMessagesService.TrySendEmbedMessage(contexts.User.Id, message.Title, string.Empty, message.GetArguments())); } else {