diff options
Diffstat (limited to 'build/cleaners/skyblock/stats.js')
-rw-r--r-- | build/cleaners/skyblock/stats.js | 34 |
1 files changed, 28 insertions, 6 deletions
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; } |