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
+25
View File
@@ -332,6 +332,31 @@ function vv_auth_uptime_window(array $buckets, int $n): ?float {
return $t > 0 ? round($u / $t * 100, 2) : null;
}
// The same buckets as a drawable series: one entry per period on the calendar, oldest first, null
// where nothing was recorded. Aligned to the clock rather than packed, because the gap is the
// information — a domain probed for two of the last thirty days must read as twenty-eight unknowns
// and not as a solid bar chart that happens to be short.
//
// Keys are built with mktime rather than strtotime("-N month"), which resolves relative to today's
// day-of-month and skips a month entirely when run on the 31st.
function vv_auth_uptime_series(array $buckets, int $n, string $unit, ?int $now = null): array {
$now = $now ?? time();
[$Y, $M, $D, $H] = [(int) date('Y', $now), (int) date('n', $now),
(int) date('j', $now), (int) date('G', $now)];
$out = [];
for ($i = $n - 1; $i >= 0; $i--) {
// mktime normalises underflow, so hour -3 is 21:00 the previous day and month 0 is December.
[$fmt, $ts] = match ($unit) {
'hour' => ['YmdH', mktime($H - $i, 0, 0, $M, $D, $Y)],
'month' => ['Ym', mktime(0, 0, 0, $M - $i, 1, $Y)],
default => ['Ymd', mktime(0, 0, 0, $M, $D - $i, $Y)],
};
$b = $buckets[date($fmt, $ts)] ?? null;
$out[] = ($b && ($b['t'] ?? 0) > 0) ? round($b['u'] / $b['t'] * 100, 2) : null;
}
return $out;
}
function vv_auth_db_file(string $name): string {
return rtrim(defined('DB_DIR') ? DB_DIR : (DATA_DIR . '/db'), '/') . '/' . $name;
}