Skip to content

Commit

Permalink
Cyberleague: [premieroctet#122] create function to compute field is_l…
Browse files Browse the repository at this point in the history
…evel to check according to score level
  • Loading branch information
Bastien-Wappizy committed Sep 9, 2024
1 parent dfe350e commit 2570da2
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions backend/web/server/plugins/cyberleague/score.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { loadFromDb } = require("../../utils/database")
const lodash = require('lodash')
const { ANSWER_NOT_APPLICABLE, ANSWER_YES } = require("./consts")
const { ANSWER_NOT_APPLICABLE, ANSWER_YES, SCORE_LEVEL_1, SCORE_LEVEL_3, SCORE_LEVEL_2 } = require("./consts")

// questionArray: [{question, answer}]
const computeScores = async (answerArray) => {
Expand Down Expand Up @@ -77,7 +77,23 @@ const computeScores = async (answerArray) => {
return {global_rate, category_rates, bellwether_rates}
}

const booleanLevelFieldName = (scoreLevel) => {
switch (scoreLevel) {
case SCORE_LEVEL_1:
return `is_level_1`

case SCORE_LEVEL_2:
return `is_level_2`

case SCORE_LEVEL_3:
return `is_level_3`

default:
throw new Error(`Unknown score level`);
}
}

module.exports = {
computeScores
computeScores,
booleanLevelFieldName
}

0 comments on commit 2570da2

Please sign in to comment.