aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/experimentation.ts
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-05-30 04:42:17 +0000
committerGitHub <noreply@github.com>2022-05-29 23:42:17 -0500
commit5777b24bbf1ccad2b4c897d8c3960b892405b7c0 (patch)
treea7f6e6ff7b0ece158378bc6c9b331fa8109d1d5d /src/cleaners/skyblock/experimentation.ts
parent445d2929970e583cd1b7331d6a86015b0cf25777 (diff)
downloadskyblock-api-5777b24bbf1ccad2b4c897d8c3960b892405b7c0.tar.gz
skyblock-api-5777b24bbf1ccad2b4c897d8c3960b892405b7c0.tar.bz2
skyblock-api-5777b24bbf1ccad2b4c897d8c3960b892405b7c0.zip
Experimentation table (#220)
* Create experimentation.ts * Experimentation implementation * Fix tests
Diffstat (limited to 'src/cleaners/skyblock/experimentation.ts')
-rw-r--r--src/cleaners/skyblock/experimentation.ts70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/experimentation.ts b/src/cleaners/skyblock/experimentation.ts
new file mode 100644
index 0000000..d81fb3d
--- /dev/null
+++ b/src/cleaners/skyblock/experimentation.ts
@@ -0,0 +1,70 @@
+import typedHypixelApi from 'typed-hypixel-api'
+import { ExperimentationGame as ApiExperimentationGame } from 'typed-hypixel-api/build/responses/skyblock/_profile_member'
+import * as constants from '../../constants.js'
+
+export interface ExperimentationGame {
+ /** `superpairs`, `chronomatron` or `ultrasequencer`. */
+ id: string
+ last_attempt: number | undefined
+ last_claimed: number | undefined
+ types: {
+ attempts: number
+ claims: number
+ best_score: number
+ }[]
+}
+
+const EXPERIMENTATION_GAME_IDS = {
+ pairings: 'superpairs',
+ simon: 'chronomatron',
+ numbers: 'ultrasequencer'
+} as const
+
+// this should be in skyblock-constants, but i don't expect hypixel to add new experimentation games
+const EXPERIMENTATION_GAME_TYPES_COUNT: Record<typeof EXPERIMENTATION_GAME_IDS[keyof typeof EXPERIMENTATION_GAME_IDS], number> = {
+ superpairs: 6,
+ chronomatron: 5,
+ ultrasequencer: 3
+}
+
+export interface Experimentation {
+ games: ExperimentationGame[]
+}
+
+function cleanGame(apiId: string, game: ApiExperimentationGame | undefined): ExperimentationGame {
+ const gameId = EXPERIMENTATION_GAME_IDS[apiId]
+
+ if (!game)
+ game = {}
+
+ const types: ExperimentationGame['types'] = []
+
+ for (let i = 0; i < EXPERIMENTATION_GAME_TYPES_COUNT[gameId]; i++) {
+ const type_attempts = game[`attempts_${i}`] ?? 0
+ const type_claims = game[`claims_${i}`] ?? 0
+ const type_best_score = game[`best_score_${i}`] ?? 0
+
+ types.push({
+ attempts: type_attempts,
+ claims: type_claims,
+ best_score: type_best_score
+ })
+ }
+
+ return {
+ id: gameId,
+ last_attempt: game.last_attempt || undefined,
+ last_claimed: game.last_claimed || undefined,
+ types
+ }
+}
+
+export async function cleanExperimentation(data: typedHypixelApi.SkyBlockProfileMember): Promise<Experimentation> {
+ return {
+ games: [
+ cleanGame('pairings', data.experimentation?.pairings),
+ cleanGame('simon', data.experimentation?.simon),
+ cleanGame('numbers', data.experimentation?.numbers)
+ ]
+ }
+}