Skip to content

Commit 1ee9b8b

Browse files
committed
Add bandwidth quota display and usage calculation to platform stats
1 parent 5abb511 commit 1ee9b8b

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

app/Livewire/PlatformStats.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Enums\ResultStatus;
66
use App\Models\Result;
7+
use App\Services\DataUsageCalculator;
78
use Carbon\Carbon;
89
use Cron\CronExpression;
910
use Illuminate\Support\Number;
@@ -30,11 +31,19 @@ public function platformStats(): array
3031
$totalResults = Result::count();
3132
$completedResults = Result::where('status', ResultStatus::Completed)->count();
3233
$failedResults = Result::where('status', ResultStatus::Failed)->count();
34+
$bandwidthLimit = null;
35+
$bandwidthUsed = DataUsageCalculator::calculate(now()->startOfMonth(), now());
3336

3437
return [
3538
'total' => Number::format($totalResults),
3639
'completed' => Number::format($completedResults),
3740
'failed' => Number::format($failedResults),
41+
'bandwidth_limit' => $bandwidthLimit,
42+
'bandwidth_used' => [
43+
'download_bytes' => $bandwidthUsed['download_bytes'],
44+
'upload_bytes' => $bandwidthUsed['upload_bytes'],
45+
'total_bytes' => $bandwidthUsed['total_bytes'],
46+
],
3847
];
3948
}
4049

resources/views/livewire/platform-stats.blade.php

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,6 @@
55
{{ __('general.statistics') }}
66
</h2>
77

8-
{{-- <x-filament::section class="col-span-full">
9-
<div class="flex items-center justify-between">
10-
<p class="text-sm/6 font-medium text-zinc-500">Quota Usage</p>
11-
<a href="#" class="text-sm font-medium text-zinc-600 hover:text-amber-500 underline">Edit</a>
12-
</div>
13-
14-
<div class="mt-2">
15-
<div class="flex justify-between mb-1">
16-
<span class="text-sm font-medium text-body">Bandwidth</span>
17-
<span class="text-sm font-medium text-body">450MB of 1 GB</span>
18-
</div>
19-
20-
<div class="w-full bg-zinc-200 rounded-full h-2">
21-
<div class="bg-amber-500 h-2 rounded-full" style="width: 45%"></div>
22-
</div>
23-
</div>
24-
</x-filament::section> --}}
25-
268
@filled($this->nextSpeedtest)
279
<x-filament::section class="col-span-1">
2810
<x-slot name="heading">
@@ -64,5 +46,46 @@
6446

6547
<p class="text-xl font-semibold tracking-tight text-zinc-900 dark:text-zinc-100">{{ $this->platformStats['failed'] }}</p>
6648
</x-filament::section>
49+
50+
<x-filament::section class="col-span-full" icon="tabler-chart-pie" icon-size="md">
51+
<x-slot name="heading">
52+
Bandwidth Quota
53+
</x-slot>
54+
55+
<x-slot name="description">
56+
Resets on {{ today()->addMonth()->startOfMonth()->format('M. jS, Y') }}
57+
</x-slot>
58+
59+
@auth
60+
<x-slot name="afterHeader">
61+
<x-filament::button
62+
href="#"
63+
tag="a"
64+
size="sm"
65+
>
66+
{{ __('general.edit') }}
67+
</x-filament::button>
68+
</x-slot>
69+
@endauth
70+
71+
<div>
72+
<div class="flex justify-between mb-1">
73+
<span class="text-sm font-medium text-body">Usage</span>
74+
<span class="text-sm font-medium text-body">{{ Number::fileSize($this->platformStats['bandwidth_used']['total_bytes'] ?? 0, 2) }} of {{ $this->platformStats['bandwidth_limit'] ?? 'Unlimited' }}</span>
75+
</div>
76+
77+
@php
78+
$used = 0;
79+
80+
if (isset($this->platformStats['bandwidth_used']['total_bytes']) && isset($this->platformStats['bandwidth_limit'])) {
81+
$used = round($this->platformStats['bandwidth_used']['total_bytes'] / (\App\Helpers\FileSize::toBytes($this->platformStats['bandwidth_limit']) ?: 1) * 100);
82+
}
83+
@endphp
84+
85+
<div class="w-full bg-zinc-200 rounded-full h-2">
86+
<div class="bg-amber-500 h-2 rounded-full" style="width: {{ min($used, 100) }}%" title="{{ number_format($used) }}%"></div>
87+
</div>
88+
</div>
89+
</x-filament::section>
6790
</div>
6891
</div>

0 commit comments

Comments
 (0)