From e861e397b51fcad6ce459a7074b7a34fabc61734 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Thu, 8 Apr 2021 21:53:32 -0500 Subject: change how stats are sent to allow for extra info --- build/cleaners/skyblock/member.js | 8 ++++---- build/cleaners/skyblock/stats.js | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'build/cleaners') diff --git a/build/cleaners/skyblock/member.js b/build/cleaners/skyblock/member.js index 5c26e40..9869646 100644 --- a/build/cleaners/skyblock/member.js +++ b/build/cleaners/skyblock/member.js @@ -20,16 +20,16 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanSkyBlockProfileMemberResponse = exports.cleanSkyBlockProfileMemberResponseBasic = void 0; -const stats_1 = require("./stats"); +const collections_1 = require("./collections"); const inventory_1 = require("./inventory"); const fairysouls_1 = require("./fairysouls"); const objectives_1 = require("./objectives"); +const stats_1 = require("./stats"); const minions_1 = require("./minions"); +const slayers_1 = require("./slayers"); +const zones_1 = require("./zones"); const skills_1 = require("./skills"); const cached = __importStar(require("../../hypixelCached")); -const zones_1 = require("./zones"); -const collections_1 = require("./collections"); -const slayers_1 = require("./slayers"); async function cleanSkyBlockProfileMemberResponseBasic(member, included = null) { const player = await cached.fetchPlayer(member.uuid); return { diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js index 9c6966f..5673d99 100644 --- a/build/cleaners/skyblock/stats.js +++ b/build/cleaners/skyblock/stats.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.cleanProfileStats = exports.categorizeStat = void 0; +exports.cleanProfileStats = exports.getStatUnit = exports.statUnits = exports.categorizeStat = void 0; const statCategories = { 'deaths': ['deaths_', 'deaths'], 'kills': ['kills_', 'kills'], @@ -56,17 +56,39 @@ function categorizeStat(statNameRaw) { }; } exports.categorizeStat = categorizeStat; +exports.statUnits = { + time: ['_best_time', '_best_time_2'], + date: ['first_join'], + coins: ['purse'] +}; +function getStatUnit(name) { + for (const [unitName, statMatchers] of Object.entries(exports.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; + } + } +} +exports.getStatUnit = getStatUnit; function cleanProfileStats(data) { - var _a; + var _a, _b; // TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there) - const stats = {}; + const stats = []; const rawStats = (_a = data === null || data === void 0 ? void 0 : data.stats) !== null && _a !== void 0 ? _a : {}; 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 !== null && statName !== void 0 ? statName : 'total', + value: statValue, + rawName: statNameRaw, + category: statCategory, + unit: (_b = getStatUnit(statNameRaw)) !== null && _b !== void 0 ? _b : null + }); } return stats; } -- cgit