Skip to content

Commit 390dbb4

Browse files
committed
wip
1 parent 0cab5c2 commit 390dbb4

File tree

3 files changed

+4
-45
lines changed

3 files changed

+4
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ tempest-access.log
1818
vite-tempest
1919
public/build/
2020
database.sqlite
21+
database-old.sqlite

src/Web/Analytics/StatsController.php

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
namespace App\Web\Analytics;
44

5-
use App\Web\Analytics\PackageDownloadsPerHour\PackageDownloadsPerHour;
65
use App\Web\Analytics\VisitsPerDay\VisitsPerDay;
7-
use App\Web\Analytics\VisitsPerHour\VisitsPerHour;
8-
use DateInterval;
9-
use DateTimeImmutable;
106
use Tempest\Clock\Clock;
11-
use Tempest\Database\Query;
127
use Tempest\DateTime\Duration;
138
use Tempest\Router\Get;
149
use Tempest\View\View;
1510

11+
use function Tempest\Database\query;
1612
use function Tempest\Support\arr;
1713
use function Tempest\view;
1814

@@ -21,54 +17,17 @@
2117
#[Get('/stats')]
2218
public function __invoke(Clock $clock): View
2319
{
24-
$now = $clock->now();
25-
26-
$visitsPerHour = arr(
27-
VisitsPerHour::select()
28-
->where('date >= ?', $now->minus(Duration::hours(24))->format('Y-m-d H:i:s'))
29-
->all(),
30-
);
31-
3220
$visitsPerDay = arr(
33-
VisitsPerDay::select()
34-
->where('date >= ?', $now->minus(Duration::days(30))->format('Y-m-d H:i:s'))
35-
->all(),
36-
);
37-
38-
$packageDownloadsPerHour = arr(new Query(<<<SQL
39-
SELECT `date`, SUM(`count`) as `count` FROM package_downloads_per_hours WHERE `date` >= :date GROUP BY `date`
40-
SQL)->fetch(
41-
date: $now->minus(Duration::days(24))->format('Y-m-d H:i:s'),
42-
));
43-
44-
$packageDownloadsPerDay = arr(new Query(<<<SQL
45-
SELECT `date`, SUM(`count`) as `count` FROM package_downloads_per_days WHERE date >= :date GROUP BY `date`
46-
SQL)->fetch(
47-
date: $now->minus(Duration::days(30))->format('Y-m-d H:i:s'),
48-
));
21+
query(VisitsPerDay::class)->select()->orderBy('date DESC')->limit(30)->all(),
22+
)->reverse();
4923

5024
return view(
5125
__DIR__ . '/stats.view.php',
5226

53-
visitsPerHour: new Chart(
54-
labels: $visitsPerHour->map(fn (VisitsPerHour $item) => $item->date->format('H:i')),
55-
values: $visitsPerHour->map(fn (VisitsPerHour $item) => $item->count),
56-
),
57-
5827
visitsPerDay: new Chart(
5928
labels: $visitsPerDay->map(fn (VisitsPerDay $item) => $item->date->format('Y-m-d')),
6029
values: $visitsPerDay->map(fn (VisitsPerDay $item) => $item->count),
6130
),
62-
63-
packageDownloadsPerHour: new Chart(
64-
labels: $packageDownloadsPerHour->map(fn (array $item) => new DateTimeImmutable($item['date'])->format('H:i')),
65-
values: $packageDownloadsPerHour->map(fn (array $item) => $item['count']),
66-
),
67-
68-
packageDownloadsPerDay: new Chart(
69-
labels: $packageDownloadsPerDay->map(fn (array $item) => new DateTimeImmutable($item['date'])->format('Y-m-d')),
70-
values: $packageDownloadsPerDay->map(fn (array $item) => $item['count']),
71-
),
7231
);
7332
}
7433
}

src/Web/Analytics/stats.view.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<div class="w-full flex flex-col ">
1515
<div class="w-full z-10 md:py-24 pt-12">
1616
<div class="w-full mx-auto grid md:grid-cols-2 xl:grid-cols-3 gap-12 md:px-24 px-8">
17-
<x-chart :chart="$visitsPerHour" label="Visits per hour" title="Website visits last 24 hours"></x-chart>
1817
<x-chart :chart="$visitsPerDay" label="Visits per day" title="Website visits last 30 days"></x-chart>
1918
</div>
2019
</div>

0 commit comments

Comments
 (0)