- Introduced a new set of multiple choice and gap fill exercises focused on family-related vocabulary in Bisaya, enhancing language learning. - Included detailed explanations for each term to provide context and aid understanding for learners. - Removed dummy exercises for unknown lessons, streamlining the exercise return logic for better user experience.
259 lines
7.9 KiB
JavaScript
Executable File
259 lines
7.9 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Script zum Aktualisieren der "Familienwörter"-Übungen in Bisaya-Kursen
|
|
*
|
|
* Verwendung:
|
|
* node backend/scripts/update-family-words-exercises.js
|
|
*
|
|
* Ersetzt bestehende Dummy-Übungen durch spezifische Familienwörter-Übungen.
|
|
*/
|
|
|
|
import { sequelize } from '../utils/sequelize.js';
|
|
import VocabCourseLesson from '../models/community/vocab_course_lesson.js';
|
|
import VocabGrammarExercise from '../models/community/vocab_grammar_exercise.js';
|
|
import User from '../models/community/user.js';
|
|
|
|
// Spezifische Übungen für Familienwörter
|
|
const FAMILY_WORDS_EXERCISES = [
|
|
{
|
|
exerciseTypeId: 2, // multiple_choice
|
|
title: 'Wie sagt man "Mutter" auf Bisaya?',
|
|
instruction: 'Wähle die richtige Übersetzung.',
|
|
questionData: {
|
|
type: 'multiple_choice',
|
|
question: 'Wie sagt man "Mutter" auf Bisaya?',
|
|
options: ['Nanay', 'Tatay', 'Kuya', 'Ate']
|
|
},
|
|
answerData: {
|
|
type: 'multiple_choice',
|
|
correctAnswer: 0
|
|
},
|
|
explanation: '"Nanay" bedeutet "Mutter" auf Bisaya. "Mama" wird auch verwendet.'
|
|
},
|
|
{
|
|
exerciseTypeId: 2, // multiple_choice
|
|
title: 'Wie sagt man "Vater" auf Bisaya?',
|
|
instruction: 'Wähle die richtige Übersetzung.',
|
|
questionData: {
|
|
type: 'multiple_choice',
|
|
question: 'Wie sagt man "Vater" auf Bisaya?',
|
|
options: ['Tatay', 'Nanay', 'Kuya', 'Ate']
|
|
},
|
|
answerData: {
|
|
type: 'multiple_choice',
|
|
correctAnswer: 0
|
|
},
|
|
explanation: '"Tatay" bedeutet "Vater" auf Bisaya. "Papa" wird auch verwendet.'
|
|
},
|
|
{
|
|
exerciseTypeId: 2, // multiple_choice
|
|
title: 'Wie sagt man "älterer Bruder" auf Bisaya?',
|
|
instruction: 'Wähle die richtige Übersetzung.',
|
|
questionData: {
|
|
type: 'multiple_choice',
|
|
question: 'Wie sagt man "älterer Bruder" auf Bisaya?',
|
|
options: ['Kuya', 'Ate', 'Nanay', 'Tatay']
|
|
},
|
|
answerData: {
|
|
type: 'multiple_choice',
|
|
correctAnswer: 0
|
|
},
|
|
explanation: '"Kuya" bedeutet "älterer Bruder" auf Bisaya. Wird auch für respektvolle Anrede von älteren Männern verwendet.'
|
|
},
|
|
{
|
|
exerciseTypeId: 2, // multiple_choice
|
|
title: 'Wie sagt man "ältere Schwester" auf Bisaya?',
|
|
instruction: 'Wähle die richtige Übersetzung.',
|
|
questionData: {
|
|
type: 'multiple_choice',
|
|
question: 'Wie sagt man "ältere Schwester" auf Bisaya?',
|
|
options: ['Ate', 'Kuya', 'Nanay', 'Tatay']
|
|
},
|
|
answerData: {
|
|
type: 'multiple_choice',
|
|
correctAnswer: 0
|
|
},
|
|
explanation: '"Ate" bedeutet "ältere Schwester" auf Bisaya. Wird auch für respektvolle Anrede von älteren Frauen verwendet.'
|
|
},
|
|
{
|
|
exerciseTypeId: 2, // multiple_choice
|
|
title: 'Wie sagt man "Großmutter" auf Bisaya?',
|
|
instruction: 'Wähle die richtige Übersetzung.',
|
|
questionData: {
|
|
type: 'multiple_choice',
|
|
question: 'Wie sagt man "Großmutter" auf Bisaya?',
|
|
options: ['Lola', 'Lolo', 'Nanay', 'Tatay']
|
|
},
|
|
answerData: {
|
|
type: 'multiple_choice',
|
|
correctAnswer: 0
|
|
},
|
|
explanation: '"Lola" bedeutet "Großmutter" auf Bisaya.'
|
|
},
|
|
{
|
|
exerciseTypeId: 2, // multiple_choice
|
|
title: 'Wie sagt man "Großvater" auf Bisaya?',
|
|
instruction: 'Wähle die richtige Übersetzung.',
|
|
questionData: {
|
|
type: 'multiple_choice',
|
|
question: 'Wie sagt man "Großvater" auf Bisaya?',
|
|
options: ['Lolo', 'Lola', 'Nanay', 'Tatay']
|
|
},
|
|
answerData: {
|
|
type: 'multiple_choice',
|
|
correctAnswer: 0
|
|
},
|
|
explanation: '"Lolo" bedeutet "Großvater" auf Bisaya.'
|
|
},
|
|
{
|
|
exerciseTypeId: 1, // gap_fill
|
|
title: 'Familienwörter vervollständigen',
|
|
instruction: 'Fülle die Lücken mit den richtigen Bisaya-Familienwörtern.',
|
|
questionData: {
|
|
type: 'gap_fill',
|
|
text: '{gap} (Mutter) | {gap} (Vater) | {gap} (älterer Bruder) | {gap} (ältere Schwester) | {gap} (Großmutter) | {gap} (Großvater)',
|
|
gaps: 6
|
|
},
|
|
answerData: {
|
|
type: 'gap_fill',
|
|
answers: ['Nanay', 'Tatay', 'Kuya', 'Ate', 'Lola', 'Lolo']
|
|
},
|
|
explanation: 'Nanay = Mutter, Tatay = Vater, Kuya = älterer Bruder, Ate = ältere Schwester, Lola = Großmutter, Lolo = Großvater.'
|
|
},
|
|
{
|
|
exerciseTypeId: 4, // transformation
|
|
title: 'Familienwörter übersetzen',
|
|
instruction: 'Übersetze das Familienwort ins Bisaya.',
|
|
questionData: {
|
|
type: 'transformation',
|
|
text: 'Mutter',
|
|
sourceLanguage: 'Deutsch',
|
|
targetLanguage: 'Bisaya'
|
|
},
|
|
answerData: {
|
|
type: 'transformation',
|
|
correct: 'Nanay',
|
|
alternatives: ['Mama', 'Nanay', 'Inahan']
|
|
},
|
|
explanation: '"Nanay" oder "Mama" bedeutet "Mutter" auf Bisaya.'
|
|
}
|
|
];
|
|
|
|
async function findOrCreateSystemUser() {
|
|
let systemUser = await User.findOne({
|
|
where: {
|
|
username: 'system'
|
|
}
|
|
});
|
|
|
|
if (!systemUser) {
|
|
systemUser = await User.findOne({
|
|
where: {
|
|
username: 'admin'
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!systemUser) {
|
|
console.error('❌ System-Benutzer nicht gefunden.');
|
|
throw new Error('System user not found');
|
|
}
|
|
|
|
return systemUser;
|
|
}
|
|
|
|
async function updateFamilyWordsExercises() {
|
|
await sequelize.authenticate();
|
|
console.log('Datenbankverbindung erfolgreich hergestellt.\n');
|
|
|
|
const systemUser = await findOrCreateSystemUser();
|
|
console.log(`Verwende System-Benutzer: ${systemUser.username} (ID: ${systemUser.id})\n`);
|
|
|
|
// Finde alle Bisaya-Kurse
|
|
const [bisayaLanguage] = await sequelize.query(
|
|
`SELECT id FROM community.vocab_language WHERE name = 'Bisaya' LIMIT 1`,
|
|
{
|
|
type: sequelize.QueryTypes.SELECT
|
|
}
|
|
);
|
|
|
|
if (!bisayaLanguage) {
|
|
console.error('❌ Bisaya-Sprache nicht gefunden.');
|
|
return;
|
|
}
|
|
|
|
const courses = await sequelize.query(
|
|
`SELECT id, title, owner_user_id FROM community.vocab_course WHERE language_id = :languageId`,
|
|
{
|
|
replacements: { languageId: bisayaLanguage.id },
|
|
type: sequelize.QueryTypes.SELECT
|
|
}
|
|
);
|
|
|
|
console.log(`Gefunden: ${courses.length} Bisaya-Kurse\n`);
|
|
|
|
let totalExercisesUpdated = 0;
|
|
let totalLessonsUpdated = 0;
|
|
|
|
for (const course of courses) {
|
|
console.log(`📚 Kurs: ${course.title} (ID: ${course.id})`);
|
|
|
|
// Finde "Familienwörter"-Lektionen
|
|
const lessons = await VocabCourseLesson.findAll({
|
|
where: {
|
|
courseId: course.id,
|
|
title: 'Familienwörter'
|
|
},
|
|
order: [['lessonNumber', 'ASC']]
|
|
});
|
|
|
|
console.log(` ${lessons.length} "Familienwörter"-Lektionen gefunden\n`);
|
|
|
|
for (const lesson of lessons) {
|
|
// Lösche bestehende Übungen (inkl. Dummy-Übungen)
|
|
const deletedCount = await VocabGrammarExercise.destroy({
|
|
where: { lessonId: lesson.id }
|
|
});
|
|
|
|
console.log(` 🗑️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - ${deletedCount} alte Übung(en) gelöscht`);
|
|
|
|
// Erstelle neue Übungen
|
|
let exerciseNumber = 1;
|
|
for (const exerciseData of FAMILY_WORDS_EXERCISES) {
|
|
await VocabGrammarExercise.create({
|
|
lessonId: lesson.id,
|
|
exerciseTypeId: exerciseData.exerciseTypeId,
|
|
exerciseNumber: exerciseNumber++,
|
|
title: exerciseData.title,
|
|
instruction: exerciseData.instruction,
|
|
questionData: JSON.stringify(exerciseData.questionData),
|
|
answerData: JSON.stringify(exerciseData.answerData),
|
|
explanation: exerciseData.explanation,
|
|
createdByUserId: course.owner_user_id || systemUser.id
|
|
});
|
|
totalExercisesUpdated++;
|
|
}
|
|
|
|
console.log(` ✅ Lektion ${lesson.lessonNumber}: "${lesson.title}" - ${FAMILY_WORDS_EXERCISES.length} neue Übung(en) erstellt`);
|
|
totalLessonsUpdated++;
|
|
}
|
|
|
|
console.log('');
|
|
}
|
|
|
|
console.log(`\n🎉 Zusammenfassung:`);
|
|
console.log(` ${totalLessonsUpdated} Lektionen aktualisiert`);
|
|
console.log(` ${totalExercisesUpdated} neue Grammatik-Übungen erstellt`);
|
|
}
|
|
|
|
updateFamilyWordsExercises()
|
|
.then(() => {
|
|
sequelize.close();
|
|
process.exit(0);
|
|
})
|
|
.catch((error) => {
|
|
console.error('❌ Fehler:', error);
|
|
sequelize.close();
|
|
process.exit(1);
|
|
});
|