From 8d8f8e89883aaec0586c8544940f418850a178b9 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:59:06 +0100 Subject: [PATCH] feat(analytics): compact traffic metrics and scale latency units --- bootstrap/helpers/shared.php | 21 ++++++++++++++++--- resources/views/livewire/analytics.blade.php | 6 +++--- .../dashboard/traffic-analytics.blade.php | 4 ++-- .../project/application/analytics.blade.php | 6 +++--- .../livewire/project/shared/metrics.blade.php | 8 ++++--- .../livewire/traffic/_paths-list.blade.php | 2 +- tests/Unit/CompactNumberTest.php | 12 +++++++++++ tests/Unit/FormatLatencyTest.php | 11 ++++++++++ 8 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 tests/Unit/CompactNumberTest.php create mode 100644 tests/Unit/FormatLatencyTest.php diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 2ed69ed773..0ca4cfe922 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -5064,8 +5064,8 @@ function formatBytes(?int $bytes, int $precision = 2): string } /** - * Compact human-readable count (e.g. 26_360 -> "26.36k", 1_200_000 -> "1.2M"). - * Trailing zeros are trimmed so round values read cleanly ("1k", not "1.00k"). + * Compact human-readable count (e.g. 26_360 -> "26.36K", 1_200_000 -> "1.2M"). + * Trailing zeros are trimmed so round values read cleanly ("1K", not "1.00K"). * Used for the dense metric columns in the traffic-analytics lists. */ function compactNumber(?int $n): string @@ -5079,12 +5079,27 @@ function compactNumber(?int $n): string [$divisor, $suffix] = match (true) { $n >= 1_000_000_000 => [1_000_000_000, 'B'], $n >= 1_000_000 => [1_000_000, 'M'], - default => [1000, 'k'], + default => [1000, 'K'], }; return rtrim(rtrim(number_format($n / $divisor, 2, '.', ''), '0'), '.').$suffix; } +/** + * Compact response time for the traffic-analytics latency figures + * (e.g. 85.4 -> "85.4 ms", 2_450 -> "2.5 s", 312_000 -> "5.2 min"). + */ +function formatLatency(float|int|null $ms): string +{ + $ms = (float) $ms; + + return match (true) { + $ms >= 60_000 => number_format($ms / 60_000, 1).' min', + $ms >= 1000 => number_format($ms / 1000, 1).' s', + default => number_format($ms, 1).' ms', + }; +} + /** * Validates that a file path is safely within the /tmp/ directory. * Protects against unsafe parent directory paths by resolving the real path diff --git a/resources/views/livewire/analytics.blade.php b/resources/views/livewire/analytics.blade.php index 4af35df784..6b41fcc983 100644 --- a/resources/views/livewire/analytics.blade.php +++ b/resources/views/livewire/analytics.blade.php @@ -139,7 +139,7 @@ $appListboxOptions = array_merge(