Skip to content

Commit

Permalink
Merge pull request #119 from Devscord-Team/fix-add-pre-generated-stat…
Browse files Browse the repository at this point in the history
…istics

fix-add-pre-generated-statistics
  • Loading branch information
Marcin99b authored Dec 18, 2020
2 parents a0429ad + ecc221b commit c416f4b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 3 additions & 4 deletions Statsman/ChartsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public async Task<Stream> GetImageStatisticsPerPeriod(IEnumerable<TimeStatisticI
var dates = statistics.Select(x => 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<string>()
<= 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
{
Expand Down
10 changes: 7 additions & 3 deletions Statsman/Core/TimeSplitting/PeriodStatisticsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private IEnumerable<Message> FilterMessages(IEnumerable<Message> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit c416f4b

Please sign in to comment.