Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions app/Filament/Widgets/RecentJitterChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class RecentJitterChart extends LineChartWidget

protected static ?string $maxHeight = '300px';

public ?string $filter = '24h';

protected function getHeading(): string
{
return 'Jitter (ms)';
Expand All @@ -20,44 +22,27 @@ protected function getHeading(): string
protected function getFilters(): ?array
{
return [
'today' => 'Today',
'24h' => 'Last 24h',
'week' => 'Last week',
'month' => 'Last month',
];
}

protected function getData(): array
{
$range = [];

$settings = new GeneralSettings();

switch ($this->filter) {
case 'today':
$range = [
['created_at', '>=', now()->startOfDay()],
['created_at', '<=', now()],
];
break;

case 'week':
$range = [
['created_at', '>=', now()->subWeek()],
['created_at', '<=', now()],
];
break;

case 'month':
$range = [
['created_at', '>=', now()->subMonth()],
['created_at', '<=', now()],
];
break;
}

$results = Result::query()
->select(['data', 'created_at'])
->where($range)
->when($this->filter == '24h', function ($query) {
$query->where('created_at', '>=', now()->subDay());
})
->when($this->filter == 'week', function ($query) {
$query->where('created_at', '>=', now()->subWeek());
})
->when($this->filter == 'month', function ($query) {
$query->where('created_at', '>=', now()->subMonth());
})
->get();

return [
Expand Down
39 changes: 12 additions & 27 deletions app/Filament/Widgets/RecentPingChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class RecentPingChart extends LineChartWidget

protected static ?string $maxHeight = '300px';

public ?string $filter = '24h';

protected function getHeading(): string
{
return 'Ping (ms)';
Expand All @@ -20,44 +22,27 @@ protected function getHeading(): string
protected function getFilters(): ?array
{
return [
'today' => 'Today',
'24h' => 'Last 24h',
'week' => 'Last week',
'month' => 'Last month',
];
}

protected function getData(): array
{
$range = [];

$settings = new GeneralSettings();

switch ($this->filter) {
case 'today':
$range = [
['created_at', '>=', now()->startOfDay()],
['created_at', '<=', now()],
];
break;

case 'week':
$range = [
['created_at', '>=', now()->subWeek()],
['created_at', '<=', now()],
];
break;

case 'month':
$range = [
['created_at', '>=', now()->subMonth()],
['created_at', '<=', now()],
];
break;
}

$results = Result::query()
->select(['ping', 'created_at'])
->where($range)
->when($this->filter == '24h', function ($query) {
$query->where('created_at', '>=', now()->subDay());
})
->when($this->filter == 'week', function ($query) {
$query->where('created_at', '>=', now()->subWeek());
})
->when($this->filter == 'month', function ($query) {
$query->where('created_at', '>=', now()->subMonth());
})
->get();

return [
Expand Down
41 changes: 13 additions & 28 deletions app/Filament/Widgets/RecentSpeedChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class RecentSpeedChart extends LineChartWidget

protected static ?string $maxHeight = '300px';

public ?string $filter = '24h';

protected function getHeading(): string
{
return 'Download / Upload (mbps)';
Expand All @@ -20,44 +22,27 @@ protected function getHeading(): string
protected function getFilters(): ?array
{
return [
'today' => 'Today',
'24h' => 'Last 24h',
'week' => 'Last week',
'month' => 'Last month',
];
}

protected function getData(): array
{
$range = [];

$settings = new GeneralSettings();

switch ($this->filter) {
case 'today':
$range = [
['created_at', '>=', now()->startOfDay()],
['created_at', '<=', now()],
];
break;

case 'week':
$range = [
['created_at', '>=', now()->subWeek()],
['created_at', '<=', now()],
];
break;

case 'month':
$range = [
['created_at', '>=', now()->subMonth()],
['created_at', '<=', now()],
];
break;
}

$results = Result::query()
->select(['download', 'upload', 'created_at'])
->where($range)
->select(['id', 'download', 'upload', 'created_at'])
->when($this->filter == '24h', function ($query) {
$query->where('created_at', '>=', now()->subDay());
})
->when($this->filter == 'week', function ($query) {
$query->where('created_at', '>=', now()->subWeek());
})
->when($this->filter == 'month', function ($query) {
$query->where('created_at', '>=', now()->subMonth());
})
->get();

return [
Expand Down