aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/stats.ts
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-04-08 21:53:32 -0500
committermat <27899617+mat-1@users.noreply.github.com>2021-04-08 21:53:32 -0500
commite861e397b51fcad6ce459a7074b7a34fabc61734 (patch)
tree5cfcb4ab9096c6c5e11b5cac03cfe87df649bcc5 /src/cleaners/skyblock/stats.ts
parent93860fc217937431fd31a68daf69f3376b960161 (diff)
downloadskyblock-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/skyblock/stats.ts')
-rw-r--r--src/cleaners/skyblock/stats.ts49
1 files changed, 40 insertions, 9 deletions
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
}