Some analtics work

This commit is contained in:
Jocelyn Badgley (Twipped) 2021-03-22 18:26:45 -07:00
parent c8537b3ac9
commit 131be58887
2 changed files with 26 additions and 4 deletions

View File

@ -98,6 +98,8 @@ async function* loadFiles () {
); );
`); `);
await db.run('PRAGMA busy_timeout = 6000');
const stmt = await db.prepare(sql` const stmt = await db.prepare(sql`
REPLACE INTO records VALUES ( REPLACE INTO records VALUES (
:dts, :dts,
@ -122,6 +124,8 @@ async function* loadFiles () {
); );
`); `);
let counter = 0;
await pipeline( await pipeline(
Readable.from(loadFiles()), Readable.from(loadFiles()),
parser, parser,
@ -180,7 +184,7 @@ async function* loadFiles () {
client_end: sessionEnd ? format(new Date(sessionStart), 'yyyy-MM-dd HH:mm:ss') : null, client_end: sessionEnd ? format(new Date(sessionStart), 'yyyy-MM-dd HH:mm:ss') : null,
duration, duration,
language, language,
viewed, scrolled: viewed,
max_scroll, max_scroll,
page_height, page_height,
viewport_height, viewport_height,
@ -202,15 +206,24 @@ async function* loadFiles () {
write (record, encoding, done) { write (record, encoding, done) {
(async () => { (async () => {
const params = Object.fromEntries( const params = Object.fromEntries(
Object.entries(record).map(([ k, v ]) => [ ':' + k, v ]), Object.entries(record).map(([ k, v ]) => [ ':' + k, v || null ]),
); );
await stmt.run(params); while (true) {
process.stdout.write('.'); try {
await stmt.run(params);
break;
} catch (err) {
if (err.code !== 'SQLITE_BUSY') throw err;
}
}
counter++;
if (!(counter % 10)) process.stdout.write('.');
})().then(() => done(), done); })().then(() => done(), done);
}, },
}), }),
); );
await stmt.finalize();
await db.close(); await db.close();
})().then( })().then(

View File

@ -11,3 +11,12 @@ FROM records
WHERE duration > 1 AND duration < (60 * 30) WHERE duration > 1 AND duration < (60 * 30)
GROUP BY duration / 60 GROUP BY duration / 60
HAVING total > 5; HAVING total > 5;
SELECT referrer_host, count(DISTINCT IFNULL(tid, ip)) as tids, referrer
FROM records
GROUP BY referrer_host;
SELECT COUNT(IFNULL(tid,ip)) as total, referrer
FROM records
WHERE referrer_host LIKE '%reddit.com'
GROUP BY referrer