Skip to content

Commit 29ed30b

Browse files
committed
Add script for viewing statistics
1 parent 5404bae commit 29ed30b

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"repeatbookrsh": "npm run rr && npm run bookrs && npm run healthrs",
6060
"flc": "npm run format && npm run lint && npm run check",
6161
"updateDurations": "pnpx vite-node --options.transformMode.ssr='/.*/' scripts/updateDatabaseDurations.ts",
62-
"stats": "pnpx vite-node --options.transformMode.ssr='/.*/' scripts/createStatistics.ts"
62+
"stats": "pnpx vite-node --options.transformMode.ssr='/.*/' scripts/createStatistics.ts",
63+
"vstats": "pnpx vite-node --options.transformMode.ssr='/.*/' scripts/viewStatistics.ts"
6364
},
6465
"devDependencies": {
6566
"@eslint/compat": "^1.2.5",

scripts/viewStatistics.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { db } from '../src/lib/server/db/index.js';
2+
3+
async function getTours() {
4+
return await db.selectFrom('tour').where('tour.approachAndReturnM', 'is not', null).selectAll().execute();
5+
}
6+
7+
async function getRsTours() {
8+
return await db.selectFrom('rideShareTour').where('rideShareTour.approachAndReturnM', 'is not', null).selectAll().execute();
9+
}
10+
11+
type Tours = Awaited<ReturnType<typeof getTours>>;
12+
type RsTours = Awaited<ReturnType<typeof getRsTours>>;
13+
14+
async function viewStatistics() {
15+
const tours = await getTours();
16+
const tourEntries = {
17+
all: createEntries(tours),
18+
cancelled: createEntries(tours.filter((t) => t.cancelled)),
19+
uncancelledTours: createEntries(tours.filter((t) => !t.cancelled))
20+
}
21+
22+
const rsTours = await getRsTours();
23+
const rsTourEntries = {
24+
all: createRsEntries(rsTours),
25+
cancelled: createRsEntries(rsTours.filter((t) => t.cancelled)),
26+
uncancelledTours: createRsEntries(rsTours.filter((t) => !t.cancelled))
27+
}
28+
console.log("TAXI");
29+
console.log(JSON.stringify(tourEntries,null,2));
30+
console.log();
31+
console.log("RIDE SHARE");
32+
console.log(JSON.stringify(rsTourEntries,null,2));
33+
}
34+
35+
function createEntries(tours: Tours) {
36+
return {
37+
count: tours.length,
38+
approachAndReturnM: tours.reduce((prev, curr) => prev += curr.approachAndReturnM!, 0),
39+
fullyPayedM: tours.reduce((prev, curr) => prev += curr.fullyPayedM!, 0),
40+
occupiedM: tours.reduce((prev, curr) => prev+= curr.occupiedM!, 0)
41+
}
42+
}
43+
44+
function createRsEntries(tours: RsTours) {
45+
return {
46+
count: tours.length,
47+
approachAndReturnM: tours.reduce((prev, curr) => prev += curr.approachAndReturnM!, 0),
48+
fullyPayedM: tours.reduce((prev, curr) => prev += curr.fullyPayedM!, 0),
49+
occupiedM: tours.reduce((prev, curr) => prev+= curr.occupiedM!, 0)
50+
}
51+
}
52+
53+
viewStatistics().catch((error) => {
54+
console.error('Error in main function:', error);
55+
});

0 commit comments

Comments
 (0)