feat: Füge Skript hinzu, um problematische Multiple-Choice-Übungen zu identifizieren und zu löschen
All checks were successful
Deploy to production / deploy (push) Successful in 1m57s
All checks were successful
Deploy to production / deploy (push) Successful in 1m57s
This commit is contained in:
74
backend/scripts/repair-remove-sentence-mc.js
Normal file
74
backend/scripts/repair-remove-sentence-mc.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Findet Multiple-Choice-Übungen, bei denen die Frage ein einzelnes Wort ist
|
||||||
|
* aber die richtige Antwort ein kompletter Satz (mehrere Wörter) ist.
|
||||||
|
*
|
||||||
|
* Default: Dry-run und listet die gefundenen Übungen auf.
|
||||||
|
* Use --apply to actually delete them from the DB.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { sequelize } from '../utils/sequelize.js';
|
||||||
|
import VocabGrammarExercise from '../models/community/vocab_grammar_exercise.js';
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const apply = args.includes('--apply');
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
await sequelize.authenticate();
|
||||||
|
console.log('✅ DB verbunden');
|
||||||
|
|
||||||
|
const list = await VocabGrammarExercise.findAll({
|
||||||
|
where: { exerciseTypeId: 2 },
|
||||||
|
order: [['lesson_id', 'ASC'], ['exercise_number', 'ASC']]
|
||||||
|
});
|
||||||
|
|
||||||
|
const candidates = [];
|
||||||
|
for (const ex of list) {
|
||||||
|
const q = ex.questionData || {};
|
||||||
|
const a = ex.answerData || {};
|
||||||
|
const questionText = String(q.question || q.text || '').trim();
|
||||||
|
const correct = String(a.correctAnswer || a.correct || a.correctAnswerText || '').trim();
|
||||||
|
if (!questionText || !correct) continue;
|
||||||
|
|
||||||
|
const questionWords = questionText.split(/\s+/).filter(Boolean).length;
|
||||||
|
const correctWords = correct.split(/\s+/).filter(Boolean).length;
|
||||||
|
|
||||||
|
// Heuristik: Frage ist Einzelwort, Antwort ist Satz (>1 Wort)
|
||||||
|
if (questionWords === 1 && correctWords > 1) {
|
||||||
|
candidates.push({ id: ex.id, lessonId: ex.lessonId, exerciseNumber: ex.exerciseNumber, title: ex.title, questionText, correct });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!candidates.length) {
|
||||||
|
console.log('Keine problematischen MC-Übungen gefunden.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Gefundene problematische Übungen: ${candidates.length}`);
|
||||||
|
candidates.forEach((c, i) => {
|
||||||
|
console.log(`${i + 1}. ID:${c.id} lesson:${c.lessonId} #${c.exerciseNumber} title:"${c.title}" question:"${c.questionText}" -> correct:"${c.correct}"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!apply) {
|
||||||
|
console.log('\nDry-run beendet. Verwende --apply, um die gefundenen Übungen zu löschen.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n--apply gesetzt: Lösche die gefundenen Übungen...');
|
||||||
|
for (const c of candidates) {
|
||||||
|
const ex = await VocabGrammarExercise.findByPk(c.id);
|
||||||
|
if (ex) {
|
||||||
|
await ex.destroy();
|
||||||
|
console.log(`Gelöscht: ID ${c.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('Fertig.');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Fehler:', err);
|
||||||
|
} finally {
|
||||||
|
await sequelize.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
Reference in New Issue
Block a user