Initial web

This commit is contained in:
Caesar2011
2026-05-17 19:55:53 +02:00
parent 6e3499812e
commit 20ed6ee9fb
58 changed files with 8541 additions and 0 deletions

38
web/lib/sessions.ts Normal file
View File

@@ -0,0 +1,38 @@
import pool from '@/lib/db';
import type { SessionBoundary } from '@/lib/types';
/**
* Returns session-start timestamps where any gap > 30 min exists
* in the global tick_timing timeline.
*/
export async function getSessionBoundaries(
from: Date,
to: Date,
): Promise<SessionBoundary[]> {
const result = await pool.query<{ real_time: Date; game_tick: string }>(
`SELECT real_time, game_tick
FROM tick_timing
WHERE real_time BETWEEN $1 AND $2
ORDER BY real_time ASC`,
[from, to],
);
const rows = result.rows;
if (rows.length === 0) return [];
const boundaries: SessionBoundary[] = [{
real_time: rows[0].real_time.toISOString(),
game_tick: parseInt(rows[0].game_tick, 10),
}];
for (let i = 1; i < rows.length; i++) {
if (rows[i].real_time.getTime() - rows[i - 1].real_time.getTime() > 30 * 60 * 1000) {
boundaries.push({
real_time: rows[i].real_time.toISOString(),
game_tick: parseInt(rows[i].game_tick, 10),
});
}
}
return boundaries;
}