Created a few helper scripts to dump some refined analytics

This commit is contained in:
Jocelyn Badgley
2023-05-20 13:55:18 -07:00
parent 1a12e0ca1e
commit aa368614b1
2 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
const path = require('path');
const { open: opensql } = require('sqlite');
const sqlite3 = require('sqlite3');
const sql = require('../sql-tag');
(async () => {
// open the database
const db = await opensql({
filename: path.resolve(__dirname, '..', 'database.sqlite'),
driver: sqlite3.Database,
});
const rows = await db.all(sql`
SELECT
date(dts) as day,
count(DISTINCT IFNULL(tid, ip)) as tids
FROM records
WHERE date(dts) > date('now', '-12 month')
GROUP BY date(dts);
`);
// console.table(results);
for (const { day, tids } of rows) {
process.stdout.write(day + '\t' + tids + '\n');
}
})().catch(console.error);