Skip to content

Commit

Permalink
ranked logging (#6)
Browse files Browse the repository at this point in the history
* ranked logging

* better logging
  • Loading branch information
reteps authored Jun 29, 2024
1 parent 6750dc3 commit 3db0ca9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server/api/challs/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default {
req.log.info({
chall: challengeid,
flag: submittedFlag,
type: challenge.type
type: challenge.type,
challenge: challenge
}, 'flag submission attempt')

if (!challenge) {
Expand Down
1 change: 1 addition & 0 deletions server/cache/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const setLeaderboard = async ({ challengeValues, solveAmount, leaderboard
challengeValues.forEach((value, key) => {
challengeInfo.push(key, `${value},${solveAmount.get(key)}`)
})
console.dir({ challengeValues, solveAmount, leaderboard, leaderboardUpdate }, { depth: null })
await redisEvalsha(
await setLeaderboardScript,
keys.length,
Expand Down
1 change: 1 addition & 0 deletions server/challenges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const cleanChallenge = (chall: Challenge): CleanedChallenge => {
}

const onUpdate = (newChallenges: Challenge[]): void => {
console.dir({ newChallenges }, { depth: null })
challenges = newChallenges
challengesMap = new Map(newChallenges.map(c => [c.id, c]))
cleanedChallenges = challenges.map(cleanChallenge)
Expand Down
19 changes: 18 additions & 1 deletion server/leaderboard/calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
}
} = workerData

console.dir({ allChallenges }, { depth: null })
const solveAmount = new Map()
const challengeTiebreakEligibles = new Map()
for (let i = 0; i < allChallenges.length; i++) {
Expand Down Expand Up @@ -81,6 +82,7 @@ const calculateScores = (sample) => {
))
}

const rankedSolvesForLogging = []
for (let i = 0; i < users.length; i++) {
const user = users[i]
let currScore = 0
Expand All @@ -100,7 +102,17 @@ const calculateScores = (sample) => {
rankedMetadata.minScore,
rankedMetadata.maxScore,
solveScore
)
)
rankedSolvesForLogging.push({
userId: user.id,
challengeId: solvedChallId,
score: solveScore,
value,
min: rankedMetadata.min,
max: rankedMetadata.max,
minScore: rankedMetadata.minScore,
maxScore: rankedMetadata.maxScore
})
} else {
// Add the score for the specific solve loaded from the challengeValues array using ids

Expand All @@ -121,6 +133,9 @@ const calculateScores = (sample) => {
])
}

console.dir({ rankedSolvesForLogging }, { depth: null })
console.dir({ challengeRankedMetadata }, { depth: null })

return {
challengeValues,
userScores
Expand Down Expand Up @@ -159,6 +174,8 @@ samples.forEach((sample) => {
const { userScores, challengeValues } = calculateScores(leaderboardUpdate)
const sortedUsers = userScores.sort(userCompare).map((user) => user.slice(0, 4))

console.log({ sortedUsers })

parentPort.postMessage({
leaderboard: sortedUsers,
graphLeaderboards,
Expand Down
5 changes: 4 additions & 1 deletion server/leaderboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const fetchData = async () => {
database.users.getAllUsers(),
cache.leaderboard.getGraphUpdate()
])
return {
const workerData = {
solves,
users,
graphUpdate,
allChallenges: getAllChallenges()
}
console.dir({ workerData }, { depth: null })
return workerData
}

let updating = false
Expand All @@ -32,6 +34,7 @@ const runUpdate = async () => {
}
})
worker.once('message', async (data) => {
console.dir({ leaderboardData: data }, { depth: null })
await cache.leaderboard.setLeaderboard(data)
await cache.leaderboard.setGraph({ leaderboards: data.graphLeaderboards })
updating = false
Expand Down
2 changes: 2 additions & 0 deletions server/providers/challenges/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class DatabaseProvider extends EventEmitter implements Provider {
}
})

console.dir({ databaseUpdateChallenges: this.challenges }, { depth: null })

this.emit('update', this.challenges)
} catch (e) {
// TODO: wrap error?
Expand Down

0 comments on commit 3db0ca9

Please sign in to comment.