Show how each domain has behaved over a day, a week, a month and a year, not just now

This commit is contained in:
Gmer4Lfe
2026-08-16 11:55:25 -04:00
parent 187dc188c2
commit f2ad41e8e2
5 changed files with 228 additions and 14 deletions
+29
View File
@@ -126,6 +126,19 @@ function vv_uptime_window_api(array $buckets, int $n): ?float {
return vv_auth_uptime_window($buckets, $n);
}
// One period of the history card: the rolled-up percentage, the drawable series, and how much of
// the window has actually been observed. All three come off the same buckets, so the number and
// the graph beside it can never disagree.
function vv_uptime_period(array $buckets, int $n, string $unit): array {
$series = vv_auth_uptime_series($buckets, $n, $unit);
return [
'pct' => vv_auth_uptime_window($buckets, $n),
'series' => $series,
'have' => count(array_filter($series, fn($v) => $v !== null)),
'want' => $n,
];
}
function vv_auth_action_allowed(string $action): bool {
$panel = VV_AUTH_ACTION_PANEL[$action] ?? null;
// Unmapped actions are left to the existing "Unknown action" answer rather than being refused
@@ -190,6 +203,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
'last_change' => $r['last_change'] ?? null,
'last_detail' => $r['last_detail'] ?? null,
'last_ms' => $r['last_ms'] ?? null,
// The history card below the table. One aligned series per period rather than the
// raw buckets: the client would otherwise have to re-derive calendar keys to know
// which of thirty slots a given day belongs in, and there would then be two
// implementations of that rule in two languages.
//
// `have` is what actually exists, so the card can say "collecting — 2 of 30 days"
// instead of printing a percentage computed from two days as though it were a
// month. The store began 2026-08-15; every window longer than a day is partial
// for a while, and a confident figure over a short sample is the one thing this
// card must not do.
'hist' => [
'h24' => vv_uptime_period($r['hours'] ?? [], 24, 'hour'),
'd7' => vv_uptime_period($r['days'] ?? [], 7, 'day'),
'd30' => vv_uptime_period($r['days'] ?? [], 30, 'day'),
'm12' => vv_uptime_period($r['months'] ?? [], 12, 'month'),
],
];
}
echo json_encode(['ok' => true, 'domains' => $out, 'last_pass' => $u['last_pass'] ?? null]);