From 446954d439c0cae5ed054882f5dba398a2607cab Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 1 Dec 2025 15:49:29 -0600 Subject: tweaks --- src/slskd/Telemetry/API/StatisticsController.cs | 57 ++++++++++++++----------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'src/slskd/Telemetry/API/StatisticsController.cs') diff --git a/src/slskd/Telemetry/API/StatisticsController.cs b/src/slskd/Telemetry/API/StatisticsController.cs index 5da2f979..68bcb46c 100644 --- a/src/slskd/Telemetry/API/StatisticsController.cs +++ b/src/slskd/Telemetry/API/StatisticsController.cs @@ -50,11 +50,11 @@ public class StatisticsController : ControllerBase /// /// Gets a summary of all transfer activity over the specified timeframe, grouped by direction and final state. /// - /// The start time (default: 7 days ago). - /// The end time (default: now). - /// An optional direction by which to filter activity. - /// An optional username by which to filter activity. - /// A dictionary keyed by direction and state and containing summary information. + /// The start time of the summary window (default: 7 days ago). + /// The end time of the summary window (default: now). + /// An optional direction (Upload, Download) by which to filter records. + /// An optional username by which to filter records. + /// A nested dictionary keyed by direction and state and containing summary information. /// The request completed successfully. /// Bad request. /// An error occurred. @@ -110,12 +110,12 @@ public class StatisticsController : ControllerBase /// Gets a histogram of all transfer activity over the specified timeframe, aggregated into fixed size time intervals /// and grouped by direction and final state. /// - /// The start time (default: 7 days ago). - /// The end time (default: now). + /// The start time of the histogram window (default: 7 days ago). + /// The end time of the histogram window (default: now). /// The interval, in minutes (default: 60). - /// An optional direction by which to filter activity. - /// An optional username by which to filter activity. - /// A dictionary keyed by direction and state and containing summary information. + /// An optional direction (Upload, Download) by which to filter records. + /// An optional username by which to filter records. + /// A nested dictionary keyed by interval, direction, and state and containing summary information. /// The request completed successfully. /// Bad request. /// An error occurred. @@ -124,7 +124,7 @@ public class StatisticsController : ControllerBase [ProducesResponseType(typeof(Dictionary>>), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 500)] - public IActionResult GetTransferSummaryHistogram( + public IActionResult GetTransferHistogram( [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] int interval = 60, @@ -170,7 +170,7 @@ public class StatisticsController : ControllerBase try { - return Ok(Telemetry.Statistics.GetTransferSummaryHistogram( + return Ok(Telemetry.Statistics.GetTransferHistogram( start: start.Value, end: end.Value, interval: intervalTimeSpan, @@ -185,11 +185,11 @@ public class StatisticsController : ControllerBase } /// - /// Gets the top N user summaries by total count and direction. + /// Gets the top N user summaries by count, total bytes, or average speed. /// /// The direction (Upload, Download). - /// The start time. - /// The end time. + /// The start time of the summary window (default: 12/30/2025). + /// The end time of the summary window (default: now). /// The property by which to sort (Count, TotalBytes, AverageSpeed. Default: Count). /// The sort order (ASC, DESC. Default: DESC). /// The number of records to return (Default: 25). @@ -197,7 +197,6 @@ public class StatisticsController : ControllerBase /// [HttpGet("transfers/leaderboard")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 500)] @@ -206,7 +205,7 @@ public class StatisticsController : ControllerBase [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string sortBy = "Count", - [FromQuery] string sortOrder = "ASC", + [FromQuery] string sortOrder = "DESC", [FromQuery] int limit = 25, [FromQuery] int offset = 0) { @@ -220,8 +219,8 @@ public class StatisticsController : ControllerBase return BadRequest($"Invalid direction; expected one of: {string.Join(", ", Enum.GetNames(typeof(TransferDirection)))}"); } - start ??= DateTime.MinValue; - end ??= DateTime.MaxValue; + start ??= Program.GenesisDateTime; + end ??= DateTime.UtcNow; if (start >= end) { @@ -250,7 +249,7 @@ public class StatisticsController : ControllerBase try { - return Ok(Telemetry.Statistics.GetTransferRanking( + return Ok(Telemetry.Statistics.GetTransferLeaderboard( direction: parsedDirection, start: start.Value, end: end, @@ -273,6 +272,7 @@ public class StatisticsController : ControllerBase /// The start time. /// The end time. /// An optional username by which to filter exceptions. + /// The sort order (ASC, DESC. Default: DESC). /// The number of records to return (Default: 25). /// The record offset (if paginating). /// @@ -281,7 +281,7 @@ public class StatisticsController : ControllerBase /// An error occurred. [HttpGet("transfers/exceptions")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 500)] public IActionResult GetTransferExceptions( @@ -289,6 +289,7 @@ public class StatisticsController : ControllerBase [FromQuery] DateTime? start = null, [FromQuery] DateTime? end = null, [FromQuery] string username = null, + [FromQuery] string sortOrder = "DESC", [FromQuery] int limit = 25, [FromQuery] int offset = 0) { @@ -310,6 +311,11 @@ public class StatisticsController : ControllerBase return BadRequest("End time must be later than start time"); } + if (!Enum.TryParse(sortOrder, out var parsedSortOrder)) + { + return BadRequest($"Invalid sortOrder; expected one of: {string.Join(", ", Enum.GetNames(typeof(SortOrder)))}"); + } + if (limit <= 0) { return BadRequest("Limit must be greater than zero"); @@ -323,12 +329,13 @@ public class StatisticsController : ControllerBase try { return Ok(Telemetry.Statistics.GetTransferExceptions( + direction: parsedDirection, start: start.Value, end: end.Value, + username: username, + sortOrder: parsedSortOrder, limit: limit, - offset: offset, - direction: parsedDirection, - username: username)); + offset: offset)); } catch (Exception ex) { @@ -352,7 +359,7 @@ public class StatisticsController : ControllerBase /// An error occurred. [HttpGet("transfers/exceptions/pareto")] [Authorize(Policy = AuthPolicy.Any)] - [ProducesResponseType(typeof(Dictionary>), 200)] + [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 500)] public IActionResult GetTransferExceptionsPareto( -- cgit v1.2.3