Don't validate answer without valid correction template
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-11-16 09:37:15 +01:00
parent 8fd9908d59
commit 140935e15d

View File

@ -38,17 +38,25 @@
export async function applyCorrections() { export async function applyCorrections() {
for (const r of filteredResponses) { for (const r of filteredResponses) {
const my_correction = { }; const my_correction = { };
let has_no_lost_answer = false;
let completed_correction = false;
for (const tpl of templates) { for (const tpl of templates) {
if (tpl.score >= 0) has_no_lost_answer = true;
if (!tpl.regexp && tpl.label) continue; if (!tpl.regexp && tpl.label) continue;
if (tpl.regexp && (tpl.regexp[0] == '!' && !r.value.match(tpl.regexp.substring(1))) || r.value.match(tpl.regexp)) { if (tpl.regexp && (tpl.regexp[0] == '!' && !r.value.match(tpl.regexp.substring(1))) || r.value.match(tpl.regexp)) {
my_correction[tpl.id] = true; my_correction[tpl.id] = true;
completed_correction = true;
} else { } else {
my_correction[tpl.id] = false; my_correction[tpl.id] = false;
} }
} }
// If no valid correction template AND valid answer is defined,
// don't consider the absence of match as valid answer.
if (!completed_correction && has_no_lost_answer) continue;
const auto = await autoCorrection(r.id_user, my_correction); const auto = await autoCorrection(r.id_user, my_correction);
r.score = auto.score; r.score = auto.score;
r.score_explaination = auto.score_explaination; r.score_explaination = auto.score_explaination;