diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-11-30 18:46:20 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-11-30 18:46:20 -0600 |
| commit | 91cb8165cb59744d959337a4a0b2793afcc88fe4 (patch) | |
| tree | 72e7d88db03101d7b8adc4c9fc5a515144dc9a29 /src/slskd/Telemetry/StatisticsService.cs | |
| parent | 47b106fcd88200755c15eed8b9014761c48b2e24 (diff) | |
| download | slskd-91cb8165cb59744d959337a4a0b2793afcc88fe4.tar.gz | |
add leaderboard
Diffstat (limited to 'src/slskd/Telemetry/StatisticsService.cs')
| -rw-r--r-- | src/slskd/Telemetry/StatisticsService.cs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/slskd/Telemetry/StatisticsService.cs b/src/slskd/Telemetry/StatisticsService.cs index 3bd9b26b..c528b8f3 100644 --- a/src/slskd/Telemetry/StatisticsService.cs +++ b/src/slskd/Telemetry/StatisticsService.cs @@ -144,8 +144,9 @@ public class StatisticsService var dict = new Dictionary<DateTime, Dictionary<TransferDirection, Dictionary<TransferStates, TransferSummary>>>(); - // Fill the dictionary with gapless intervals and empty dictionaries + // fill the dictionary with gapless intervals and empty dictionaries var currentInterval = new DateTime(start.Ticks / interval.Ticks * interval.Ticks, DateTimeKind.Utc); + while (currentInterval < end) { dict[currentInterval] = new Dictionary<TransferDirection, Dictionary<TransferStates, TransferSummary>>() @@ -203,7 +204,7 @@ public class StatisticsService if (result.Interval.HasValue) { - // Normalize the result interval to match the bucket interval + // normalize the result interval to match the bucket interval var bucketInterval = new DateTime(result.Interval.Value.Ticks / interval.Ticks * interval.Ticks, DateTimeKind.Utc); if (dict.TryGetValue(bucketInterval, out var intervalDict)) @@ -366,6 +367,8 @@ public class StatisticsService /// <param name="direction">The direction (Upload or Download) for the summary.</param> /// <param name="start">The optional start time of the summary window.</param> /// <param name="end">The optional end time of the summary window.</param> + /// <param name="sortBy">The property by which to sort.</param> + /// <param name="sortOrder">The sort order.</param> /// <param name="limit">The number of records to return (default: 25).</param> /// <param name="offset">The record offset (if paginating).</param> /// <returns>A dictionary keyed by username and containing summary information.</returns> @@ -376,6 +379,8 @@ public class StatisticsService TransferDirection direction, DateTime? start = null, DateTime? end = null, + LeaderboardSortBy sortBy = LeaderboardSortBy.Count, + SortOrder sortOrder = SortOrder.DESC, int limit = 25, int offset = 0) { @@ -408,7 +413,7 @@ public class StatisticsService AND EndedAt IS NOT NULL AND EndedAt BETWEEN @Start AND @End GROUP BY Username, Direction, StateDescription - ORDER BY Count DESC, TotalBytes DESC, Username ASC + ORDER BY {sortBy} {sortOrder}, Username DESC LIMIT @Limit OFFSET @Offset "; @@ -452,12 +457,4 @@ public class StatisticsService public double AverageWait { get; init; } public double AverageDuration { get; init; } } - - private record ExceptionSummaryRow - { - public TransferDirection Direction { get; init; } - public string Exception { get; init; } - public long Count { get; init; } - public long DistinctUsers { get; init; } - } }
\ No newline at end of file |
