-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.js
45 lines (40 loc) · 1.42 KB
/
stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import admin from 'firebase-admin';
import { get } from 'firebase/database';
import serviceAccount from './service-account-key.json' assert { type: "json" };
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: process.env['VITE_FIREBASE_DATABASE_URL'],
});
const printRow = function(...params) {
process.stdout.write(params.join('\t'));
process.stdout.write('\n');
}
const main = async function() {
const root = admin.database().ref('room');
printRow(
'roomId',
'url',
'currentTime',
'paused',
'isLocalMode',
'minutesWatched',
'updatedAt',
'createdAt',
)
const rooms = await get(root);
for (const [roomId, room] of Object.entries(rooms.val())) {
if (!room) continue;
const minutesWatched = room.minutesWatched && typeof room.minutesWatched === 'object' && Object.values(room.minutesWatched).reduce((a, b) => a + b);
printRow(
roomId,
room.url?.value,
room.currentTime?.value,
room.paused?.value,
room.isLocalMode?.value,
minutesWatched,
room.currentTime?.updatedAt && new Date(room.currentTime?.updatedAt * 1000).toISOString(),
room.createdAt && new Date(room.createdAt * 1000).toISOString()
);
}
};
main().catch(e => process.stderr.write(e.toString())).finally(() => process.exit(0));