aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-04-14 21:24:11 -0500
committerGitHub <noreply@github.com>2021-04-14 21:24:11 -0500
commitc31e4fe77467486dc03226ebdad4c0bc67e1d715 (patch)
tree03cc94dd7155eeb6a522ebd7e7f65eff86ef6e09 /src/cleaners
parent52907cf2056cd434dad7270475fc9e4a532c04fa (diff)
downloadskyblock-api-c31e4fe77467486dc03226ebdad4c0bc67e1d715.tar.gz
skyblock-api-c31e4fe77467486dc03226ebdad4c0bc67e1d715.tar.bz2
skyblock-api-c31e4fe77467486dc03226ebdad4c0bc67e1d715.zip
Total leaderboards leaderboard working (#6)
* add leaderboards leaderboard * slightly optimize fetchPlayer to not unnecessarily fetch the same player twice * Compiled TS into JS * fix errors with fetch * fix random bugs that made people disappear from leaderboards
Diffstat (limited to 'src/cleaners')
-rw-r--r--src/cleaners/skyblock/stats.ts141
1 files changed, 71 insertions, 70 deletions
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts
index 218e034..31a894c 100644
--- a/src/cleaners/skyblock/stats.ts
+++ b/src/cleaners/skyblock/stats.ts
@@ -1,16 +1,16 @@
const statCategories: { [ key: string ]: string[] | null } = { // sorted in order of importance
- 'deaths': ['deaths_', 'deaths'],
- 'kills': ['kills_', 'kills'],
- 'fishing': ['items_fished_', 'items_fished', 'shredder_'],
- 'auctions': ['auctions_'],
- 'races': ['_best_time', '_best_time_2'],
- 'mythos': ['mythos_burrows_', 'mythos_kills'],
+ 'deaths': ['deaths_', 'deaths'],
+ 'kills': ['kills_', 'kills'],
+ 'fishing': ['items_fished_', 'items_fished', 'shredder_'],
+ 'auctions': ['auctions_'],
+ 'races': ['_best_time', '_best_time_2'],
+ 'mythos': ['mythos_burrows_', 'mythos_kills'],
- 'collection': ['collection_'],
- 'skills': ['skill_'],
- 'slayer': ['slayer_'],
+ 'collection': ['collection_'],
+ 'skills': ['skill_'],
+ 'slayer': ['slayer_'],
- 'misc': null // everything else goes here
+ 'misc': null // everything else goes here
}
export interface StatCategory {
@@ -19,59 +19,60 @@ export interface StatCategory {
}
export function categorizeStat(statNameRaw: string): StatCategory {
- // 'deaths_void'
- for (const statCategory in statCategories) {
- // 'deaths'
- const statCategoryMatchers = statCategories[statCategory]
- if (statCategoryMatchers == null) {
- // If it's null, just go with this. Can only ever be 'misc'
- return {
- category: statCategory,
- name: statNameRaw
- }
- }
- for (const categoryMatch of statCategoryMatchers) {
- // ['deaths_']
- let trailingEnd = categoryMatch[0] === '_'
- let trailingStart = categoryMatch.substr(-1) === '_'
- if (trailingStart && statNameRaw.startsWith(categoryMatch)) {
- return {
- category: statCategory,
- name: statNameRaw.substr(categoryMatch.length)
- }
- } else if (trailingEnd && statNameRaw.endsWith(categoryMatch)) {
- return {
- category: statCategory,
- name: statNameRaw.substr(0, statNameRaw.length - categoryMatch.length)
- }
- } else if (statNameRaw == categoryMatch) {
- // if it matches exactly, we don't know the name. will be defaulted to category later on
- return {
- category: statCategory,
- name: null
- }
- }
- }
- }
- // this should never happen, as it'll default to misc and return if nothing is found
- return {
- category: null,
- name: statNameRaw
- }
+ // 'deaths_void'
+ for (const statCategory in statCategories) {
+ // 'deaths'
+ const statCategoryMatchers = statCategories[statCategory]
+ if (statCategoryMatchers == null) {
+ // If it's null, just go with this. Can only ever be 'misc'
+ return {
+ category: statCategory,
+ name: statNameRaw
+ }
+ }
+ for (const categoryMatch of statCategoryMatchers) {
+ // ['deaths_']
+ let trailingEnd = categoryMatch[0] === '_'
+ let trailingStart = categoryMatch.substr(-1) === '_'
+ if (trailingStart && statNameRaw.startsWith(categoryMatch)) {
+ return {
+ category: statCategory,
+ name: statNameRaw.substr(categoryMatch.length)
+ }
+ } else if (trailingEnd && statNameRaw.endsWith(categoryMatch)) {
+ return {
+ category: statCategory,
+ name: statNameRaw.substr(0, statNameRaw.length - categoryMatch.length)
+ }
+ } else if (statNameRaw == categoryMatch) {
+ // if it matches exactly, we don't know the name. will be defaulted to category later on
+ return {
+ category: statCategory,
+ name: null
+ }
+ }
+ }
+ }
+ // this should never happen, as it'll default to misc and return if nothing is found
+ return {
+ category: null,
+ name: statNameRaw
+ }
}
export const statUnits = {
time: ['_best_time', '_best_time_2'],
date: ['first_join'],
- coins: ['purse']
+ coins: ['purse'],
+ leaderboards: ['leaderboards_count']
}
export interface StatItem {
- rawName: string
- value: number
- categorizedName: string
- category: string
- unit: string
+ rawName: string
+ value: number
+ categorizedName: string
+ category: string
+ unit: string
}
export function getStatUnit(name: string): string {
@@ -91,22 +92,22 @@ export function getStatUnit(name: string): string {
export function cleanProfileStats(data: any): StatItem[] {
- // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there)
- const stats: StatItem[] = []
+ // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there)
+ const stats: StatItem[] = []
- const rawStats = data?.stats ?? {}
+ const rawStats = data?.stats ?? {}
- for (const statNameRaw in rawStats) {
- const statValue = rawStats[statNameRaw]
- let { category: statCategory, name: statName } = categorizeStat(statNameRaw)
- stats.push({
- categorizedName: statName ?? 'total',
- value: statValue,
- rawName: statNameRaw,
- category: statCategory,
- unit: getStatUnit(statNameRaw) ?? null
- })
- }
+ for (const statNameRaw in rawStats) {
+ const statValue = rawStats[statNameRaw]
+ let { category: statCategory, name: statName } = categorizeStat(statNameRaw)
+ stats.push({
+ categorizedName: statName ?? 'total',
+ value: statValue,
+ rawName: statNameRaw,
+ category: statCategory,
+ unit: getStatUnit(statNameRaw) ?? null
+ })
+ }
- return stats
+ return stats
}