aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-02-28 16:10:02 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-02-28 16:10:02 -0600
commitdfd4016d4ea907719d0b4edf28e4b9529534870c (patch)
tree4f96fb0e54a6bdea021fd9eb1cbc391d3accdf30
parentb69690f7cf2405bc817082cce45185fb389d0bb9 (diff)
downloadskyblock-api-dfd4016d4ea907719d0b4edf28e4b9529534870c.tar.gz
skyblock-api-dfd4016d4ea907719d0b4edf28e4b9529534870c.tar.bz2
skyblock-api-dfd4016d4ea907719d0b4edf28e4b9529534870c.zip
make /leaderboards include categories
-rw-r--r--build/cleaners/skyblock/stats.js4
-rw-r--r--build/database.js18
-rw-r--r--build/index.js3
-rw-r--r--src/cleaners/skyblock/stats.ts5
-rw-r--r--src/database.ts20
-rw-r--r--src/index.ts4
6 files changed, 48 insertions, 6 deletions
diff --git a/build/cleaners/skyblock/stats.js b/build/cleaners/skyblock/stats.js
index 80686c1..09941a4 100644
--- a/build/cleaners/skyblock/stats.js
+++ b/build/cleaners/skyblock/stats.js
@@ -1,11 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-exports.cleanProfileStats = void 0;
+exports.cleanProfileStats = exports.categorizeStat = void 0;
const statCategories = {
'deaths': ['deaths_', 'deaths'],
'kills': ['kills_', 'kills'],
'fishing': ['items_fished_', 'items_fished'],
'auctions': ['auctions_'],
+ 'collection': ['collection_'],
'races': ['_best_time'],
'misc': null // everything else goes here
};
@@ -52,6 +53,7 @@ function categorizeStat(statNameRaw) {
name: statNameRaw
};
}
+exports.categorizeStat = categorizeStat;
function cleanProfileStats(data) {
var _a;
// TODO: add type for statsRaw (probably in hypixelApi.ts since its coming from there)
diff --git a/build/database.js b/build/database.js
index 1edb990..a813a78 100644
--- a/build/database.js
+++ b/build/database.js
@@ -25,12 +25,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.updateDatabaseMember = exports.fetchMemberLeaderboard = void 0;
+exports.updateDatabaseMember = exports.fetchMemberLeaderboard = exports.fetchAllMemberLeaderboardAttributes = exports.fetchAllLeaderboardsCategoriezed = void 0;
const constants = __importStar(require("./constants"));
const cached = __importStar(require("./hypixelCached"));
const mongodb_1 = require("mongodb");
const node_cache_1 = __importDefault(require("node-cache"));
const util_1 = require("./util");
+const stats_1 = require("./cleaners/skyblock/stats");
// don't update the user for 3 minutes
const recentlyUpdated = new node_cache_1.default({
stdTTL: 60 * 3,
@@ -73,6 +74,20 @@ function getMemberLeaderboardAttributes(member) {
visited_zones: member.visited_zones.length,
};
}
+async function fetchAllLeaderboardsCategoriezed() {
+ const memberLeaderboardAttributes = await fetchAllMemberLeaderboardAttributes();
+ const categorizedLeaderboards = [];
+ for (const leaderboard of memberLeaderboardAttributes) {
+ const { category, name } = stats_1.categorizeStat(leaderboard);
+ categorizedLeaderboards.push({
+ category,
+ name,
+ id: leaderboard
+ });
+ }
+ return categorizedLeaderboards;
+}
+exports.fetchAllLeaderboardsCategoriezed = fetchAllLeaderboardsCategoriezed;
/** Fetch the names of all the leaderboards */
async function fetchAllMemberLeaderboardAttributes() {
return [
@@ -86,6 +101,7 @@ async function fetchAllMemberLeaderboardAttributes() {
'visited_zones',
];
}
+exports.fetchAllMemberLeaderboardAttributes = fetchAllMemberLeaderboardAttributes;
async function fetchMemberLeaderboardRaw(name) {
if (cachedRawLeaderboards.has(name))
return cachedRawLeaderboards.get(name);
diff --git a/build/index.js b/build/index.js
index 52e711c..0d8bd70 100644
--- a/build/index.js
+++ b/build/index.js
@@ -28,4 +28,7 @@ app.get('/player/:user/:profile', async (req, res) => {
app.get('/leaderboard/:name', async (req, res) => {
res.json(await database_1.fetchMemberLeaderboard(req.params.name));
});
+app.get('/leaderboards', async (req, res) => {
+ res.json(await database_1.fetchAllLeaderboardsCategoriezed());
+});
app.listen(8080, () => console.log('App started :)'));
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts
index 99aa1f7..d55fdd4 100644
--- a/src/cleaners/skyblock/stats.ts
+++ b/src/cleaners/skyblock/stats.ts
@@ -3,16 +3,17 @@ const statCategories: { [ key: string ]: string[] | null } = { // sorted in orde
'kills': ['kills_', 'kills'],
'fishing': ['items_fished_', 'items_fished'],
'auctions': ['auctions_'],
+ 'collection': ['collection_'],
'races': ['_best_time'],
'misc': null // everything else goes here
}
-interface statCategory {
+export interface StatCategory {
category: string,
name: string
}
-function categorizeStat(statNameRaw: string): statCategory {
+export function categorizeStat(statNameRaw: string): StatCategory {
// 'deaths_void'
for (const statCategory in statCategories) {
// 'deaths'
diff --git a/src/database.ts b/src/database.ts
index 7cc2f46..b6507cc 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -10,6 +10,7 @@ import { CleanMember } from './cleaners/skyblock/member'
import { CleanPlayer } from './cleaners/player'
import { shuffle } from './util'
import { CleanFullProfile } from './cleaners/skyblock/profile'
+import { categorizeStat, StatCategory } from './cleaners/skyblock/stats'
// don't update the user for 3 minutes
const recentlyUpdated = new NodeCache({
@@ -75,6 +76,25 @@ function getMemberLeaderboardAttributes(member: CleanMember) {
}
}
+interface CategorizedLeaderboard extends StatCategory {
+ id: string
+}
+
+export async function fetchAllLeaderboardsCategoriezed(): Promise<CategorizedLeaderboard[]> {
+ const memberLeaderboardAttributes = await fetchAllMemberLeaderboardAttributes()
+ const categorizedLeaderboards: CategorizedLeaderboard[] = []
+ for (const leaderboard of memberLeaderboardAttributes) {
+ const { category, name } = categorizeStat(leaderboard)
+ categorizedLeaderboards.push({
+ category,
+ name,
+ id: leaderboard
+ })
+ }
+ return categorizedLeaderboards
+}
+
+
/** Fetch the names of all the leaderboards */
export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> {
return [
diff --git a/src/index.ts b/src/index.ts
index a1da3e1..f35363a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,6 @@
import { fetchMemberProfile, fetchUser } from './hypixel'
import express from 'express'
-import { fetchAllMemberLeaderboardAttributes, fetchMemberLeaderboard } from './database'
+import { fetchAllLeaderboardsCategoriezed, fetchMemberLeaderboard } from './database'
const app = express()
@@ -42,7 +42,7 @@ app.get('/leaderboard/:name', async(req, res) => {
app.get('/leaderboards', async(req, res) => {
res.json(
- await fetchAllMemberLeaderboardAttributes()
+ await fetchAllLeaderboardsCategoriezed()
)
})