[M] Move scoring to separate file

pull/14/head
Azalea 2024-02-26 20:16:49 -05:00
parent d93c2ee267
commit 902cc9009e
3 changed files with 58 additions and 47 deletions

View File

@ -3,27 +3,8 @@ import type { TrendEntry } from './generalTypes'
import type { MaimaiUserSummaryEntry } from './maimaiTypes'
const multTable = [
[ 100.5, 22.4, 'SSSp' ],
[ 100, 21.6, 'SSS' ],
[ 99.5, 21.1, 'SSp' ],
[ 99, 20.8, 'SS' ],
[ 98, 20.3, 'Sp' ],
[ 97, 20, 'S' ],
[ 94, 16.8, 'AAA' ],
[ 90, 15.2, 'AA' ],
[ 80, 13.6, 'A' ]
]
export function getMult(achievement: number) {
achievement /= 10000
for (let i = 0; i < multTable.length; i++) {
if (achievement >= (multTable[i][0] as number)) return multTable[i]
}
return [ 0, 0, 0 ]
}
export async function getMaimai(endpoint: string, params: any) {
return await fetch(`${AQUA_HOST}/Maimai2Servlet/${endpoint}`, {
@ -35,17 +16,3 @@ export async function getMaimai(endpoint: string, params: any) {
export async function getMaimaiAllMusic(): Promise<{ [key: string]: any }> {
return fetch(`${DATA_HOST}/maimai/meta/00/all-music.json`).then(it => it.json())
}
export async function getMaimaiApi(endpoint: string, params: any) {
const url = new URL(`${AQUA_HOST}/api/game/maimai2new/${endpoint}`)
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
return await fetch(url).then(res => res.json())
}
export async function getMaimaiTrend(userId: number): Promise<TrendEntry[]> {
return await getMaimaiApi('trend', { userId })
}
export async function getMaimaiUser(userId: number): Promise<MaimaiUserSummaryEntry> {
return await getMaimaiApi('user-summary', { userId })
}

View File

@ -1,3 +1,5 @@
import type { MusicMeta } from "./generalTypes";
export interface Rating {
musicId: number
level: number
@ -5,24 +7,11 @@ export interface Rating {
}
export interface ParsedRating extends Rating {
music: MaimaiMusic,
music: MusicMeta,
calc: number,
rank: string
}
export interface MaimaiMusic {
name: string,
composer: string,
bpm: number,
ver: number,
note: {
lv: number
designer: string
lv_id: number
notes: number
}
}
export interface MaimaiUserSummaryEntry {
name: string
iconId: number

View File

@ -0,0 +1,55 @@
export type GameName = 'mai2' | 'chu3' | 'ongeki'
const multTable = {
'mai2': [
[ 100.5, 22.4, 'SSSp' ],
[ 100.0, 21.6, 'SSS' ],
[ 99.5, 21.1, 'SSp' ],
[ 99, 20.8, 'SS' ],
[ 98, 20.3, 'Sp' ],
[ 97, 20, 'S' ],
[ 94, 16.8, 'AAA' ],
[ 90, 15.2, 'AA' ],
[ 80, 13.6, 'A' ]
],
// TODO: Fill in multipliers for Chunithm and Ongeki
'chu3': [
[ 100.75, 0, 'SSS' ],
[ 100.0, 0, 'SS' ],
[ 97.5, 0, 'S' ],
[ 95.0, 0, 'AAA' ],
[ 92.5, 0, 'AA' ],
[ 90.0, 0, 'A' ],
[ 80.0, 0, 'BBB' ],
[ 70.0, 0, 'BB' ],
[ 60.0, 0, 'B' ],
[ 50.0, 0, 'C' ],
[ 0.0, 0, 'D' ]
],
'ongeki': [
[ 100.75, 0, 'SSS+' ],
[ 100.0, 0, 'SSS' ],
[ 99.0, 0, 'SS' ],
[ 97.0, 0, 'S' ],
[ 94.0, 0, 'AAA' ],
[ 90.0, 0, 'AA' ],
[ 85.0, 0, 'A' ],
[ 80.0, 0, 'BBB' ],
[ 75.0, 0, 'BB' ],
[ 70.0, 0, 'B' ],
[ 50.0, 0, 'C' ],
[ 0.0, 0, 'D' ]
]
}
export function getMult(achievement: number, game: GameName) {
achievement /= 10000
const mt = multTable[game]
for (let i = 0; i < mt.length; i++) {
if (achievement >= (mt[i][0] as number)) return mt[i]
}
return [ 0, 0, 0 ]
}