diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-07-07 12:39:03 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-07-07 12:39:03 -0500 |
| commit | ada8c819946892bf680fc59202f2620f1aba4368 (patch) | |
| tree | b79ce38202b213e60b3616215af8a06d75c209cf /src | |
| parent | 5bc50e07cfb9d2bdbc0c8f90d6a6eda24158076e (diff) | |
| download | slskd-ada8c819946892bf680fc59202f2620f1aba4368.tar.gz | |
add tests for GetTransferHistogram
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Telemetry/ReportsService.cs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/slskd/Telemetry/ReportsService.cs b/src/slskd/Telemetry/ReportsService.cs index 965b95d0..7cd245bf 100644 --- a/src/slskd/Telemetry/ReportsService.cs +++ b/src/slskd/Telemetry/ReportsService.cs @@ -207,7 +207,10 @@ public class ReportsService var dict = new Dictionary<DateTime, Dictionary<TransferDirection, Dictionary<TransferStates, TransferSummary>>>(); // fill the dictionary with gapless intervals and empty dictionaries - var currentInterval = new DateTime(start.Ticks / effectiveInterval.Ticks * effectiveInterval.Ticks, DateTimeKind.Utc); + // snap to Unix epoch to match the SQL bucket formula: strftime('%s', ...) / interval * interval, otherwise + // we may end up with an empty/partial first bucket + var intervalSeconds = (long)effectiveInterval.TotalSeconds; + var currentInterval = DateTime.UnixEpoch.AddSeconds((long)(start - DateTime.UnixEpoch).TotalSeconds / intervalSeconds * intervalSeconds); while (currentInterval < end) { @@ -267,8 +270,7 @@ public class ReportsService if (result.Interval.HasValue) { - // normalize the result interval to match the bucket interval - var bucketInterval = new DateTime(result.Interval.Value.Ticks / effectiveInterval.Ticks * effectiveInterval.Ticks, DateTimeKind.Utc); + var bucketInterval = DateTime.SpecifyKind(result.Interval.Value, DateTimeKind.Utc); if (dict.TryGetValue(bucketInterval, out var intervalDict)) { |
