From 5777b24bbf1ccad2b4c897d8c3960b892405b7c0 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Mon, 30 May 2022 04:42:17 +0000 Subject: Experimentation table (#220) * Create experimentation.ts * Experimentation implementation * Fix tests --- src/cleaners/skyblock/experimentation.ts | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/cleaners/skyblock/experimentation.ts (limited to 'src/cleaners/skyblock/experimentation.ts') 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 = { + 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 { + return { + games: [ + cleanGame('pairings', data.experimentation?.pairings), + cleanGame('simon', data.experimentation?.simon), + cleanGame('numbers', data.experimentation?.numbers) + ] + } +} -- cgit