From 5bf83da726f919d870e3044d40660f0dbc861e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Mon, 20 Nov 2023 13:16:44 -0600 Subject: [PATCH] feat: ratings leaderboard efficiency plot script --- .vscode/settings.json | 1 + package.json | 1 + scripts/buildRatingsPlot.ts | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 scripts/buildRatingsPlot.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 45f0cf251..c157c2994 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,6 +25,7 @@ "playerachievements", "playerinfo", "ratingsleaderboard", + "ratingsplot", "Resvg", "roboto", "searchclans", diff --git a/package.json b/package.json index 072fa109c..d23645902 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "build:docs": "vitepress build docs", "build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard", "build:tankopedia": "vite-node --script scripts/buildTankopedia", + "build:ratingsplot": "vite-node --script scripts/buildRatingsPlot", "dev:bot": "yarn build:bot && yarn start:bot", "dev:docs": "vitepress dev docs", "dev:website": "next dev", diff --git a/scripts/buildRatingsPlot.ts b/scripts/buildRatingsPlot.ts new file mode 100644 index 000000000..a0352a9ab --- /dev/null +++ b/scripts/buildRatingsPlot.ts @@ -0,0 +1,46 @@ +import { writeFile } from 'fs/promises'; +import { Region } from '../src/constants/regions'; +import { getRatingsNeighbors } from '../src/core/blitz/getRatingsNeighbors'; + +const REGION: Region = 'com'; +const PLAYER = 1041988373; +const ITERATIONS = 2 ** 4; +const MAX_NEIGHBORS = 2 ** 7; +const data: [number, number][] = []; +let finished = 0; + +for (let index = 0; index < ITERATIONS; index++) { + const neighbors = Math.round((Math.random() * MAX_NEIGHBORS) / 2) * 2; + const start = Date.now(); + + console.log(`🟡 Iteration ${index} with ${neighbors} neighbors`); + + try { + await getRatingsNeighbors(REGION, PLAYER, neighbors); + + finished++; + console.log( + `🟢 (${Math.round( + 100 * (finished / ITERATIONS), + )}%) Iteration ${index} with ${neighbors} neighbors`, + ); + + const end = Date.now(); + const time = end - start; + + data.push([neighbors, time]); + } catch (error) { + console.log( + `🔴 Iteration ${index} with ${neighbors} neighbors\n\n${error}`, + ); + } +} + +console.log('🟢 Done, sorting'); +data.sort(([neighborsA], [neighborsB]) => neighborsA - neighborsB); + +console.log('🟢 Writing'); +writeFile( + 'dist/ratingsPlot.csv', + data.map(([neighbors, time]) => `${neighbors},${time}`).join('\n'), +);