diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-08 21:53:32 -0500 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-08 21:53:32 -0500 |
commit | e861e397b51fcad6ce459a7074b7a34fabc61734 (patch) | |
tree | 5cfcb4ab9096c6c5e11b5cac03cfe87df649bcc5 /src/cleaners | |
parent | 93860fc217937431fd31a68daf69f3376b960161 (diff) | |
download | skyblock-api-e861e397b51fcad6ce459a7074b7a34fabc61734.tar.gz skyblock-api-e861e397b51fcad6ce459a7074b7a34fabc61734.tar.bz2 skyblock-api-e861e397b51fcad6ce459a7074b7a34fabc61734.zip |
change how stats are sent to allow for extra info
Diffstat (limited to 'src/cleaners')
-rw-r--r-- | src/cleaners/skyblock/member.ts | 14 | ||||
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 49 |
2 files changed, 47 insertions, 16 deletions
diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 424bb9b..fe86e2e 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -1,18 +1,18 @@ -import { CleanProfileStats, cleanProfileStats } from './stats' +import { cleanCollections, Collection } from './collections' import { cleanInventories, Inventories } from './inventory' import { cleanFairySouls, FairySouls } from './fairysouls' import { cleanObjectives, Objective } from './objectives' +import { CleanFullProfileBasicMembers } from './profile' +import { cleanProfileStats, StatItem } from './stats' import { CleanMinion, cleanMinions } from './minions' +import { cleanSlayers, SlayerData } from './slayers' +import { cleanVisitedZones, Zone } from './zones' import { cleanSkills, Skill } from './skills' import * as cached from '../../hypixelCached' -import { CleanFullProfile, CleanFullProfileBasicMembers } from './profile' import { Included } from '../../hypixel' import { CleanPlayer } from '../player' +import { CleanRank } from '../rank' import { Bank } from './bank' -import { cleanVisitedZones, Zone } from './zones' -import { cleanCollections, Collection } from './collections' -import { cleanSlayers, SlayerData } from './slayers' -import { cleanRank, CleanRank } from '../rank' export interface CleanBasicMember { uuid: string @@ -24,7 +24,7 @@ export interface CleanBasicMember { export interface CleanMember extends CleanBasicMember { purse: number - stats: CleanProfileStats + stats: StatItem[] rawHypixelStats?: { [ key: string ]: number } minions: CleanMinion[] fairy_souls: FairySouls diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index 7d8da57..efb79bd 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -59,22 +59,53 @@ export function categorizeStat(statNameRaw: string): StatCategory { } } -export interface CleanProfileStats { - [ category: string ]: { - [ stat: string ]: any - total?: any - } +export const statUnits = { + time: ['_best_time', '_best_time_2'], + date: ['first_join'], + coins: ['purse'] +} + +export interface StatItem { + rawName: string + value: number + categorizedName: string + category: string + unit: string +} + +export function getStatUnit(name: string): string { + for (const [ unitName, statMatchers ] of Object.entries(statUnits)) { + for (const statMatch of statMatchers) { + let trailingEnd = statMatch[0] === '_' + let trailingStart = statMatch.substr(-1) === '_' + if ( + (trailingStart && name.startsWith(statMatch)) + || (trailingEnd && name.endsWith(statMatch)) + || (name == statMatch) + ) + return unitName + } + } } -export function cleanProfileStats(data: any): CleanProfileStats { + +export function cleanProfileStats(data: any): StatItem[] { // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) - const stats: CleanProfileStats = {} + const stats: StatItem[] = [] + const rawStats = data?.stats ?? {} + for (const statNameRaw in rawStats) { const statValue = rawStats[statNameRaw] let { category: statCategory, name: statName } = categorizeStat(statNameRaw) - if (!stats[statCategory]) stats[statCategory] = {} - stats[statCategory][statName || 'total'] = statValue + stats.push({ + categorizedName: statName ?? 'total', + value: statValue, + rawName: statNameRaw, + category: statCategory, + unit: getStatUnit(statNameRaw) ?? null + }) } + return stats } |