Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Sync master with develop #35

Merged
merged 9 commits into from
Oct 23, 2020
Next Next commit
updates for storing final score along with the provisional
  • Loading branch information
Dushyant Bhalgami committed Nov 13, 2019
commit a351157f201e446fece9dd12b04013be3dbfe385
3 changes: 2 additions & 1 deletion src/models/Leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const LeaderboardSchema = new Schema({
scoreResetTime: { type: Number },
totalTestCases: { type: Number },
groupIds: { type: [String] },
status: { type: String }
status: { type: String },
finalDetails: { type: Object }
})

module.exports = LeaderboardSchema
68 changes: 39 additions & 29 deletions src/services/LeaderboardService.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,37 +203,47 @@ async function updateLeaderboard (challengeId, memberId, review) {

let scoreLevelChanged = false

if (review.status !== 'queued') {
if (existRecords[0].aggregateScore > review.score) {
scoreLevel = 'down'
scoreLevelChanged = true
} else if (existRecords[0].aggregateScore < review.score) {
scoreLevel = 'up'
scoreLevelChanged = true
}

if (scoreLevelChanged) {
const timerKey = `${challengeId}:${memberId}`
// if we got a new review for the same challengeId:memberId, reset the timer
clearTimeout(timers[timerKey])
// resets the score after an amount of time
timers[timerKey] = setTimeout(resetScoreLevelWithMemberInfo, config.SCORE_RESET_TIME, challengeId, memberId)
scoreResetTime = Date.now() + config.SCORE_RESET_TIME
}
if (review.resource === 'reviewSummation') {
_.assignIn(existRecords[0], {
finalDetails: {
aggregateScore: review.aggregateScore,
testsPassed,
totalTestCases,
}
})
} else {
scoreLevel = 'queued'
if (review.status !== 'queued') {
if (existRecords[0].aggregateScore > review.score) {
scoreLevel = 'down'
scoreLevelChanged = true
} else if (existRecords[0].aggregateScore < review.score) {
scoreLevel = 'up'
scoreLevelChanged = true
}

if (scoreLevelChanged) {
const timerKey = `${challengeId}:${memberId}`
// if we got a new review for the same challengeId:memberId, reset the timer
clearTimeout(timers[timerKey])
// resets the score after an amount of time
timers[timerKey] = setTimeout(resetScoreLevelWithMemberInfo, config.SCORE_RESET_TIME, challengeId, memberId)
scoreResetTime = Date.now() + config.SCORE_RESET_TIME
}
} else {
scoreLevel = 'queued'
}

_.assignIn(existRecords[0], {
aggregateScore: review.score,
reviewId: review.id,
testsPassed,
totalTestCases,
scoreLevel,
scoreResetTime,
status: review.status
})
}

_.assignIn(existRecords[0], {
aggregateScore: review.score,
reviewId: review.id,
testsPassed,
totalTestCases,
scoreLevel,
scoreResetTime,
status: review.status
})


return existRecords[0].save()
}

Expand Down