88 Commits

Author SHA1 Message Date
fc0cb210cc fix(deps): update dependency express to v4.19.2 2024-04-17 15:01:27 +00:00
f621f6c5ae attempt to close the old socket
All checks were successful
deploy / deploy (push) Successful in 20s
2024-01-16 15:37:58 +00:00
3621941a0d e
All checks were successful
deploy / deploy (push) Successful in 22s
2024-01-16 15:36:30 +00:00
fe15f660e6 e
All checks were successful
deploy / deploy (push) Successful in 36s
2024-01-16 15:33:50 +00:00
5c2416e7ee e
Some checks failed
deploy / deploy (push) Has been cancelled
2024-01-16 15:33:11 +00:00
46efd6b6dc Merge branch 'master' of https://git.fascinated.cc/Fascinated/beatsaber-metrics-tracker
Some checks failed
deploy / deploy (push) Failing after 23s
2024-01-16 15:31:32 +00:00
7749a570d6 impl a simple dead socket handler 2024-01-16 15:29:59 +00:00
Lee
62cbe6141d Merge pull request 'fix(deps): update dependency @sentry/node to v7.83.0' (#27) from renovate/sentry-javascript-monorepo into master
All checks were successful
deploy / deploy (push) Successful in 34s
Reviewed-on: #27
2023-11-30 08:31:23 +00:00
Lee
b8f0d84f69 Merge pull request 'chore(deps): update dependency @types/node to v20.10.1' (#29) from renovate/node-20.x-lockfile into master
Some checks failed
deploy / deploy (push) Has been cancelled
Reviewed-on: #29
2023-11-30 08:31:18 +00:00
Lee
5a8b3556b3 Merge pull request 'fix(deps): update dependency mongoose to v8.0.2' (#28) from renovate/mongoose-8.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 1m1s
Reviewed-on: #28
2023-11-30 08:29:32 +00:00
9a12e65f8a chore(deps): update dependency @types/node to v20.10.1 2023-11-29 20:00:57 +00:00
b99e8e979c fix(deps): update dependency mongoose to v8.0.2 2023-11-28 22:00:58 +00:00
6d213dd3eb fix(deps): update dependency @sentry/node to v7.83.0 2023-11-28 12:00:55 +00:00
Lee
454e1f2914 Merge pull request 'chore(deps): update dependency @types/node to v20.10.0' (#25) from renovate/node-20.x-lockfile into master
Some checks failed
deploy / deploy (push) Failing after 5s
Reviewed-on: #25
2023-11-27 18:11:02 +00:00
Lee
7f0ab00e3b Merge pull request 'chore(deps): update dependency @types/websocket to v1.0.10' (#24) from renovate/websocket-1.x-lockfile into master
Some checks failed
deploy / deploy (push) Has been cancelled
Reviewed-on: #24
2023-11-27 18:10:56 +00:00
Lee
b291c10402 Merge pull request 'fix(deps): update dependency typescript to v5.3.2' (#23) from renovate/typescript-5.x-lockfile into master
Some checks failed
deploy / deploy (push) Has been cancelled
Reviewed-on: #23
2023-11-27 18:10:50 +00:00
Lee
06ea301120 Merge pull request 'fix(deps): update dependency @sentry/node to v7.82.0' (#26) from renovate/sentry-javascript-monorepo into master
Some checks are pending
deploy / deploy (push) Waiting to run
Reviewed-on: #26
2023-11-27 18:10:45 +00:00
7943fabcca fix(deps): update dependency @sentry/node to v7.82.0 2023-11-27 18:00:41 +00:00
9189f510db fix(deps): update dependency typescript to v5.3.2 2023-11-24 10:00:42 +00:00
4afbb8f468 chore(deps): update dependency @types/node to v20.10.0 2023-11-24 10:00:39 +00:00
19dbd63c33 chore(deps): update dependency @types/websocket to v1.0.10 2023-11-24 10:00:36 +00:00
Lee
6ed9d3e3b5 Merge pull request 'fix(deps): update dependency @sentry/node to v7.81.1' (#22) from renovate/sentry-javascript-monorepo into master
All checks were successful
deploy / deploy (push) Successful in 1m2s
Reviewed-on: #22
2023-11-24 09:15:41 +00:00
Lee
3b76431cb9 Merge pull request 'chore(deps): update dependency @types/node to v20.9.5' (#21) from renovate/node-20.x-lockfile into master
Some checks failed
deploy / deploy (push) Has been cancelled
Reviewed-on: #21
2023-11-24 09:15:29 +00:00
cd33aae6ce chore(deps): update dependency @types/node to v20.9.5 2023-11-24 01:00:59 +00:00
a086f540ad fix(deps): update dependency @sentry/node to v7.81.1 2023-11-23 23:00:47 +00:00
Lee
d34c35ef5e Merge pull request 'fix(deps): update dependency @sentry/node to v7.80.1' (#18) from renovate/sentry-javascript-monorepo into master
All checks were successful
deploy / deploy (push) Successful in 33s
Reviewed-on: #18
2023-11-16 06:51:33 +00:00
Lee
7e2db095ec Merge pull request 'fix(deps): update dependency axios to v1.6.2' (#19) from renovate/axios-1.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 33s
Reviewed-on: #19
2023-11-16 06:50:25 +00:00
Lee
7f0415a1e5 Merge pull request 'fix(deps): update dependency mongoose to v8.0.1' (#20) from renovate/mongoose-8.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 1m6s
Reviewed-on: #20
2023-11-16 06:48:56 +00:00
3a3cdd89df fix(deps): update dependency mongoose to v8.0.1 2023-11-15 17:01:25 +00:00
cdbe6e519d fix(deps): update dependency axios to v1.6.2 2023-11-14 21:01:17 +00:00
afd65d2e91 fix(deps): update dependency @sentry/node to v7.80.1 2023-11-14 11:01:05 +00:00
Lee
1083f58372 Merge pull request 'fix(deps): update dependency @sentry/node to v7.80.0' (#17) from renovate/sentry-javascript-monorepo into master
All checks were successful
deploy / deploy (push) Successful in 35s
Reviewed-on: #17
2023-11-09 17:59:34 +00:00
0f6fe18257 fix(deps): update dependency @sentry/node to v7.80.0 2023-11-09 17:01:15 +00:00
Lee
f475e9c287 Merge pull request 'fix(deps): update dependency @sentry/node to v7.79.0' (#14) from renovate/sentry-javascript-monorepo into master
All checks were successful
deploy / deploy (push) Successful in 34s
Reviewed-on: #14
2023-11-08 19:31:45 +00:00
Lee
df40071d06 Merge pull request 'fix(deps): update dependency node-cron to v3.0.3' (#15) from renovate/node-cron-3.x-lockfile into master
Some checks failed
deploy / deploy (push) Has been cancelled
Reviewed-on: #15
2023-11-08 19:31:30 +00:00
Lee
ec91033104 Merge pull request 'fix(deps): update dependency axios to v1.6.1' (#16) from renovate/axios-1.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 34s
Reviewed-on: #16
2023-11-08 19:30:43 +00:00
aaff6f8ac2 fix(deps): update dependency @sentry/node to v7.79.0 2023-11-08 17:01:27 +00:00
793b80e216 fix(deps): update dependency axios to v1.6.1 2023-11-08 16:01:15 +00:00
ba005cbfd5 fix(deps): update dependency node-cron to v3.0.3 2023-11-08 15:01:14 +00:00
Lee
f9077f739c use real player count
All checks were successful
deploy / deploy (push) Successful in 30s
2023-11-08 07:43:00 +00:00
Lee
5b3e7e8198 Merge pull request 'chore(deps): update dependency @types/express to v4.17.21' (#10) from renovate/express-4.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 35s
Reviewed-on: #10
2023-11-08 06:48:24 +00:00
Lee
434b0a3e99 Merge pull request 'chore(deps): update dependency @types/websocket to v1.0.9' (#11) from renovate/websocket-1.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 34s
Reviewed-on: #11
2023-11-08 06:47:35 +00:00
b9dedbc603 switch to pnpm 2023-11-08 06:45:46 +00:00
Lee
b9ae192b00 Merge pull request 'chore(deps): update dependency @types/node-cron to v3.0.11' (#12) from renovate/node-cron-3.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 36s
Reviewed-on: #12
2023-11-08 06:43:16 +00:00
Lee
3db3cff285 Merge pull request 'chore(deps): update dependency @types/node to v20.9.0' (#13) from renovate/node-20.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 36s
Reviewed-on: #13
2023-11-08 06:42:32 +00:00
3f605dc15f add comments
All checks were successful
deploy / deploy (push) Successful in 37s
2023-11-08 06:41:35 +00:00
e8d2b3db9a chore(deps): update dependency @types/node to v20.9.0 2023-11-07 21:01:11 +00:00
18882f9ec4 chore(deps): update dependency @types/node-cron to v3.0.11 2023-11-07 21:01:04 +00:00
c1cb3141bc chore(deps): update dependency @types/websocket to v1.0.9 2023-11-07 20:00:39 +00:00
055e314731 chore(deps): update dependency @types/express to v4.17.21 2023-11-07 04:00:36 +00:00
1532b0fb4a feat(beatsaver): log json data on error
All checks were successful
deploy / deploy (push) Successful in 29s
2023-11-01 22:51:23 +00:00
39205498ea add beatsaver stats
All checks were successful
deploy / deploy (push) Successful in 41s
2023-11-01 21:50:55 +00:00
f1645d9714 re-enable player ids in scores
All checks were successful
deploy / deploy (push) Successful in 36s
2023-11-01 17:07:16 +00:00
Lee
2703adcb0b Merge pull request 'fix(deps): update dependency mongoose to v8' (#9) from renovate/mongoose-8.x into master
All checks were successful
deploy / deploy (push) Successful in 36s
Reviewed-on: #9
2023-10-31 15:44:45 +00:00
3548071f35 fix(deps): update dependency mongoose to v8 2023-10-31 15:01:11 +00:00
42de0a39f3 make cronjob every min instead of every 5
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-31 14:26:09 +00:00
9c5115b9e1 sentry typescript stuff
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-31 14:24:11 +00:00
4c6a8c80fb add sentry
All checks were successful
deploy / deploy (push) Successful in 33s
2023-10-31 14:22:06 +00:00
e0363de4ad set total scores less often - will savve data
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-31 14:07:26 +00:00
ec0fe68eab Merge branch 'master' of https://git.fascinated.cc/Fascinated/beatsaber-metrics-tracker
All checks were successful
deploy / deploy (push) Successful in 30s
2023-10-31 13:54:36 +00:00
9f66300b35 remove leaderboard_id and player_id - should help save data 2023-10-31 13:54:33 +00:00
Lee
189ef91850 Merge pull request 'chore(deps): update dependency @types/node to v20.8.10' (#8) from renovate/node-20.x-lockfile into master
All checks were successful
deploy / deploy (push) Successful in 32s
Reviewed-on: #8
2023-10-31 11:30:56 +00:00
Lee
3a70416bef Merge pull request 'fix(deps): update dependency mongoose to v7.6.4' (#7) from renovate/mongoose-7.x-lockfile into master
Some checks failed
deploy / deploy (push) Has been cancelled
Reviewed-on: #7
2023-10-31 11:30:48 +00:00
bc650bcd47 chore(deps): update dependency @types/node to v20.8.10 2023-10-31 09:01:10 +00:00
50f6436c20 fix(deps): update dependency mongoose to v7.6.4 2023-10-30 23:01:11 +00:00
bd992ad0e5 add more hmd names
All checks were successful
deploy / deploy (push) Successful in 30s
2023-10-30 21:06:27 +00:00
410dc1c52c change how score stats are stored - much cleaner
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-30 20:14:50 +00:00
d023efe9e6 scores with acc stuff
All checks were successful
deploy / deploy (push) Successful in 27s
2023-10-30 16:55:45 +00:00
9fbf212754 update averages faster
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-30 16:32:35 +00:00
56aea4a613 fix ranked scores history
All checks were successful
deploy / deploy (push) Successful in 30s
2023-10-30 16:32:08 +00:00
28898fdd56 fix ranked scores history 2023-10-30 16:31:52 +00:00
ea3a0d2753 many fixes
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-30 16:08:47 +00:00
37d86b7a7d add comments and fix score deletion
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-30 15:49:06 +00:00
41661059a0 get actual heaset name and get long region name
Some checks failed
deploy / deploy (push) Failing after 31s
2023-10-30 15:45:35 +00:00
9984b416b6 fix country
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-30 15:33:33 +00:00
b348969089 update how countries and hmds are stored
All checks were successful
deploy / deploy (push) Successful in 39s
2023-10-30 15:27:10 +00:00
4be7a46a90 fix deps
All checks were successful
deploy / deploy (push) Successful in 33s
2023-10-30 15:13:23 +00:00
1520340bf4 add country to score point
Some checks failed
deploy / deploy (push) Failing after 34s
2023-10-30 15:08:56 +00:00
12000f7de8 isNaN checks
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-30 15:05:28 +00:00
a19cf7e448 fix bug
Some checks failed
deploy / deploy (push) Failing after 24s
2023-10-30 15:03:29 +00:00
f9021413d4 add score averages data
Some checks failed
deploy / deploy (push) Failing after 31s
2023-10-30 15:01:08 +00:00
6d4d1e782f update default time
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-27 18:26:20 +01:00
b720e96431 add score count history
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-27 18:23:13 +01:00
3c8b605fec switch to axios
All checks were successful
deploy / deploy (push) Successful in 32s
2023-10-27 16:30:30 +01:00
8d2cd9a234 update longer intervals
All checks were successful
deploy / deploy (push) Successful in 30s
2023-10-27 16:28:15 +01:00
e09ee235bc fix bug
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-27 16:21:32 +01:00
63662a6074 fix a silly
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-27 16:18:49 +01:00
42485166bf return less data if long time frame
All checks were successful
deploy / deploy (push) Successful in 29s
2023-10-27 16:16:07 +01:00
16 changed files with 2126 additions and 216 deletions

4
.gitignore vendored
View File

@ -144,3 +144,7 @@ dist
# Built Visual Studio Code Extensions
*.vsix
# lock files
package-lock.json
yarn.lock

View File

@ -1,9 +1,10 @@
FROM node:alpine
FROM fascinated/docker-images:node-pnpm-latest
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY package.json pnpm-lock.yaml ./
RUN pnpm install
COPY . .
RUN npx tsc -b
RUN pnpm run build
ENV PORT=80
EXPOSE 80
CMD [ "npm", "start" ]
CMD [ "pnpm", "start" ]

335
package-lock.json generated
View File

@ -10,10 +10,12 @@
"license": "ISC",
"dependencies": {
"@influxdata/influxdb-client": "^1.33.2",
"@sentry/node": "^7.77.0",
"axios": "^1.6.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mongoose": "^7.6.3",
"node-fetch": "^2.6.1",
"mongoose": "^8.0.0",
"node-cron": "^3.0.2",
"nodemon": "^3.0.1",
"typescript": "^5.2.2",
"websocket": "^1.0.34"
@ -21,7 +23,7 @@
"devDependencies": {
"@types/express": "^4.17.20",
"@types/node": "^20.8.9",
"@types/node-fetch": "^2.6.1",
"@types/node-cron": "^3.0.10",
"@types/websocket": "^1.0.8"
}
},
@ -34,11 +36,69 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.0.tgz",
"integrity": "sha512-Xfijy7HvfzzqiOAhAepF4SGN5e9leLkMvg/OPOF97XemjfVCYN/oWa75wnkc6mltMSTwY+XlbhWgUOJmkFspSw==",
"optional": true,
"dependencies": {
"sparse-bitfield": "^3.0.3"
}
},
"node_modules/@sentry-internal/tracing": {
"version": "7.83.0",
"resolved": "https://registry.npmjs.org/@sentry-internal/tracing/-/tracing-7.83.0.tgz",
"integrity": "sha512-fY1ZyOiQaaUTuoq5rO+G4/5Ov3n8BnfNK7ck97yAGxy3w+E1CwhVZkXHEvTngNfdYV3ArxvlrtPRb9STFRqXvQ==",
"dependencies": {
"@sentry/core": "7.83.0",
"@sentry/types": "7.83.0",
"@sentry/utils": "7.83.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/core": {
"version": "7.83.0",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-7.83.0.tgz",
"integrity": "sha512-fglvpw8aWM6nWXzCjAVXIMTiTEAQ9G9b85IpDd/7L8fuwaFTPQAUSJXupF2PfbpQ3FUYbJt80dxshbERVJG8vQ==",
"dependencies": {
"@sentry/types": "7.83.0",
"@sentry/utils": "7.83.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/node": {
"version": "7.83.0",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-7.83.0.tgz",
"integrity": "sha512-ibnON+5ovoGOsvcLxcWQu5XAc4rbkvDkzCP74YGnME3/NzRuo3cKam8bUL5Wlm15h68QzxskyNOLuj6BEJ6AfQ==",
"dependencies": {
"@sentry-internal/tracing": "7.83.0",
"@sentry/core": "7.83.0",
"@sentry/types": "7.83.0",
"@sentry/utils": "7.83.0",
"https-proxy-agent": "^5.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/types": {
"version": "7.83.0",
"resolved": "https://registry.npmjs.org/@sentry/types/-/types-7.83.0.tgz",
"integrity": "sha512-Bd+zJcy8p1VgCfQqUprmUaw0QPWUV+GmCt6zJRHrHTb2pwLahXv6sHJvQ8F8Va6S7Keuy088U+kHzUFGQLMZMQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/@sentry/utils": {
"version": "7.83.0",
"resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-7.83.0.tgz",
"integrity": "sha512-7SrZtgAn3pHFBqSSvV/VL0CWTBQ7VenJjok4+WGWd6/FhP3fKrEEd9rjVTUb2Pzq9WLJJYzdvxAG8RlggG+H4g==",
"dependencies": {
"@sentry/types": "7.83.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/@types/body-parser": {
"version": "1.19.4",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.4.tgz",
@ -59,9 +119,9 @@
}
},
"node_modules/@types/express": {
"version": "4.17.20",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.20.tgz",
"integrity": "sha512-rOaqlkgEvOW495xErXMsmyX3WKBInbhG5eqojXYi3cGUaLoRDlXa5d52fkfWZT963AZ3v2eZ4MbKE6WpDAGVsw==",
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz",
"integrity": "sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==",
"dev": true,
"dependencies": {
"@types/body-parser": "*",
@ -95,22 +155,18 @@
"dev": true
},
"node_modules/@types/node": {
"version": "20.8.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.9.tgz",
"integrity": "sha512-UzykFsT3FhHb1h7yD4CA4YhBHq545JC0YnEz41xkipN88eKQtL6rSgocL5tbAP6Ola9Izm/Aw4Ora8He4x0BHg==",
"version": "20.10.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.1.tgz",
"integrity": "sha512-T2qwhjWwGH81vUEx4EXmBKsTJRXFXNZTL4v0gi01+zyBmCwzE6TyHszqX01m+QHTEq+EZNo13NeJIdEqf+Myrg==",
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/@types/node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==",
"dev": true,
"dependencies": {
"@types/node": "*",
"form-data": "^3.0.0"
}
"node_modules/@types/node-cron": {
"version": "3.0.11",
"resolved": "https://registry.npmjs.org/@types/node-cron/-/node-cron-3.0.11.tgz",
"integrity": "sha512-0ikrnug3/IyneSHqCBeslAhlK2aBfYek1fGo4bP4QnZPmiqSGRK+Oy7ZMisLWkesffJvQ1cqAcBnJC+8+nxIAg==",
"dev": true
},
"node_modules/@types/qs": {
"version": "6.9.9",
@ -151,9 +207,9 @@
"integrity": "sha512-uNv6b/uGRLlCVmelat2rA8bcVd3k/42mV2EmjhPh6JLkd35T5bgwR/t6xy7a9MWhd9sixIeBUzhBenvk3NO+DQ=="
},
"node_modules/@types/websocket": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@types/websocket/-/websocket-1.0.8.tgz",
"integrity": "sha512-wvkOpWApbuxVfHhSQ1XrjVN4363vsfLJwEo4AboIZk0g1vJA5nmLp8GXUHuIdf4/Fe7+/V0Efe2HvWiLqHtlqw==",
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/@types/websocket/-/websocket-1.0.10.tgz",
"integrity": "sha512-svjGZvPB7EzuYS94cI7a+qhwgGU1y89wUgjT6E2wVUfmAGIvRfT7obBvRtnhXCSsoMdlG4gBFGE7MfkIXZLoww==",
"dev": true,
"dependencies": {
"@types/node": "*"
@ -185,6 +241,38 @@
"node": ">= 0.6"
}
},
"node_modules/agent-base": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
"integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
"dependencies": {
"debug": "4"
},
"engines": {
"node": ">= 6.0.0"
}
},
"node_modules/agent-base/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/agent-base/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/anymatch": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
@ -205,8 +293,17 @@
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"dev": true
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz",
"integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==",
"dependencies": {
"follow-redirects": "^1.15.0",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.2",
@ -222,12 +319,12 @@
}
},
"node_modules/body-parser": {
"version": "1.20.1",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
"version": "1.20.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
"integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
"dependencies": {
"bytes": "3.1.2",
"content-type": "~1.0.4",
"content-type": "~1.0.5",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
@ -235,7 +332,7 @@
"iconv-lite": "0.4.24",
"on-finished": "2.4.1",
"qs": "6.11.0",
"raw-body": "2.5.1",
"raw-body": "2.5.2",
"type-is": "~1.6.18",
"unpipe": "1.0.0"
},
@ -278,11 +375,11 @@
}
},
"node_modules/bson": {
"version": "5.5.1",
"resolved": "https://registry.npmjs.org/bson/-/bson-5.5.1.tgz",
"integrity": "sha512-ix0EwukN2EpC0SRWIj/7B5+A6uQMQy6KMREI9qQqvgpkV2frH63T0UDVd1SYedL6dNCmDBYB3QtXi4ISk9YT+g==",
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz",
"integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==",
"engines": {
"node": ">=14.20.1"
"node": ">=16.20.1"
}
},
"node_modules/bufferutil": {
@ -348,7 +445,6 @@
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dev": true,
"dependencies": {
"delayed-stream": "~1.0.0"
},
@ -381,9 +477,9 @@
}
},
"node_modules/cookie": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==",
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
"integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
"engines": {
"node": ">= 0.6"
}
@ -427,7 +523,6 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"dev": true,
"engines": {
"node": ">=0.4.0"
}
@ -520,16 +615,16 @@
}
},
"node_modules/express": {
"version": "4.18.2",
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
"integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==",
"version": "4.19.2",
"resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz",
"integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==",
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
"body-parser": "1.20.1",
"body-parser": "1.20.2",
"content-disposition": "0.5.4",
"content-type": "~1.0.4",
"cookie": "0.5.0",
"cookie": "0.6.0",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "2.0.0",
@ -627,11 +722,29 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/follow-redirects": {
"version": "1.15.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz",
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"dev": true,
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
@ -781,6 +894,39 @@
"node": ">= 0.8"
}
},
"node_modules/https-proxy-agent": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz",
"integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==",
"dependencies": {
"agent-base": "6",
"debug": "4"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/https-proxy-agent/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/https-proxy-agent/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -805,7 +951,9 @@
"node_modules/ip": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz",
"integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ=="
"integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==",
"optional": true,
"peer": true
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
@ -888,8 +1036,7 @@
"node_modules/memory-pager": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
"optional": true
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg=="
},
"node_modules/merge-descriptors": {
"version": "1.0.1",
@ -946,26 +1093,25 @@
}
},
"node_modules/mongodb": {
"version": "5.9.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-5.9.0.tgz",
"integrity": "sha512-g+GCMHN1CoRUA+wb1Agv0TI4YTSiWr42B5ulkiAfLLHitGK1R+PkSAf3Lr5rPZwi/3F04LiaZEW0Kxro9Fi2TA==",
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.2.0.tgz",
"integrity": "sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==",
"dependencies": {
"bson": "^5.5.0",
"mongodb-connection-string-url": "^2.6.0",
"socks": "^2.7.1"
"@mongodb-js/saslprep": "^1.1.0",
"bson": "^6.2.0",
"mongodb-connection-string-url": "^2.6.0"
},
"engines": {
"node": ">=14.20.1"
},
"optionalDependencies": {
"@mongodb-js/saslprep": "^1.1.0"
"node": ">=16.20.1"
},
"peerDependencies": {
"@aws-sdk/credential-providers": "^3.188.0",
"@mongodb-js/zstd": "^1.0.0",
"kerberos": "^1.0.0 || ^2.0.0",
"mongodb-client-encryption": ">=2.3.0 <3",
"snappy": "^7.2.2"
"@mongodb-js/zstd": "^1.1.0",
"gcp-metadata": "^5.2.0",
"kerberos": "^2.0.1",
"mongodb-client-encryption": ">=6.0.0 <7",
"snappy": "^7.2.2",
"socks": "^2.7.1"
},
"peerDependenciesMeta": {
"@aws-sdk/credential-providers": {
@ -974,6 +1120,9 @@
"@mongodb-js/zstd": {
"optional": true
},
"gcp-metadata": {
"optional": true
},
"kerberos": {
"optional": true
},
@ -982,6 +1131,9 @@
},
"snappy": {
"optional": true
},
"socks": {
"optional": true
}
}
},
@ -995,20 +1147,20 @@
}
},
"node_modules/mongoose": {
"version": "7.6.3",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-7.6.3.tgz",
"integrity": "sha512-moYP2qWCOdWRDeBxqB/zYwQmQnTBsF5DoolX5uPyI218BkiA1ujGY27P0NTd4oWIX+LLkZPw0LDzlc/7oh1plg==",
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.0.2.tgz",
"integrity": "sha512-Vsi9GzTXjdBVzheT1HZOZ2jHNzzR9Xwb5OyLz/FvDEAhlwrRnXnuqJf0QHINUOQSm7aoyvnPks0q85HJkd6yDw==",
"dependencies": {
"bson": "^5.5.0",
"bson": "^6.2.0",
"kareem": "2.5.1",
"mongodb": "5.9.0",
"mongodb": "6.2.0",
"mpath": "0.9.0",
"mquery": "5.0.0",
"ms": "2.1.3",
"sift": "16.0.1"
},
"engines": {
"node": ">=14.20.1"
"node": ">=16.20.1"
},
"funding": {
"type": "opencollective",
@ -1073,12 +1225,15 @@
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
"integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ=="
},
"node_modules/node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==",
"node_modules/node-cron": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.3.tgz",
"integrity": "sha512-dOal67//nohNgYWb+nWmg5dkFdIwDm8EpeGYMekPMrngV3637lqnX0lbUcCtgibHTz6SEz7DAIjKvKDFYCnO1A==",
"dependencies": {
"uuid": "8.3.2"
},
"engines": {
"node": "4.x || >=6.0.0"
"node": ">=6.0.0"
}
},
"node_modules/node-gyp-build": {
@ -1195,6 +1350,11 @@
"node": ">= 0.10"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/pstree.remy": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz",
@ -1231,9 +1391,9 @@
}
},
"node_modules/raw-body": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
"dependencies": {
"bytes": "3.1.2",
"http-errors": "2.0.0",
@ -1395,6 +1555,8 @@
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
"integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
"optional": true,
"peer": true,
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
@ -1404,6 +1566,8 @@
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz",
"integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==",
"optional": true,
"peer": true,
"dependencies": {
"ip": "^2.0.0",
"smart-buffer": "^4.2.0"
@ -1417,7 +1581,6 @@
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
"optional": true,
"dependencies": {
"memory-pager": "^1.0.2"
}
@ -1508,9 +1671,9 @@
}
},
"node_modules/typescript": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz",
"integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@ -1557,6 +1720,14 @@
"node": ">= 0.4.0"
}
},
"node_modules/uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

View File

@ -6,16 +6,19 @@
"scripts": {
"start": "node dist/index.js",
"tsc": "tsc -w",
"build": "tsc",
"dev": "nodemon dist/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@influxdata/influxdb-client": "^1.33.2",
"@sentry/node": "^7.77.0",
"axios": "^1.6.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mongoose": "^7.6.3",
"node-fetch": "^2.6.1",
"mongoose": "^8.0.0",
"node-cron": "^3.0.2",
"nodemon": "^3.0.1",
"typescript": "^5.2.2",
"websocket": "^1.0.34"
@ -23,7 +26,7 @@
"devDependencies": {
"@types/express": "^4.17.20",
"@types/node": "^20.8.9",
"@types/node-fetch": "^2.6.1",
"@types/node-cron": "^3.0.10",
"@types/websocket": "^1.0.8"
}
}

1381
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

47
src/api/api.ts Normal file
View File

@ -0,0 +1,47 @@
import * as Sentry from "@sentry/node";
import express from "express";
import analyticsRoute from "./routes/analytics";
const app = express();
const port = process.env.PORT || 3000;
Sentry.init({
dsn: "https://19a8f6e661f41ed26ec9c221954594cf@sentry.fascinated.cc/3",
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Sentry.Integrations.Express({ app }),
new Sentry.Integrations.OnUncaughtException(),
new Sentry.Integrations.OnUnhandledRejection(),
new Sentry.Integrations.Mongo({
useMongoose: true,
}),
],
// Performance Monitoring
tracesSampleRate: 1.0,
});
// Routes
analyticsRoute(app);
// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler() as express.RequestHandler);
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());
// The error handler must be registered before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler() as express.ErrorRequestHandler);
// Optional fallthrough error handler
app.use(function onError(err: any, req: any, res: any, next: any) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end(res.sentry + "\n");
});
app.listen(port, () => {
console.log(`API Server is running on http://localhost:${port}`);
});

View File

@ -0,0 +1,85 @@
import { INFLUXDB_BUCKET, InfluxQueryAPI } from "../..";
import { formatString } from "../../utils/stringUtils";
import { parseTimeToMilliseconds } from "../../utils/timeUtils";
// Query to get the player count history for tge last 24 hours in 1 hour intervals
const getPlayerHistoryQuery = `from(bucket: "${INFLUXDB_BUCKET}")
|> range(start: -{})
|> filter(fn: (r) => r["_measurement"] == "scoresaber")
|> filter(fn: (r) => r["type"] == "score")
|> filter(fn: (r) => r["_field"] == "player_id")
|> unique()
|> aggregateWindow(every: {}, fn: count)
`;
const getScoreCountHistoryQuery = `from(bucket: "${INFLUXDB_BUCKET}")
|> range(start: -{})
|> filter(fn: (r) => r["_measurement"] == "scoresaber")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["type"] == "score_count")
|> aggregateWindow(every: {}, fn: spread, createEmpty: true)
`;
export default function analyticsRoute(app: any) {
app.get("/analytics", async (req: any, res: any) => {
const before = new Date().getTime();
const timeQuery = req.query.time || "30d";
const timeInMs = parseTimeToMilliseconds(timeQuery.toString());
if (timeInMs > 30 * 24 * 60 * 60 * 1000) {
return res.status(400).json({
error: "Time range too large. Max time range is 30 days.",
});
}
const shouldUseLongerIntervals = timeInMs > 24 * 60 * 60 * 1000 * 7; // 7 days
const getActivePlayersHistory = async () => {
const rows = await InfluxQueryAPI.collectRows(
formatString(
getPlayerHistoryQuery,
false,
timeQuery,
shouldUseLongerIntervals ? "1d" : "1h"
)
);
let history = rows.map((row: any) => ({
time: row._time,
value: row._value !== null ? row._value.toFixed(0) : null,
}));
return history.sort(
(a: any, b: any) =>
new Date(a.time).getTime() - new Date(b.time).getTime()
);
};
const getScoreCountHistory = async () => {
const rows = await InfluxQueryAPI.collectRows(
formatString(
getScoreCountHistoryQuery,
false,
timeQuery,
shouldUseLongerIntervals ? "1d" : "1h"
)
);
let history = rows.map((row: any) => ({
time: row._time,
value: row._value !== null ? row._value.toFixed(0) : null,
}));
return history.sort(
(a: any, b: any) =>
new Date(a.time).getTime() - new Date(b.time).getTime()
);
};
const [activePlayersHistory, scoreCountHistory] = await Promise.all([
getActivePlayersHistory(),
getScoreCountHistory(),
]);
return res.json({
serverTimeTaken: new Date().getTime() - before + "ms",
activePlayersHistory,
scoreCountHistory,
});
});
}

View File

@ -0,0 +1,12 @@
import mongoose from "mongoose";
const { Schema } = mongoose;
const beatSaverSchema = new Schema({
_id: String,
totalCreated: Number,
totalUpdated: Number,
totalDeleted: Number,
});
export const BeatSaverSchema =
mongoose.models.BeatSaver || mongoose.model("BeatSaver", beatSaverSchema);

11
src/headsets.ts Normal file
View File

@ -0,0 +1,11 @@
export const Headsets: { [key: number]: string } = {
0: "Unknown",
1: "Rift CV1",
2: "Vive",
4: "Vive Pro",
8: "Windows Mixed Reality",
16: "Rift S",
32: "Oculus Quest",
64: "Valve Index",
128: "Vive Cosmos",
};

View File

@ -22,5 +22,6 @@ export const InfluxWriteAPI = influxClient.getWriteApi(
);
export const InfluxQueryAPI = influxClient.getQueryApi(INFLUXDB_ORG);
require("./services/updateData");
require("./services/api");
require("./services/scoresaber");
require("./services/beatsaver");
require("./api/api");

View File

@ -1,52 +0,0 @@
import express from "express";
import { INFLUXDB_BUCKET, InfluxQueryAPI } from "../index";
import { formatString } from "../utils/stringUtils";
const app = express();
const port = process.env.PORT || 3000;
// Query to get the player count history for tge last 24 hours in 1 hour intervals
const getPlayerHistoryQuery = `from(bucket: "${INFLUXDB_BUCKET}")
|> range(start: {})
|> filter(fn: (r) => r["_measurement"] == "scoresaber")
|> filter(fn: (r) => r["_field"] == "value")
|> filter(fn: (r) => r["type"] == "player_count")
|> aggregateWindow(every: 1h, fn: mean)
|> yield()
`;
app.get("/", (req, res) => {
res.send("Hello!");
});
app.get("/analytics", async (req, res) => {
const before = new Date().getTime();
const timeQuery = req.query.time || "24h";
const timeInMs = parseTimeToMilliseconds(timeQuery.toString());
if (timeInMs > 30 * 24 * 60 * 60 * 1000) {
return res.status(400).json({
error: "Time range too large. Max time range is 30 days.",
});
}
const rows = await InfluxQueryAPI.collectRows(
formatString(getPlayerHistoryQuery, false, timeQuery)
);
let history = rows.map((row: any) => ({
time: row._time,
value: row._value !== null ? row._value.toFixed(0) : null,
}));
history = history.sort(
(a: any, b: any) => new Date(a.time).getTime() - new Date(b.time).getTime()
);
return res.json({
serverTimeTaken: new Date().getTime() - before + "ms",
history: history,
});
});
app.listen(port, () => {
console.log(`API Server is running on http://localhost:${port}`);
});

139
src/services/beatsaver.ts Normal file
View File

@ -0,0 +1,139 @@
import { Point } from "@influxdata/influxdb-client";
import cron from "node-cron";
import { w3cwebsocket as WebsocketClient } from "websocket";
import { InfluxWriteAPI } from "..";
import { connectMongo } from "../db/mongo";
import { BeatSaverSchema } from "../db/schemas/beatsaver";
const WEBSOCKET_URL = "wss://ws.beatsaver.com/maps";
let totalUpdated: number | undefined;
let totalCreated: number | undefined;
let totalDeleted: number | undefined;
// Thee last time a map was heard
let lastMap: number = Date.now();
let socket: WebsocketClient | undefined;
async function update() {
if (totalCreated == undefined) {
throw new Error("Total created is undefined");
}
if (totalUpdated == undefined) {
throw new Error("Total updated is undefined");
}
if (totalDeleted == undefined) {
throw new Error("Total deleted is undefined");
}
const totalCreatedPoint = new Point("beatsaver")
.tag("type", "maps_created")
.intField("value", totalCreated)
.timestamp(new Date());
const totalUpdatedPoint = new Point("beatsaver")
.tag("type", "maps_updated")
.intField("value", totalUpdated)
.timestamp(new Date());
const totalDeletedPoint = new Point("beatsaver")
.tag("type", "maps_deleted")
.intField("value", totalDeleted)
.timestamp(new Date());
InfluxWriteAPI.writePoints([
totalCreatedPoint,
totalUpdatedPoint,
totalDeletedPoint,
]);
}
async function connectWebsocket() {
socket = new WebsocketClient(WEBSOCKET_URL);
await connectMongo();
let beatSaver = await BeatSaverSchema.findOne({ _id: "beatsaver" });
if (!beatSaver) {
beatSaver = await BeatSaverSchema.create({
_id: "beatsaver",
totalUpdated: 0,
totalCreated: 0,
totalDeleted: 0,
});
}
totalCreated = beatSaver.totalCreated || 0;
totalUpdated = beatSaver.totalUpdated || 0;
totalDeleted = beatSaver.totalDeleted || 0;
console.log(totalCreated, totalUpdated, totalDeleted);
socket.onopen = () => {
console.log("Connected to beatsaver websocket");
};
socket.onclose = () => {
console.log("Disconnected from beatsaver websocket");
setTimeout(connectWebsocket, 5000);
};
socket.onerror = (error) => {
console.error("Beatsaver Websocket error:", error);
};
socket.onmessage = async (message) => {
const json = JSON.parse(message.data.toString());
console.log(totalCreated, totalUpdated, totalDeleted);
if (totalCreated == undefined) {
throw new Error("Total created is undefined");
}
if (totalUpdated == undefined) {
throw new Error("Total updated is undefined");
}
if (totalDeleted == undefined) {
throw new Error("Total deleted is undefined");
}
const { type, msg } = json;
const { id, metadata, uploaded, updatedAt } = msg;
if (!metadata) {
console.log(msg);
throw new Error("Metadata is undefined for map " + id);
}
const { bpm, duration } = metadata;
// new map
if (type == "MAP_UPDATE" && uploaded == updatedAt) {
totalCreated++;
InfluxWriteAPI.writePoint(
new Point("beatsaver")
.tag("type", "map_create")
.intField("bpm", bpm)
.intField("duration", duration)
);
} else {
// updated map
totalUpdated++;
}
// deleted map
if (type == "MAP_DELETE") {
totalDeleted++;
}
BeatSaverSchema.updateOne(
{ _id: "beatsaver" },
{
$set: {
totalUpdated: totalUpdated,
totalCreated: totalCreated,
totalDeleted: totalDeleted,
},
}
).exec();
};
}
connectWebsocket();
cron.schedule("*/5 * * * *", update);
cron.schedule("*/1 * * * *", () => {
// 1 minute
if (lastMap && Date.now() - lastMap > 60_000) {
console.log("Beatsaver websocket is dead, reconnecting");
socket?.close();
connectWebsocket();
}
});

167
src/services/scoresaber.ts Normal file
View File

@ -0,0 +1,167 @@
import { Point } from "@influxdata/influxdb-client";
import axios from "axios";
import cron from "node-cron";
import { w3cwebsocket as WebsocketClient } from "websocket";
import { InfluxWriteAPI } from "..";
import { connectMongo } from "../db/mongo";
import { LeaderboardSchema } from "../db/schemas/leaderboard";
import { Headsets } from "../headsets";
import { normalizedRegionName } from "../utils/regionUtils";
let totalScores: number | undefined;
// Thee last time a score was heard
let lastScore: number = Date.now();
let socket: WebsocketClient | undefined;
/**
* Updates the player count and adds data to influx
*/
async function update() {
const response = await axios.get("https://scoresaber.com/api/players/count");
const count = response.data;
const point = new Point("scoresaber")
.tag("type", "player_count")
.intField("value", parseInt(count))
.timestamp(new Date());
InfluxWriteAPI.writePoint(point);
console.log(`Updated player count to ${count}`);
if (totalScores) {
InfluxWriteAPI.writePoint(
new Point("scoresaber")
.tag("type", "score_count")
.intField("value", totalScores)
.timestamp(new Date())
);
console.log(`Updated score count to ${totalScores}`);
}
}
/**
* Connects to the scoresaber websocket and listens for new scores
*/
async function connectWebsocket() {
await connectMongo();
const leaderboard = await LeaderboardSchema.findOne({ _id: "scoresaber" });
if (!leaderboard) {
await LeaderboardSchema.create({ _id: "scoresaber", totalPlays: 0 });
}
// set total scores to the current total plays in the database
totalScores = leaderboard?.totalPlays || 0;
socket = new WebsocketClient("wss://scoresaber.com/ws");
socket.onopen = () => {
console.log("Connected to scoresaber websocket");
};
socket.onclose = () => {
console.log("Disconnected from scoresaber websocket");
setTimeout(connectWebsocket, 5000);
};
socket.onerror = (error) => {
console.error("Scoresaber Websocket error:", error);
};
socket.onmessage = async (message) => {
lastScore = Date.now();
const data = message.data;
let json;
try {
json = JSON.parse(data.toString());
} catch (e) {
return;
}
const commandName = json.commandName;
const commandData = json.commandData;
if (commandName == "score") {
const { score, leaderboard } = commandData;
if (!totalScores) {
throw new Error("totalScores is undefined");
}
totalScores++;
const {
id,
hmd,
baseScore,
missedNotes,
badCuts,
rank,
maxCombo,
leaderboardPlayerInfo: player,
pp,
} = score;
const { maxScore, stars } = leaderboard;
const hmdName = Headsets[hmd] || "Unknown";
const countryId = normalizedRegionName(player.country) || "Unknown";
// Update the leaderboard data in the database
await LeaderboardSchema.updateOne(
{ _id: "scoresaber" },
{
$set: {
totalPlays: totalScores,
},
}
).exec();
const scorePoint = new Point("scoresaber")
.tag("type", "score")
.intField("id", id)
.timestamp(new Date());
if (baseScore && maxScore) {
scorePoint.floatField("acc", ((baseScore / maxScore) * 100).toFixed(2));
}
if (stars) {
scorePoint.floatField("stars", stars);
}
if (pp) {
scorePoint.floatField("pp", pp.toFixed(2));
}
if (missedNotes) {
scorePoint.intField("missed_notes", missedNotes);
}
if (badCuts) {
scorePoint.intField("bad_cuts", badCuts);
}
if (rank) {
scorePoint.intField("rank", rank);
}
// if (leaderboardId) {
// scorePoint.intField("leaderboard_id", leaderboardId);
// }
if (hmdName) {
scorePoint.stringField("hmd", hmdName);
}
if (countryId) {
scorePoint.stringField("country", countryId);
}
if (maxCombo) {
scorePoint.intField("max_combo", maxCombo);
}
scorePoint.intField("player_id", player.id);
// Write the data to influx
InfluxWriteAPI.writePoint(scorePoint);
}
};
}
update();
connectWebsocket();
cron.schedule("*/1 * * * *", update);
cron.schedule("*/1 * * * *", () => {
// 1 minute
if (lastScore && Date.now() - lastScore > 60_000) {
console.log("Scoresaber websocket is dead, reconnecting");
socket?.close();
connectWebsocket();
}
});

View File

@ -1,71 +0,0 @@
import { Point } from "@influxdata/influxdb-client";
import { w3cwebsocket as WebsocketClient } from "websocket";
import { InfluxWriteAPI } from "..";
import { connectMongo } from "../db/mongo";
import { LeaderboardSchema } from "../db/schemas/leaderboard";
const fetch = require("node-fetch");
async function update() {
const response = await fetch("https://scoresaber.com/api/players/count");
const count = await response.text();
const point = new Point("scoresaber")
.tag("type", "player_count")
.intField("value", parseInt(count))
.timestamp(new Date());
InfluxWriteAPI.writePoint(point);
console.log(`Updated player count to ${count}`);
}
async function connectWebsocket() {
await connectMongo();
const leaderboard = await LeaderboardSchema.findOne({ _id: "scoresaber" });
if (!leaderboard) {
await LeaderboardSchema.create({ _id: "scoresaber", totalPlays: 0 });
}
let totalScores = leaderboard?.totalPlays || 0;
const socket = new WebsocketClient("wss://scoresaber.com/ws");
socket.onopen = () => {
console.log("Connected to websocket");
};
socket.onclose = () => {
console.log("Disconnected from websocket");
setTimeout(connectWebsocket, 5000);
};
socket.onerror = (error) => {
console.error("Websocket error:", error);
};
socket.onmessage = (message) => {
const data = message.data;
let json;
try {
json = JSON.parse(data.toString());
} catch (e) {
return;
}
const commandName = json.commandName;
const commandData = json.commandData;
if (commandName == "score") {
totalScores++;
LeaderboardSchema.updateOne(
{ _id: "scoresaber" },
{ totalPlays: totalScores }
).exec();
const point = new Point("scoresaber")
.tag("type", "score_count")
.intField("value", totalScores)
.timestamp(new Date());
InfluxWriteAPI.writePoint(point);
}
};
}
update();
connectWebsocket();
setInterval(update, 60_000); // 1 minute

11
src/utils/regionUtils.ts Normal file
View File

@ -0,0 +1,11 @@
let regionNames = new Intl.DisplayNames(["en"], { type: "region" });
/**
* Returns the normalized region name
*
* @param region the region to normalize
* @returns the normalized region name
*/
export function normalizedRegionName(region: string) {
return regionNames.of(region);
}

View File

@ -4,7 +4,7 @@
* @param time the time to parse
* @returns the time in milliseconds
*/
function parseTimeToMilliseconds(time: string) {
export function parseTimeToMilliseconds(time: string) {
// Regular expression to match the numeric value and unit
const regex = /^(\d+)([smhdwMy])$/;