aboutsummaryrefslogtreecommitdiff
path: root/src/database.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.ts')
-rw-r--r--src/database.ts20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/database.ts b/src/database.ts
index 08a8114..27bc7ec 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -3,7 +3,7 @@
*/
import { categorizeStat, getStatUnit } from './cleaners/skyblock/stats'
-import { CleanFullProfile } from './cleaners/skyblock/profile'
+import { CleanFullProfile, CleanProfile } from './cleaners/skyblock/profile'
import { CleanMember } from './cleaners/skyblock/member'
import { Collection, Db, MongoClient } from 'mongodb'
import { CleanPlayer } from './cleaners/player'
@@ -175,6 +175,7 @@ export async function fetchAllMemberLeaderboardAttributes(): Promise<string[]> {
'first_join',
'purse',
'visited_zones',
+ 'leaderboards_count'
]
}
@@ -247,7 +248,7 @@ export async function fetchMemberLeaderboardSpots(player: string, profile: strin
// update the leaderboard positions for the member
await updateDatabaseMember(fullMember, fullProfile)
- const applicableAttributes = await getApplicableAttributes(fullMember)
+ const applicableAttributes = await getApplicableAttributes(fullMember, fullProfile)
const memberLeaderboardSpots = []
@@ -276,7 +277,7 @@ async function getMemberLeaderboardRequirement(name: string): Promise<number> {
}
/** Get the attributes for the member, but only ones that would put them on the top 100 for leaderboards */
-async function getApplicableAttributes(member: CleanMember): Promise<StringNumber> {
+async function getApplicableAttributes(member: CleanMember, profile: CleanProfile): Promise<StringNumber> {
const leaderboardAttributes = getMemberLeaderboardAttributes(member)
const applicableAttributes = {}
for (const [ leaderboard, attributeValue ] of Object.entries(leaderboardAttributes)) {
@@ -289,6 +290,17 @@ async function getApplicableAttributes(member: CleanMember): Promise<StringNumbe
applicableAttributes[leaderboard] = attributeValue
}
}
+
+ let leaderboardsCount: number = Object.keys(applicableAttributes).length
+ const leaderboardsCountRequirement: number = await getMemberLeaderboardRequirement('leaderboards_count')
+ if (
+ (leaderboardsCountRequirement === null)
+ || (leaderboardsCount > leaderboardsCountRequirement)
+ ) {
+ // add 1 extra because this attribute also counts :)
+ applicableAttributes['leaderboards_count'] = leaderboardsCount + 1
+ }
+
return applicableAttributes
}
@@ -312,7 +324,7 @@ export async function updateDatabaseMember(member: CleanMember, profile: CleanFu
if (debug) console.log('done constants..')
- const leaderboardAttributes = await getApplicableAttributes(member)
+ const leaderboardAttributes = await getApplicableAttributes(member, profile)
if (debug) console.log('done getApplicableAttributes..', leaderboardAttributes)