Per-player playtime tracking + sparkline hover tooltips
- New GET /api/players/playtime (authed): reads each vanilla stats file
under /home/minecraft/server/world/stats and maps uuid→name via
usercache.json. Returns playtime in ticks and hours, plus file mtime
as "last seen". Memoized 60s via lib/cache#memoAsync.
- New PlaytimeLeaderboard card in the Players tab:
- Rank, avatar (click → PlayerDrawer), relative last-seen, hours.
- Top 10 by default with toggle to show all; combined hours badge.
- PlayerDrawer surfaces the player's total hours + last-seen using the
same cached playtime query, plus fills in UUID if the player is not
in ops/whitelist/banned.
- lib/time.ts: formatHours() — minutes under 1h, "H.Hh" under a day,
"Dd Hh" above.
- Analytics sparklines gain hover/touch tooltips:
- Timestamps threaded through from each MetricEntry.
- SVG overlay captures onMouseMove/onTouchMove, computes nearest
index by x, draws a dashed guide line + focus dot.
- Floating tooltip shows HH:MM + formatted value with unit; edge
clamping keeps it in-frame at the extremes.
- Per-chart formatValue so RAM shows GB, CPU 0 decimals, Players
integer, TPS 1 decimal. Keeps the peak-player marker intact.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7ada9ec7d9
commit
9ccd4ca772
6 changed files with 413 additions and 38 deletions
13
lib/time.ts
13
lib/time.ts
|
|
@ -15,6 +15,19 @@ export function timeAgo(iso: string | number | Date): string {
|
|||
return `${yr}y ago`;
|
||||
}
|
||||
|
||||
// Format a duration in hours as "H.Hh" under a day, otherwise "Dd Hh".
|
||||
export function formatHours(hours: number): string {
|
||||
if (!isFinite(hours) || hours <= 0) return "0h";
|
||||
if (hours < 1) {
|
||||
const m = Math.round(hours * 60);
|
||||
return `${m}m`;
|
||||
}
|
||||
if (hours < 24) return `${hours.toFixed(1)}h`;
|
||||
const days = Math.floor(hours / 24);
|
||||
const rem = Math.round(hours - days * 24);
|
||||
return rem ? `${days}d ${rem}h` : `${days}d`;
|
||||
}
|
||||
|
||||
export function formatBytes(n: number): string {
|
||||
if (!isFinite(n) || n <= 0) return "0 B";
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue