Skip to content

Commit a5575ce

Browse files
authored
Report bits not bytes (alexjustesen#49)
1 parent 3a836a0 commit a5575ce

File tree

8 files changed

+235
-149
lines changed

8 files changed

+235
-149
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
FROM serversideup/php:beta-8.1-fpm-nginx
22

33
ENV PHP_POOL_NAME=speedtest-tracker_php
4-
ENV PHP_POST_MAX_SIZE=1G
5-
ENV PHP_UPLOAD_MAX_FILE_SIZE=1G
64

75
# Install addition packages
86
RUN apt-get update && apt-get install -y \

_ide_helper.php

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

55
/**
66
* A helper file for Laravel, to provide autocomplete information to your IDE
7-
* Generated for Laravel 9.34.0.
7+
* Generated for Laravel 9.36.3.
88
*
99
* This file should not be included in your code, only analyzed by your IDE!
1010
*
@@ -12756,6 +12756,7 @@ public static function flushMacros()
1275612756
* @method static \Illuminate\Routing\RouteRegistrar scopeBindings()
1275712757
* @method static \Illuminate\Routing\RouteRegistrar where(array $where)
1275812758
* @method static \Illuminate\Routing\RouteRegistrar withoutMiddleware(array|string $middleware)
12759+
* @method static \Illuminate\Routing\RouteRegistrar withoutScopedBindings()
1275912760
* @see \Illuminate\Routing\Router
1276012761
*/
1276112762
class Route {
@@ -18428,7 +18429,19 @@ public static function assertPageActionShouldNotOpenUrlInNewTab($name, $record =
1842818429
/**
1842918430
*
1843018431
*
18431-
* @see \Filament\Testing\TestsPageActions::assertPageActionHeld()
18432+
* @see \Filament\Testing\TestsPageActions::assertPageActionHalted()
18433+
* @param string $name
18434+
* @return static
18435+
* @static
18436+
*/
18437+
public static function assertPageActionHalted($name)
18438+
{
18439+
return \Livewire\Testing\TestableLivewire::assertPageActionHalted($name);
18440+
}
18441+
/**
18442+
*
18443+
*
18444+
* @see \Filament\Testing\TestsPageActions::assertPageActionHalted()
1843218445
* @param string $name
1843318446
* @return static
1843418447
* @static
@@ -18879,7 +18892,19 @@ public static function assertTableActionShouldNotOpenUrlInNewTab($name, $record
1887918892
/**
1888018893
*
1888118894
*
18882-
* @see \Filament\Tables\Testing\TestsActions::assertTableActionHeld()
18895+
* @see \Filament\Tables\Testing\TestsActions::assertTableActionHalted()
18896+
* @param string $name
18897+
* @return static
18898+
* @static
18899+
*/
18900+
public static function assertTableActionHalted($name)
18901+
{
18902+
return \Livewire\Testing\TestableLivewire::assertTableActionHalted($name);
18903+
}
18904+
/**
18905+
*
18906+
*
18907+
* @see \Filament\Tables\Testing\TestsActions::assertTableActionHalted()
1888318908
* @param string $name
1888418909
* @return static
1888518910
* @static
@@ -19135,7 +19160,19 @@ public static function assertTableBulkActionDoesNotHaveColor($name, $color, $rec
1913519160
/**
1913619161
*
1913719162
*
19138-
* @see \Filament\Tables\Testing\TestsBulkActions::assertTableBulkActionHeld()
19163+
* @see \Filament\Tables\Testing\TestsBulkActions::assertTableBulkActionHalted()
19164+
* @param string $name
19165+
* @return static
19166+
* @static
19167+
*/
19168+
public static function assertTableBulkActionHalted($name)
19169+
{
19170+
return \Livewire\Testing\TestableLivewire::assertTableBulkActionHalted($name);
19171+
}
19172+
/**
19173+
*
19174+
*
19175+
* @see \Filament\Tables\Testing\TestsBulkActions::assertTableBulkActionHalted()
1913919176
* @param string $name
1914019177
* @return static
1914119178
* @static

app/Filament/Resources/ResultResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public static function table(Table $table): Table
2828
TextColumn::make('id')
2929
->label('ID'),
3030
ViewColumn::make('download')
31-
->view('tables.columns.bytes-column'),
31+
->view('tables.columns.bits-column'),
3232
ViewColumn::make('upload')
33-
->view('tables.columns.bytes-column'),
33+
->view('tables.columns.bits-column'),
3434
TextColumn::make('ping'),
3535
ViewColumn::make('server_id')
3636
->label('Server ID')

app/Filament/Resources/ResultResource/Pages/ListResults.php

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

55
use App\Filament\Resources\ResultResource;
66
use Filament\Resources\Pages\ListRecords;
7+
use Illuminate\Database\Eloquent\Builder;
78

89
class ListResults extends ListRecords
910
{
1011
protected static string $resource = ResultResource::class;
1112

13+
protected function getTableQuery(): Builder
14+
{
15+
return parent::getTableQuery()->orderBy('id', 'desc');
16+
}
17+
1218
protected function getHeaderWidgets(): array
1319
{
1420
return ResultResource::getWidgets();

app/Filament/Resources/ResultResource/Widgets/StatsOverview.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class StatsOverview extends BaseWidget
1313
protected function getCards(): array
1414
{
1515
return [
16-
Card::make('Latest download', formatBytes(Result::latest()->first()?->download ?: 0)),
17-
Card::make('Latest upload', formatBytes(Result::latest()->first()?->upload ?: 0)),
16+
Card::make('Latest download', formatBits(formatBytesToBits(Result::latest()->first()?->download ?: 0)).'ps'),
17+
Card::make('Latest upload', formatBits(formatBytesToBits(Result::latest()->first()?->upload ?: 0)).'ps'),
1818
Card::make('Latest ping', round(Result::latest()->first()?->ping ?: 0, 2)),
1919
];
2020
}

app/helpers.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,42 @@
11
<?php
22

3+
if (! function_exists('formatBits')) {
4+
function formatBits(int $bits, $precision = 2)
5+
{
6+
if ($bits > 0) {
7+
$i = floor(log($bits) / log(1024));
8+
9+
$sizes = ['B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb'];
10+
11+
return sprintf('%.02F', round($bits / pow(1024, $i), $precision)) * 1 .' '.@$sizes[$i];
12+
}
13+
14+
return 0;
15+
}
16+
}
17+
318
if (! function_exists('formatBytes')) {
419
function formatBytes(int $bytes, $precision = 2)
520
{
6-
$base = log($bytes, 1024);
7-
$suffixes = ['', 'Kbps', 'Mbps', 'Gbps', 'Tbps'];
21+
if ($bytes > 0) {
22+
$i = floor(log($bytes) / log(1024));
23+
24+
$sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
25+
26+
return sprintf('%.02F', round($bytes / pow(1024, $i), $precision)) * 1 .' '.@$sizes[$i];
27+
}
28+
29+
return 0;
30+
}
31+
}
32+
33+
if (! function_exists('formatBytesToBits')) {
34+
function formatBytestoBits(int $bytes)
35+
{
36+
if ($bytes > 0) {
37+
return $bytes * 8;
38+
}
839

9-
return round(pow(1024, $base - floor($base)), $precision).' '.$suffixes[floor($base)];
40+
return 0;
1041
}
1142
}

0 commit comments

Comments
 (0)