Enhance logging and improve vocabulary trainer functionality in VocabLessonView

- Added detailed console logging to track the flow of the vocabulary trainer, including checks for available vocabulary and question generation.
- Implemented a safeguard against infinite loops when generating choice options by limiting attempts.
- Enhanced the buildChoiceOptions method to ensure a minimum number of options, adding generic choices if necessary.
- Improved the nextVocabQuestion method with additional logging for better debugging and user feedback.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 22:33:12 +01:00
parent 2eee7bb0c1
commit 9e6787fb3f

View File

@@ -721,7 +721,12 @@ export default {
}, },
// Vokabeltrainer-Methoden // Vokabeltrainer-Methoden
startVocabTrainer() { startVocabTrainer() {
if (!this.importantVocab || this.importantVocab.length === 0) return; console.log('[VocabLessonView] startVocabTrainer aufgerufen');
if (!this.importantVocab || this.importantVocab.length === 0) {
console.log('[VocabLessonView] Keine Vokabeln vorhanden');
return;
}
console.log('[VocabLessonView] Vokabeln gefunden:', this.importantVocab.length);
this.vocabTrainerActive = true; this.vocabTrainerActive = true;
this.vocabTrainerPool = [...this.importantVocab]; this.vocabTrainerPool = [...this.importantVocab];
this.vocabTrainerMode = 'multiple_choice'; this.vocabTrainerMode = 'multiple_choice';
@@ -729,7 +734,10 @@ export default {
this.vocabTrainerWrong = 0; this.vocabTrainerWrong = 0;
this.vocabTrainerTotalAttempts = 0; this.vocabTrainerTotalAttempts = 0;
this.vocabTrainerStats = {}; this.vocabTrainerStats = {};
console.log('[VocabLessonView] Rufe nextVocabQuestion auf');
this.$nextTick(() => {
this.nextVocabQuestion(); this.nextVocabQuestion();
});
}, },
stopVocabTrainer() { stopVocabTrainer() {
this.vocabTrainerActive = false; this.vocabTrainerActive = false;
@@ -764,13 +772,30 @@ export default {
buildChoiceOptions(correctAnswer, allVocabs) { buildChoiceOptions(correctAnswer, allVocabs) {
const options = new Set([correctAnswer]); const options = new Set([correctAnswer]);
// Füge 3 Distraktoren hinzu // Füge 3 Distraktoren hinzu
while (options.size < 4 && allVocabs.length > 1) { let attempts = 0;
const maxAttempts = 50; // Verhindere Endlosschleife
while (options.size < 4 && allVocabs.length > 1 && attempts < maxAttempts) {
attempts++;
const randomVocab = allVocabs[Math.floor(Math.random() * allVocabs.length)]; const randomVocab = allVocabs[Math.floor(Math.random() * allVocabs.length)];
const distractor = this.vocabTrainerDirection === 'L2R' ? randomVocab.reference : randomVocab.learning; const distractor = this.vocabTrainerDirection === 'L2R' ? randomVocab.reference : randomVocab.learning;
if (distractor !== correctAnswer) { if (distractor !== correctAnswer) {
options.add(distractor); options.add(distractor);
} }
} }
// Falls nicht genug Optionen gefunden wurden, füge generische Optionen hinzu
if (options.size < 4) {
const genericOptions = ['Option A', 'Option B', 'Option C', 'Option D'];
let index = 0;
while (options.size < 4 && index < genericOptions.length) {
if (!options.has(genericOptions[index])) {
options.add(genericOptions[index]);
}
index++;
}
}
// Shuffle // Shuffle
const arr = Array.from(options); const arr = Array.from(options);
for (let i = arr.length - 1; i > 0; i--) { for (let i = arr.length - 1; i > 0; i--) {
@@ -780,7 +805,9 @@ export default {
return arr; return arr;
}, },
nextVocabQuestion() { nextVocabQuestion() {
console.log('[VocabLessonView] nextVocabQuestion aufgerufen');
if (!this.vocabTrainerPool || this.vocabTrainerPool.length === 0) { if (!this.vocabTrainerPool || this.vocabTrainerPool.length === 0) {
console.log('[VocabLessonView] Keine Vokabeln im Pool');
this.currentVocabQuestion = null; this.currentVocabQuestion = null;
return; return;
} }
@@ -799,6 +826,8 @@ export default {
key: this.getVocabKey(vocab) key: this.getVocabKey(vocab)
}; };
console.log('[VocabLessonView] Neue Frage erstellt:', this.currentVocabQuestion.prompt);
// Reset UI // Reset UI
this.vocabTrainerAnswer = ''; this.vocabTrainerAnswer = '';
this.vocabTrainerSelectedChoice = null; this.vocabTrainerSelectedChoice = null;
@@ -806,7 +835,9 @@ export default {
// Erstelle Choice-Optionen für Multiple Choice // Erstelle Choice-Optionen für Multiple Choice
if (this.vocabTrainerMode === 'multiple_choice') { if (this.vocabTrainerMode === 'multiple_choice') {
console.log('[VocabLessonView] Erstelle Choice-Optionen...');
this.vocabTrainerChoiceOptions = this.buildChoiceOptions(this.currentVocabQuestion.answer, this.vocabTrainerPool); this.vocabTrainerChoiceOptions = this.buildChoiceOptions(this.currentVocabQuestion.answer, this.vocabTrainerPool);
console.log('[VocabLessonView] Choice-Optionen erstellt:', this.vocabTrainerChoiceOptions.length);
} }
// Fokussiere Eingabefeld im Typing-Modus // Fokussiere Eingabefeld im Typing-Modus