From b5f558ca2315a4c526639c928c1f40926b0fdbd2 Mon Sep 17 00:00:00 2001 From: Julius Schlapbach <80708107+sjschlapbach@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:44:08 +0200 Subject: [PATCH] enhance: add possibility to check for single exact solution on numerical questions (#4333) --- .../questions/QuestionEditModal.tsx | 10 +++++---- .../evaluation/QuestionEvaluation.tsx | 21 ++++++++++++++++--- packages/grading/src/index.ts | 4 ++-- packages/i18n/messages/de.ts | 1 + packages/i18n/messages/en.ts | 1 + 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/frontend-manage/src/components/questions/QuestionEditModal.tsx b/apps/frontend-manage/src/components/questions/QuestionEditModal.tsx index db391f33dd..b8e4dc527d 100644 --- a/apps/frontend-manage/src/components/questions/QuestionEditModal.tsx +++ b/apps/frontend-manage/src/components/questions/QuestionEditModal.tsx @@ -183,14 +183,16 @@ function createValidationSchema(t: ReturnType) { Yup.object().shape({ min: Yup.number() .nullable() + // TODO: include this validation step again, once exact solutions can be handled through a separate input // we can only handle one case to avoid cyclic dependencies .when('max', { is: (max?: number | null) => typeof max !== 'undefined', then: (schema) => - schema.lessThan( - Yup.ref('max'), - t('manage.formErrors.NRMinLessThanMaxSol') - ), + schema.test({ + message: t('manage.formErrors.NRMinLessThanMaxSol'), + test: (value, context) => + value ? value <= context.parent.max : true, + }), }), max: Yup.number().nullable(), }) diff --git a/apps/frontend-manage/src/components/sessions/evaluation/QuestionEvaluation.tsx b/apps/frontend-manage/src/components/sessions/evaluation/QuestionEvaluation.tsx index b2b4b7ddf1..590741716d 100644 --- a/apps/frontend-manage/src/components/sessions/evaluation/QuestionEvaluation.tsx +++ b/apps/frontend-manage/src/components/sessions/evaluation/QuestionEvaluation.tsx @@ -190,7 +190,22 @@ function QuestionEvaluation({ )} {showSolution && - currentInstance.questionData.options.solutionRanges && ( + currentInstance.questionData.options.solutionRanges && + (currentInstance.questionData.options.solutionRanges.length === + 1 && + currentInstance.questionData.options.solutionRanges[0].min && + currentInstance.questionData.options.solutionRanges[0].max && + currentInstance.questionData.options.solutionRanges[0].min > + currentInstance.questionData.options.solutionRanges[0].max - + 2 * Number.EPSILON ? ( +
+ {t('manage.evaluation.correctExactSolution', { + value: + currentInstance.questionData.options.solutionRanges[0] + .min, + })} +
+ ) : (
{t('manage.evaluation.correctSolutionRanges')}: @@ -198,12 +213,12 @@ function QuestionEvaluation({ {currentInstance.questionData.options.solutionRanges.map( (range, innerIndex) => (
- [{range?.min || '-∞'},{range?.max || '+∞'}] + [{range.min ?? '-∞'},{range.max ?? '+∞'}]
) )}
- )} + ))}
)} {currentInstance.questionData.type === 'FREE_TEXT' && diff --git a/packages/grading/src/index.ts b/packages/grading/src/index.ts index 0c6ae37db9..18ca4ffa0e 100644 --- a/packages/grading/src/index.ts +++ b/packages/grading/src/index.ts @@ -93,8 +93,8 @@ export function gradeQuestionNumerical({ if (definedSolutionRanges.length === 0) return null const withinRanges = definedSolutionRanges.map(({ min, max }) => { - if (min && response < min) return false - if (max && response > max) return false + if (min && response < min - Number.EPSILON) return false + if (max && response > max + Number.EPSILON) return false return true }) diff --git a/packages/i18n/messages/de.ts b/packages/i18n/messages/de.ts index baa9fe3c5d..5e0d6e8f24 100644 --- a/packages/i18n/messages/de.ts +++ b/packages/i18n/messages/de.ts @@ -1429,6 +1429,7 @@ Da die KlickerUZH-App noch nicht im iOS-App-Store verfügbar ist, folgen Sie die fontSize: 'Schriftgrösse', validSolutionRange: 'Erlaubter Antwortbereich', correctSolutionRanges: 'Korrekte Lösungsbereiche', + correctExactSolution: 'Korrekte Lösung: {value}', statistics: 'Statistik', keywordsSolution: 'Schlüsselwörter Lösung', noChartsAvailable: 'There exists no chart for this question type yet', diff --git a/packages/i18n/messages/en.ts b/packages/i18n/messages/en.ts index 0544486ccf..0b925198d3 100644 --- a/packages/i18n/messages/en.ts +++ b/packages/i18n/messages/en.ts @@ -1416,6 +1416,7 @@ Since the KlickerUZH app is not yet available on the iOS App Store, follow these fontSize: 'Font size', validSolutionRange: 'Valid solution range', correctSolutionRanges: 'Correct solution ranges', + correctExactSolution: 'Correct solution: {value}', statistics: 'Statistics', keywordsSolution: 'Solution keywords', noChartsAvailable: 'There exists no chart for this question type yet',