forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accuracy rating for both phases of coding challenges
(currently only logged to server console)
- Loading branch information
1 parent
a5a302f
commit 7a8c880
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2014-2021 Bjoern Kimminich. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
const logger = require("./logger"); | ||
const colors = require("colors/safe"); | ||
const solves = {} | ||
|
||
exports.storeFindItVerdict = (challengeKey, verdict: boolean) => { | ||
storeVerdict(challengeKey, 'find it', verdict) | ||
} | ||
|
||
exports.storeFixItVerdict = (challengeKey, verdict: boolean) => { | ||
storeVerdict(challengeKey, 'fix it', verdict) | ||
} | ||
|
||
exports.calculateFindItAccuracy = (challengeKey) => { | ||
return calculateAccuracy(challengeKey, 'find it') | ||
} | ||
|
||
exports.calculateFixItAccuracy = (challengeKey) => { | ||
return calculateAccuracy(challengeKey, 'fix it') | ||
} | ||
|
||
function calculateAccuracy (challengeKey, phase: string) { | ||
let accuracy = 0 | ||
if (solves[challengeKey][phase]) { | ||
accuracy = 1 / solves[challengeKey].attempts[phase] | ||
} | ||
logger.info(`Accuracy for '${phase === 'fix it' ? 'Fix It' : 'Find It'}' phase of coding challenge ${colors.cyan(challengeKey)}: ${accuracy > 0.5 ? colors.green(accuracy) : (accuracy > 0.25 ? colors.yellow(accuracy) : colors.red(accuracy))}`) | ||
return accuracy | ||
} | ||
|
||
function storeVerdict (challengeKey, phase: string, verdict: boolean) { | ||
if (!solves[challengeKey]) { | ||
solves[challengeKey] = { 'find it': false, 'fix it': false, attempts: { 'find it': 0, 'fix it': 0 } } | ||
} | ||
if (!solves[challengeKey][phase]) { | ||
solves[challengeKey][phase] = verdict | ||
solves[challengeKey].attempts[phase]++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters