mirror of
https://github.com/pupperpowell/bibdle.git
synced 2026-02-04 10:54:44 -05:00
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import Database from 'bun:sqlite';
|
|
|
|
// Database path - adjust if your database is located elsewhere
|
|
const dbPath = process.env.DATABASE_URL || './local.db';
|
|
|
|
console.log(`Connecting to database: ${dbPath}`);
|
|
|
|
const db = new Database(dbPath);
|
|
|
|
// Query all rows from daily_completions
|
|
const query = db.query(`
|
|
SELECT date, guess_count
|
|
FROM daily_completions
|
|
ORDER BY date
|
|
`);
|
|
|
|
const rows = query.all() as { date: string; guess_count: number }[];
|
|
|
|
if (rows.length === 0) {
|
|
console.log('No completions found in the database.');
|
|
db.close();
|
|
process.exit(0);
|
|
}
|
|
|
|
// Group by date and calculate average guesses
|
|
const dateStats = new Map<string, { total: number; count: number }>();
|
|
|
|
for (const row of rows) {
|
|
const existing = dateStats.get(row.date) || { total: 0, count: 0 };
|
|
existing.total += row.guess_count;
|
|
existing.count += 1;
|
|
dateStats.set(row.date, existing);
|
|
}
|
|
|
|
// Display results
|
|
console.log('\n=== Average Guesses Per Day ===\n');
|
|
console.log('Date | Avg Guesses | Total Completions');
|
|
console.log('--------------|-------------|-------------------');
|
|
|
|
for (const [date, stats] of dateStats) {
|
|
const avg = (stats.total / stats.count).toFixed(2);
|
|
console.log(`${date.padEnd(14)}| ${avg.padStart(11)}| ${stats.count.toString().padStart(19)}`);
|
|
}
|
|
|
|
// Calculate overall average
|
|
const totalGuesses = Array.from(dateStats.values()).reduce((sum, s) => sum + s.total, 0);
|
|
const totalCompletions = Array.from(dateStats.values()).reduce((sum, s) => sum + s.count, 0);
|
|
const overallAvg = (totalGuesses / totalCompletions).toFixed(2);
|
|
|
|
console.log('--------------|-------------|-------------------');
|
|
console.log(`Overall Average: ${overallAvg} guesses across ${totalCompletions} completions`);
|
|
|
|
db.close();
|