Skip to content

Commit

Permalink
enhance: add possibility to check for single exact solution on numeri…
Browse files Browse the repository at this point in the history
…cal questions (#4333)
  • Loading branch information
sjschlapbach authored Oct 24, 2024
1 parent 21bb92f commit b5f558c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,16 @@ function createValidationSchema(t: ReturnType<typeof useTranslations>) {
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(),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,35 @@ function QuestionEvaluation({
</UserNotification>
)}
{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 ? (
<div className="mt-4 font-bold">
{t('manage.evaluation.correctExactSolution', {
value:
currentInstance.questionData.options.solutionRanges[0]
.min,
})}
</div>
) : (
<div>
<div className="mt-4 font-bold">
{t('manage.evaluation.correctSolutionRanges')}:
</div>
{currentInstance.questionData.options.solutionRanges.map(
(range, innerIndex) => (
<div key={innerIndex}>
[{range?.min || '-∞'},{range?.max || '+∞'}]
[{range.min ?? '-∞'},{range.max ?? '+∞'}]
</div>
)
)}
</div>
)}
))}
</div>
)}
{currentInstance.questionData.type === 'FREE_TEXT' &&
Expand Down
4 changes: 2 additions & 2 deletions packages/grading/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
1 change: 1 addition & 0 deletions packages/i18n/messages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/messages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b5f558c

Please sign in to comment.