Refactor updateFoodCareExercises function to optimize database queries and improve code clarity
- Replaced the Sequelize findAll method with a raw SQL query to fetch Bisaya courses along with native language information, enhancing performance. - Updated variable names for consistency and clarity, ensuring better readability of the code. - Adjusted the handling of course owner IDs to align with the new query structure, improving data integrity.
This commit is contained in:
@@ -512,16 +512,24 @@ async function updateFoodCareExercises() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const courses = await VocabCourse.findAll({
|
const bisayaLanguageId = bisayaLanguage.id;
|
||||||
where: { languageId: bisayaLanguage.id },
|
|
||||||
include: [
|
// Hole alle Bisaya-Kurse mit native language info
|
||||||
|
const courses = await sequelize.query(
|
||||||
|
`SELECT
|
||||||
|
c.id,
|
||||||
|
c.title,
|
||||||
|
c.owner_user_id,
|
||||||
|
c.native_language_id,
|
||||||
|
nl.name as native_language_name
|
||||||
|
FROM community.vocab_course c
|
||||||
|
LEFT JOIN community.vocab_language nl ON c.native_language_id = nl.id
|
||||||
|
WHERE c.language_id = :bisayaLanguageId`,
|
||||||
{
|
{
|
||||||
model: sequelize.models.VocabLanguage,
|
replacements: { bisayaLanguageId },
|
||||||
as: 'nativeLanguage',
|
type: sequelize.QueryTypes.SELECT
|
||||||
attributes: ['name']
|
|
||||||
}
|
}
|
||||||
]
|
);
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`Gefunden: ${courses.length} Bisaya-Kurse\n`);
|
console.log(`Gefunden: ${courses.length} Bisaya-Kurse\n`);
|
||||||
|
|
||||||
@@ -530,7 +538,7 @@ async function updateFoodCareExercises() {
|
|||||||
|
|
||||||
for (const course of courses) {
|
for (const course of courses) {
|
||||||
console.log(`📚 Kurs: ${course.title} (ID: ${course.id})`);
|
console.log(`📚 Kurs: ${course.title} (ID: ${course.id})`);
|
||||||
const nativeLangName = course.nativeLanguage?.name || 'Deutsch';
|
const nativeLangName = course.native_language_name || 'Deutsch';
|
||||||
console.log(` Muttersprache: ${nativeLangName}`);
|
console.log(` Muttersprache: ${nativeLangName}`);
|
||||||
|
|
||||||
// Finde "Essen & Fürsorge" und "Essen & Trinken" Lektionen
|
// Finde "Essen & Fürsorge" und "Essen & Trinken" Lektionen
|
||||||
@@ -587,7 +595,7 @@ async function updateFoodCareExercises() {
|
|||||||
correctAnswer: 0
|
correctAnswer: 0
|
||||||
}),
|
}),
|
||||||
explanation: conv.explanation,
|
explanation: conv.explanation,
|
||||||
createdByUserId: course.ownerUserId || systemUser.id
|
createdByUserId: course.owner_user_id || systemUser.id
|
||||||
});
|
});
|
||||||
totalExercisesCreated++;
|
totalExercisesCreated++;
|
||||||
|
|
||||||
@@ -613,7 +621,7 @@ async function updateFoodCareExercises() {
|
|||||||
correctAnswer: 0
|
correctAnswer: 0
|
||||||
}),
|
}),
|
||||||
explanation: conv.explanation,
|
explanation: conv.explanation,
|
||||||
createdByUserId: course.ownerUserId || systemUser.id
|
createdByUserId: course.owner_user_id || systemUser.id
|
||||||
});
|
});
|
||||||
totalExercisesCreated++;
|
totalExercisesCreated++;
|
||||||
}
|
}
|
||||||
@@ -639,7 +647,7 @@ async function updateFoodCareExercises() {
|
|||||||
alternatives: []
|
alternatives: []
|
||||||
}),
|
}),
|
||||||
explanation: conv.explanation,
|
explanation: conv.explanation,
|
||||||
createdByUserId: course.ownerUserId || systemUser.id
|
createdByUserId: course.owner_user_id || systemUser.id
|
||||||
});
|
});
|
||||||
totalExercisesCreated++;
|
totalExercisesCreated++;
|
||||||
}
|
}
|
||||||
@@ -668,7 +676,7 @@ async function updateFoodCareExercises() {
|
|||||||
correctAnswer: 0
|
correctAnswer: 0
|
||||||
}),
|
}),
|
||||||
explanation: vocab.explanation,
|
explanation: vocab.explanation,
|
||||||
createdByUserId: course.ownerUserId || systemUser.id
|
createdByUserId: course.owner_user_id || systemUser.id
|
||||||
});
|
});
|
||||||
totalExercisesCreated++;
|
totalExercisesCreated++;
|
||||||
|
|
||||||
@@ -694,7 +702,7 @@ async function updateFoodCareExercises() {
|
|||||||
correctAnswer: 0
|
correctAnswer: 0
|
||||||
}),
|
}),
|
||||||
explanation: vocab.explanation,
|
explanation: vocab.explanation,
|
||||||
createdByUserId: course.ownerUserId || systemUser.id
|
createdByUserId: course.owner_user_id || systemUser.id
|
||||||
});
|
});
|
||||||
totalExercisesCreated++;
|
totalExercisesCreated++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -408,7 +408,8 @@
|
|||||||
"recordingError": "Aufnahme-Fehler",
|
"recordingError": "Aufnahme-Fehler",
|
||||||
"recognizedText": "Erkannter Text",
|
"recognizedText": "Erkannter Text",
|
||||||
"speechRecognitionNotSupported": "Speech Recognition wird von diesem Browser nicht unterstützt. Bitte verwende Chrome oder Edge.",
|
"speechRecognitionNotSupported": "Speech Recognition wird von diesem Browser nicht unterstützt. Bitte verwende Chrome oder Edge.",
|
||||||
"keywords": "Schlüsselwörter"
|
"keywords": "Schlüsselwörter",
|
||||||
|
"switchBackToMultipleChoice": "Zurück zu Multiple Choice"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -408,7 +408,8 @@
|
|||||||
"recordingError": "Recording error",
|
"recordingError": "Recording error",
|
||||||
"recognizedText": "Recognized Text",
|
"recognizedText": "Recognized Text",
|
||||||
"speechRecognitionNotSupported": "Speech Recognition is not supported by this browser. Please use Chrome or Edge.",
|
"speechRecognitionNotSupported": "Speech Recognition is not supported by this browser. Please use Chrome or Edge.",
|
||||||
"keywords": "Keywords"
|
"keywords": "Keywords",
|
||||||
|
"switchBackToMultipleChoice": "Switch back to Multiple Choice"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- Texteingabe Modus -->
|
<!-- Texteingabe Modus -->
|
||||||
<div v-else class="vocab-answer-area typing">
|
<div v-else class="vocab-answer-area typing">
|
||||||
|
<div v-if="vocabTrainerAutoSwitchedToTyping" class="mode-switch-notice">
|
||||||
|
<button @click="switchBackToMultipleChoice" class="btn-switch-mode">
|
||||||
|
{{ $t('socialnetwork.vocab.courses.switchBackToMultipleChoice') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<input
|
<input
|
||||||
v-model="vocabTrainerAnswer"
|
v-model="vocabTrainerAnswer"
|
||||||
@keydown.enter.prevent="checkVocabAnswer"
|
@keydown.enter.prevent="checkVocabAnswer"
|
||||||
@@ -430,6 +435,7 @@ export default {
|
|||||||
vocabTrainerActive: false,
|
vocabTrainerActive: false,
|
||||||
vocabTrainerPool: [],
|
vocabTrainerPool: [],
|
||||||
vocabTrainerMode: 'multiple_choice', // 'multiple_choice' oder 'typing'
|
vocabTrainerMode: 'multiple_choice', // 'multiple_choice' oder 'typing'
|
||||||
|
vocabTrainerAutoSwitchedToTyping: false, // Track ob automatisch zu Typing gewechselt wurde
|
||||||
vocabTrainerCorrect: 0,
|
vocabTrainerCorrect: 0,
|
||||||
vocabTrainerWrong: 0,
|
vocabTrainerWrong: 0,
|
||||||
vocabTrainerTotalAttempts: 0,
|
vocabTrainerTotalAttempts: 0,
|
||||||
@@ -997,6 +1003,7 @@ export default {
|
|||||||
this.vocabTrainerActive = true;
|
this.vocabTrainerActive = true;
|
||||||
this.vocabTrainerPool = [...this.importantVocab];
|
this.vocabTrainerPool = [...this.importantVocab];
|
||||||
this.vocabTrainerMode = 'multiple_choice';
|
this.vocabTrainerMode = 'multiple_choice';
|
||||||
|
this.vocabTrainerAutoSwitchedToTyping = false;
|
||||||
this.vocabTrainerCorrect = 0;
|
this.vocabTrainerCorrect = 0;
|
||||||
this.vocabTrainerWrong = 0;
|
this.vocabTrainerWrong = 0;
|
||||||
this.vocabTrainerTotalAttempts = 0;
|
this.vocabTrainerTotalAttempts = 0;
|
||||||
@@ -1008,6 +1015,8 @@ export default {
|
|||||||
},
|
},
|
||||||
stopVocabTrainer() {
|
stopVocabTrainer() {
|
||||||
this.vocabTrainerActive = false;
|
this.vocabTrainerActive = false;
|
||||||
|
this.vocabTrainerMode = 'multiple_choice';
|
||||||
|
this.vocabTrainerAutoSwitchedToTyping = false;
|
||||||
this.currentVocabQuestion = null;
|
this.currentVocabQuestion = null;
|
||||||
this.vocabTrainerAnswer = '';
|
this.vocabTrainerAnswer = '';
|
||||||
this.vocabTrainerSelectedChoice = null;
|
this.vocabTrainerSelectedChoice = null;
|
||||||
@@ -1029,6 +1038,7 @@ export default {
|
|||||||
const successRate = (this.vocabTrainerCorrect / this.vocabTrainerTotalAttempts) * 100;
|
const successRate = (this.vocabTrainerCorrect / this.vocabTrainerTotalAttempts) * 100;
|
||||||
if (successRate >= 80) {
|
if (successRate >= 80) {
|
||||||
this.vocabTrainerMode = 'typing';
|
this.vocabTrainerMode = 'typing';
|
||||||
|
this.vocabTrainerAutoSwitchedToTyping = true; // Markiere als automatisch gewechselt
|
||||||
// Reset Stats für Texteingabe-Modus
|
// Reset Stats für Texteingabe-Modus
|
||||||
this.vocabTrainerCorrect = 0;
|
this.vocabTrainerCorrect = 0;
|
||||||
this.vocabTrainerWrong = 0;
|
this.vocabTrainerWrong = 0;
|
||||||
@@ -1036,6 +1046,17 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
switchBackToMultipleChoice() {
|
||||||
|
// Wechsle zurück zu Multiple Choice
|
||||||
|
this.vocabTrainerMode = 'multiple_choice';
|
||||||
|
this.vocabTrainerAutoSwitchedToTyping = false;
|
||||||
|
// Reset Stats für Multiple Choice Modus
|
||||||
|
this.vocabTrainerCorrect = 0;
|
||||||
|
this.vocabTrainerWrong = 0;
|
||||||
|
this.vocabTrainerTotalAttempts = 0;
|
||||||
|
// Starte neue Frage im Multiple Choice Modus
|
||||||
|
this.nextVocabQuestion();
|
||||||
|
},
|
||||||
buildChoiceOptions(correctAnswer, allVocabs, excludePrompt = null) {
|
buildChoiceOptions(correctAnswer, allVocabs, excludePrompt = null) {
|
||||||
const options = new Set([correctAnswer]);
|
const options = new Set([correctAnswer]);
|
||||||
// Normalisiere alle Werte für den Vergleich (trim + lowercase)
|
// Normalisiere alle Werte für den Vergleich (trim + lowercase)
|
||||||
@@ -1765,9 +1786,37 @@ export default {
|
|||||||
|
|
||||||
.vocab-answer-area.typing {
|
.vocab-answer-area.typing {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mode-switch-notice {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
background: #fff3cd;
|
||||||
|
border: 1px solid #ffc107;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-switch-mode {
|
||||||
|
padding: 8px 16px;
|
||||||
|
background: #F9A22C;
|
||||||
|
color: #000000;
|
||||||
|
border: 1px solid #F9A22C;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.9em;
|
||||||
|
font-weight: 500;
|
||||||
|
transition: background 0.05s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-switch-mode:hover {
|
||||||
|
background: #fdf1db;
|
||||||
|
color: #7E471B;
|
||||||
|
border: 1px solid #7E471B;
|
||||||
|
}
|
||||||
|
|
||||||
.vocab-answer-area.multiple-choice {
|
.vocab-answer-area.multiple-choice {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
Reference in New Issue
Block a user