diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 2 | ||||
-rw-r--r-- | src/database.ts | 86 | ||||
-rw-r--r-- | src/hypixelCached.ts | 2 |
3 files changed, 61 insertions, 29 deletions
diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index a91ca74..cce1561 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -64,7 +64,7 @@ export const statUnits = { time: ['_best_time', '_best_time_2'], date: ['first_join'], coins: ['purse'], - leaderboards: ['leaderboards_count'] + leaderboards: ['leaderboards_count', 'top_1_leaderboards_count'] } export interface StatItem { diff --git a/src/database.ts b/src/database.ts index 5ab24cd..ac5a8a5 100644 --- a/src/database.ts +++ b/src/database.ts @@ -111,7 +111,8 @@ let accountsCollection: Collection<AccountSchema> const leaderboardInfos: { [ leaderboardName: string ]: string } = { 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.', } @@ -259,7 +260,8 @@ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> { 'first_join', 'purse', 'visited_zones', - 'leaderboards_count' + 'leaderboards_count', + 'top_1_leaderboards_count' ] } @@ -487,7 +489,7 @@ export async function fetchMemberLeaderboardSpots(player: string, profile: strin return memberLeaderboardSpots } -async function getLeaderboardRequirement(name: string, leaderboardType: 'member' | 'profile'): Promise<number | null> { +async function getLeaderboardRequirement(name: string, leaderboardType: 'member' | 'profile'): Promise<{ top_100: number | null, top_1: number | null }> { let leaderboard: memberRawLeaderboardItem[] | profileRawLeaderboardItem[] if (leaderboardType === 'member') leaderboard = await fetchMemberLeaderboardRaw(name) @@ -496,38 +498,66 @@ async function getLeaderboardRequirement(name: string, leaderboardType: 'member' // 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: leaderboard![1]?.value ?? 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: CleanMember): Promise<StringNumber> { 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) + (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: number = Object.keys(applicableAttributes).length - const leaderboardsCountRequirement: number | null = await getLeaderboardRequirement('leaderboards_count', 'member') + // add the "leaderboards count" attribute + const leaderboardsCount: number = Object.keys(applicableAttributes).length + const leaderboardsCountRequirement = await getLeaderboardRequirement('leaderboards_count', 'member') if ( - (leaderboardsCountRequirement === null) - || (leaderboardsCount > leaderboardsCountRequirement) - ) { + (leaderboardsCountRequirement.top_100 === null) + || (leaderboardsCount > leaderboardsCountRequirement.top_100) + ) applicableAttributes['leaderboards_count'] = leaderboardsCount - } + + // add the "first leaderboards count" attribute + const top1LeaderboardsCount: number = 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 } @@ -535,27 +565,29 @@ async function getApplicableMemberLeaderboardAttributes(member: CleanMember): Pr async function getApplicableProfileLeaderboardAttributes(profile: CleanFullProfile): Promise<StringNumber> { 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) + (requirement.top_100 === null) + || ( + leaderboardReversed ? attributeValue < requirement.top_100 : attributeValue > requirement.top_100 + && attributeValue !== 0 + ) ) { applicableAttributes[leaderboard] = attributeValue } - } - - - let leaderboardsCount: number = Object.keys(applicableAttributes).length - const leaderboardsCountRequirement: number | null = 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 diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts index b0fc1db..51dca5f 100644 --- a/src/hypixelCached.ts +++ b/src/hypixelCached.ts @@ -201,7 +201,7 @@ export async function fetchBasicPlayer(user: string): Promise<CleanPlayer | null const player = await fetchPlayer(playerUuid) if (!player) { - console.debug('no player? this should never happen', user, playerUuid) + console.debug('no player? this should never happen, perhaps the uuid is invalid or the player hasn\'t played hypixel', playerUuid) return null } |