This commit is contained in:
Michael Zhang 2024-05-31 20:37:21 -05:00
parent 787c112f15
commit d522537423
7 changed files with 45 additions and 12 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ node_modules
.venv
prisma/dev.db*
logs.txt

BIN
bun.lockb

Binary file not shown.

25
main.ts
View file

@ -2,7 +2,7 @@ import "dotenv/config";
import Datastore from "nedb";
import WebSocket from "ws";
import { createInterface } from "readline";
import { Channel, Client, Score } from "osu-web.js";
import { Client, type Channel, type Score } from "osu-web.js";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
@ -196,9 +196,14 @@ async function scrapeChannels() {
}
async function getStats(elapsed) {
// console.clear();
const result = await prisma.score.count();
const users = (await prisma.score.groupBy({ by: ["user_id"] })).length;
console.log(
`${result} total scores (prev query: ${Math.round(elapsed / 10) / 100}s)`,
`${result} total scores, ${users} total users, (prev query: ${
Math.round(elapsed / 10) / 100
}s)`,
);
const result2 = await prisma.$queryRaw`
@ -215,14 +220,10 @@ async function getStats(elapsed) {
}
}
async function mainLoop() {
while (true) {
const start = performance.now();
await scrapeChannels();
const end = performance.now();
await getStats(end - start);
await sleep(10000);
}
while (true) {
const start = performance.now();
await scrapeChannels();
const end = performance.now();
await getStats(end - start);
await Bun.sleep(10000);
}
mainLoop();

View file

@ -6,6 +6,7 @@
"osu-web.js": "^2.4.0"
},
"devDependencies": {
"@types/bun": "^1.1.3",
"@types/nedb": "^1.8.16",
"@types/ws": "^8.5.10",
"prisma": "^5.14.0"

View file

@ -0,0 +1,5 @@
-- CreateIndex
CREATE INDEX "Score_user_id_idx" ON "Score"("user_id");
-- CreateIndex
CREATE INDEX "Transition_user_id_idx" ON "Transition"("user_id");

View file

@ -49,6 +49,7 @@ model Score {
transition_to Transition[] @relation("after")
@@unique([user_id, beatmap_id, created_at, score])
@@index([user_id])
}
model Transition {
@ -61,4 +62,5 @@ model Transition {
ms_between BigInt
@@id([before_id, after_id])
@@index([user_id])
}

23
tsconfig.json Normal file
View file

@ -0,0 +1,23 @@
{
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noPropertyAccessFromIndexSignature": true
}
}