Skip to content

Commit

Permalink
Cyberleague: [premieroctet#159] Remove bellwether_rates from score sc…
Browse files Browse the repository at this point in the history
…hema
  • Loading branch information
Bastien-Wappizy committed Sep 27, 2024
1 parent b229ca9 commit 9943ef9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
14 changes: 0 additions & 14 deletions backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ const ScoreSchema = new Schema({
}],
default: []
},
bellwether_rates: {
type: [{
category: {
type: Schema.Types.ObjectId,
ref: 'questionCategory',
required: true
},
rate: {
type: Number,
required: true
}
}],
default: []
},
level: {
type: String,
enum: Object.keys(SCORE_LEVELS),
Expand Down
13 changes: 3 additions & 10 deletions backend/web/server/plugins/cyberleague/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ const computeScores = async (answers) => {
category_weightsAndRates: {category: {weight, rate}}
where weight is the sum of the weights of already cosnidered questions of that category
and rate is wieghts of those questions which answer is YES
Same for bellwether_weightsAndRates but only for bellwether questions
*/

//weightsAndRates is like category_weights or bellwether_weights
//weightsAndRates is like category_weights
const updateWeightsAndRates = (weightsAndRates, question,answer) => {
const category = question.question_category._id.toString()
const weight = question.weight
Expand All @@ -42,7 +41,6 @@ const computeScores = async (answers) => {
}

let category_weightsAndRates={}
let bellwether_weightsAndRates = {}

lodash.forEach(answers, ({question, answer}) => {

Expand All @@ -53,10 +51,6 @@ const computeScores = async (answers) => {

total_weight += question.weight
total_rate += answer == ANSWER_YES ? question.weight : 0

if (question.is_bellwether) {
updateWeightsAndRates(bellwether_weightsAndRates,question,answer)
}
}
})

Expand All @@ -70,15 +64,14 @@ const computeScores = async (answers) => {
}

const _category_rates = await computeRates(category_weightsAndRates)
const bellwether_rates = []//computeRates(bellwether_weightsAndRates)

return {global_rate, _category_rates, bellwether_rates}
return {global_rate, _category_rates}
}

const computeScoresIfRequired = async (scoreId) => {
const score = await loadFromDb({
model: 'score',
fields: [`answers.answer`, `answers.question.weight`, `answers.question.question_category`, `answers.question.is_bellwether`],
fields: [`answers.answer`, `answers.question.weight`, `answers.question.question_category`],
id: scoreId
})
const completed = score[0].answers?.filter(a => !a.answer).length == 0
Expand Down
8 changes: 1 addition & 7 deletions backend/web/tests/cyberleague/score.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,17 @@ describe(`score tests`, () => {
const requestedScore = await Score.findOne({answers: score.answers[0]._id})
await computeScoresIfRequired(requestedScore._id)

const loadedSAnswered = await loadFromDb({model: 'score', fields: ['category_rates','bellwether_rates','global_rate']})
const loadedSAnswered = await loadFromDb({model: 'score', fields: ['category_rates','global_rate']})
const scoreAnswered = loadedSAnswered[0]

expect(scoreAnswered.category_rates.length).toEqual(2)
expect(scoreAnswered.bellwether_rates.length).toEqual(1)

expect(scoreAnswered.global_rate).toEqual(0.60)

console.log(scoreAnswered.category_rates);

expect(scoreAnswered.category_rates[1].name).toEqual(categories[2].name)

expect(scoreAnswered.category_rates[0].value).toEqual(0)
expect(scoreAnswered.category_rates[1].value).toEqual(1)

expect(scoreAnswered.bellwether_rates[0].category.toString()).toEqual(categories[1]._id.toString())
expect(scoreAnswered.bellwether_rates[0].rate).toEqual(0)
})

it(`must have correct questions_by_category`, async () => {
Expand Down

0 comments on commit 9943ef9

Please sign in to comment.