aboutsummaryrefslogtreecommitdiff
path: root/build/database.js
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-08-01 20:03:57 -0500
committermat <github@matdoes.dev>2021-08-01 20:03:57 -0500
commit3c60dd9cfd386e57e8445166ab41a92b77777f7e (patch)
tree10a2c68c8c5f388c83d1e88fa923d9c9aaf40272 /build/database.js
parentc5f65b73a863f3ee7f7206321484e1268e056b1a (diff)
downloadskyblock-api-3c60dd9cfd386e57e8445166ab41a92b77777f7e.tar.gz
skyblock-api-3c60dd9cfd386e57e8445166ab41a92b77777f7e.tar.bz2
skyblock-api-3c60dd9cfd386e57e8445166ab41a92b77777f7e.zip
add #1 leaderboards count leaderboard
Diffstat (limited to 'build/database.js')
-rw-r--r--build/database.js63
1 files changed, 45 insertions, 18 deletions
diff --git a/build/database.js b/build/database.js
index 6edb29b..be001ff 100644
--- a/build/database.js
+++ b/build/database.js
@@ -63,7 +63,8 @@ let accountsCollection;
const leaderboardInfos = {
highest_crit_damage: 'This leaderboard is capped at the integer limit because Hypixel, look at the <a href="/leaderboard/highest_critical_damage">highest critical damage leaderboard</a> instead.',
highest_critical_damage: 'uhhhhh yeah idk either',
- leaderboards_count: 'This leaderboard counts how many leaderboards people are in the top 100 for.',
+ leaderboards_count: 'This leaderboard counts how many leaderboards players are in the top 100 for.',
+ top_1_leaderboards_count: 'This leaderboard counts how many leaderboards players are #1 for.',
};
async function connect() {
if (!process.env.db_uri)
@@ -183,7 +184,8 @@ async function fetchAllMemberLeaderboardAttributes() {
'first_join',
'purse',
'visited_zones',
- 'leaderboards_count'
+ 'leaderboards_count',
+ 'top_1_leaderboards_count'
];
}
exports.fetchAllMemberLeaderboardAttributes = fetchAllMemberLeaderboardAttributes;
@@ -369,6 +371,7 @@ async function fetchMemberLeaderboardSpots(player, profile) {
}
exports.fetchMemberLeaderboardSpots = fetchMemberLeaderboardSpots;
async function getLeaderboardRequirement(name, leaderboardType) {
+ var _a, _b;
let leaderboard;
if (leaderboardType === 'member')
leaderboard = await fetchMemberLeaderboardRaw(name);
@@ -376,47 +379,71 @@ async function getLeaderboardRequirement(name, leaderboardType) {
leaderboard = await fetchProfileLeaderboardRaw(name);
// if there's more than 100 items, return the 100th. if there's less, return null
if (leaderboard.length >= leaderboardMax)
- return leaderboard[leaderboardMax - 1].value;
+ return {
+ top_100: leaderboard[leaderboardMax - 1].value,
+ top_1: leaderboard[1].value
+ };
+ else if (leaderboard.length >= 1)
+ return {
+ top_100: null,
+ top_1: (_b = (_a = leaderboard[1]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null
+ };
else
- return null;
+ return {
+ top_100: null,
+ top_1: null
+ };
}
/** Get the attributes for the member, but only ones that would put them on the top 100 for leaderboards */
async function getApplicableMemberLeaderboardAttributes(member) {
const leaderboardAttributes = getMemberLeaderboardAttributes(member);
const applicableAttributes = {};
+ const applicableTop1Attributes = {};
for (const [leaderboard, attributeValue] of Object.entries(leaderboardAttributes)) {
const requirement = await getLeaderboardRequirement(leaderboard, 'member');
const leaderboardReversed = isLeaderboardReversed(leaderboard);
- if ((requirement === null)
- || (leaderboardReversed ? attributeValue < requirement : attributeValue > requirement)) {
+ if ((requirement.top_100 === null)
+ || (leaderboardReversed ? attributeValue < requirement.top_100 : attributeValue > requirement.top_100)) {
applicableAttributes[leaderboard] = attributeValue;
}
+ if ((requirement.top_1 === null)
+ || (leaderboardReversed ? attributeValue < requirement.top_1 : attributeValue > requirement.top_1)) {
+ applicableTop1Attributes[leaderboard] = attributeValue;
+ }
}
- let leaderboardsCount = Object.keys(applicableAttributes).length;
+ // add the "leaderboards count" attribute
+ const leaderboardsCount = Object.keys(applicableAttributes).length;
const leaderboardsCountRequirement = await getLeaderboardRequirement('leaderboards_count', 'member');
- if ((leaderboardsCountRequirement === null)
- || (leaderboardsCount > leaderboardsCountRequirement)) {
+ if ((leaderboardsCountRequirement.top_100 === null)
+ || (leaderboardsCount > leaderboardsCountRequirement.top_100))
applicableAttributes['leaderboards_count'] = leaderboardsCount;
- }
+ // add the "first leaderboards count" attribute
+ const top1LeaderboardsCount = Object.keys(applicableTop1Attributes).length;
+ const top1LeaderboardsCountRequirement = await getLeaderboardRequirement('top_1_leaderboards_count', 'member');
+ if ((top1LeaderboardsCountRequirement.top_100 === null)
+ || (top1LeaderboardsCount > top1LeaderboardsCountRequirement.top_100))
+ applicableAttributes['top_1_leaderboards_count'] = top1LeaderboardsCount;
+ console.log('top_1_leaderboards_count', applicableTop1Attributes, top1LeaderboardsCount, 'requirement', top1LeaderboardsCountRequirement);
return applicableAttributes;
}
/** Get the attributes for the profile, but only ones that would put them on the top 100 for leaderboards */
async function getApplicableProfileLeaderboardAttributes(profile) {
const leaderboardAttributes = getProfileLeaderboardAttributes(profile);
const applicableAttributes = {};
+ const applicableTop1Attributes = {};
for (const [leaderboard, attributeValue] of Object.entries(leaderboardAttributes)) {
const requirement = await getLeaderboardRequirement(leaderboard, 'profile');
const leaderboardReversed = isLeaderboardReversed(leaderboard);
- if ((requirement === null)
- || (leaderboardReversed ? attributeValue < requirement : attributeValue > requirement)) {
+ if ((requirement.top_100 === null)
+ || (leaderboardReversed ? attributeValue < requirement.top_100 : attributeValue > requirement.top_100
+ && attributeValue !== 0)) {
applicableAttributes[leaderboard] = attributeValue;
}
- }
- let leaderboardsCount = Object.keys(applicableAttributes).length;
- const leaderboardsCountRequirement = await getLeaderboardRequirement('leaderboards_count', 'member');
- if (leaderboardsCountRequirement === null
- || leaderboardsCount > leaderboardsCountRequirement) {
- applicableAttributes['leaderboards_count'] = leaderboardsCount;
+ if ((requirement.top_1 === null)
+ || (leaderboardReversed ? attributeValue < requirement.top_1 : attributeValue > requirement.top_1
+ && attributeValue !== 0)) {
+ applicableTop1Attributes[leaderboard] = attributeValue;
+ }
}
return applicableAttributes;
}