refactor(exercises): standardize answer language handling across exercise scripts
All checks were successful
Deploy to production / deploy (push) Successful in 2m48s

- Introduced a mechanism to infer answer language based on question phrasing in multiple exercise scripts, enhancing consistency in exercise data.
- Updated question formats to clarify the intent of exercises, improving user understanding and engagement.
- Streamlined the code for better maintainability and clarity in exercise generation processes.
This commit is contained in:
Torsten Schulz (local)
2026-04-07 14:32:44 +02:00
parent 160c9dafb2
commit ebb2283646
7 changed files with 107 additions and 6 deletions

View File

@@ -23,6 +23,31 @@ function withTypeName(exerciseTypeName, exercise) {
const LESSON_TITLES = ['Woche 1 - Wiederholung', 'Woche 1 - Vokabeltest'];
function normalizeMcAnswerLanguage(question = '') {
const q = String(question || '').trim();
if (!q) return null;
if (/Wie sagt man/i.test(q) || /auf Bisaya\?/i.test(q)) return 'target';
if (/Was bedeutet/i.test(q) || /Was heißt/i.test(q)) return 'native';
return null;
}
function enrichAnswerLanguage(exercises = []) {
return exercises.map((exercise) => {
const qd = exercise?.questionData;
if (!qd || qd.type !== 'multiple_choice') return exercise;
if (qd.answerLanguage || qd.answerLanguageId) return exercise;
const inferred = normalizeMcAnswerLanguage(qd.question);
if (!inferred) return exercise;
return {
...exercise,
questionData: {
...qd,
answerLanguage: inferred
}
};
});
}
const BISAYA_EXERCISES = {
'Woche 1 - Wiederholung': [
{ exerciseTypeId: 2, title: 'Wiederholung: Wie sagt man "Wie geht es dir?"?', instruction: 'Wähle die richtige Begrüßung aus.', questionData: { type: 'multiple_choice', question: 'Wie sagt man "Wie geht es dir?" auf Bisaya?', options: ['Kumusta ka?', 'Maayo', 'Salamat', 'Palihug'] }, answerData: { type: 'multiple_choice', correctAnswer: 0 }, explanation: '"Kumusta ka?" ist die Standard-Begrüßung auf Bisaya.' },
@@ -111,7 +136,7 @@ async function updateWeek1BisayaExercises() {
console.log(`📚 Kurs: ${course.title} (ID: ${course.id})`);
for (const lessonTitle of LESSON_TITLES) {
const exercises = BISAYA_EXERCISES[lessonTitle];
const exercises = enrichAnswerLanguage(BISAYA_EXERCISES[lessonTitle]);
if (!exercises || exercises.length === 0) continue;
const lessons = await VocabCourseLesson.findAll({