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:
@@ -721,7 +721,12 @@ export default {
|
||||
},
|
||||
// Vokabeltrainer-Methoden
|
||||
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.vocabTrainerPool = [...this.importantVocab];
|
||||
this.vocabTrainerMode = 'multiple_choice';
|
||||
@@ -729,7 +734,10 @@ export default {
|
||||
this.vocabTrainerWrong = 0;
|
||||
this.vocabTrainerTotalAttempts = 0;
|
||||
this.vocabTrainerStats = {};
|
||||
console.log('[VocabLessonView] Rufe nextVocabQuestion auf');
|
||||
this.$nextTick(() => {
|
||||
this.nextVocabQuestion();
|
||||
});
|
||||
},
|
||||
stopVocabTrainer() {
|
||||
this.vocabTrainerActive = false;
|
||||
@@ -764,13 +772,30 @@ export default {
|
||||
buildChoiceOptions(correctAnswer, allVocabs) {
|
||||
const options = new Set([correctAnswer]);
|
||||
// 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 distractor = this.vocabTrainerDirection === 'L2R' ? randomVocab.reference : randomVocab.learning;
|
||||
if (distractor !== correctAnswer) {
|
||||
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
|
||||
const arr = Array.from(options);
|
||||
for (let i = arr.length - 1; i > 0; i--) {
|
||||
@@ -780,7 +805,9 @@ export default {
|
||||
return arr;
|
||||
},
|
||||
nextVocabQuestion() {
|
||||
console.log('[VocabLessonView] nextVocabQuestion aufgerufen');
|
||||
if (!this.vocabTrainerPool || this.vocabTrainerPool.length === 0) {
|
||||
console.log('[VocabLessonView] Keine Vokabeln im Pool');
|
||||
this.currentVocabQuestion = null;
|
||||
return;
|
||||
}
|
||||
@@ -799,6 +826,8 @@ export default {
|
||||
key: this.getVocabKey(vocab)
|
||||
};
|
||||
|
||||
console.log('[VocabLessonView] Neue Frage erstellt:', this.currentVocabQuestion.prompt);
|
||||
|
||||
// Reset UI
|
||||
this.vocabTrainerAnswer = '';
|
||||
this.vocabTrainerSelectedChoice = null;
|
||||
@@ -806,7 +835,9 @@ export default {
|
||||
|
||||
// Erstelle Choice-Optionen für Multiple Choice
|
||||
if (this.vocabTrainerMode === 'multiple_choice') {
|
||||
console.log('[VocabLessonView] Erstelle Choice-Optionen...');
|
||||
this.vocabTrainerChoiceOptions = this.buildChoiceOptions(this.currentVocabQuestion.answer, this.vocabTrainerPool);
|
||||
console.log('[VocabLessonView] Choice-Optionen erstellt:', this.vocabTrainerChoiceOptions.length);
|
||||
}
|
||||
|
||||
// Fokussiere Eingabefeld im Typing-Modus
|
||||
|
||||
Reference in New Issue
Block a user