Initial web
This commit is contained in:
38
web/lib/sessions.ts
Normal file
38
web/lib/sessions.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user