42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function shuffleArray(array) {
|
|
for (let i = array.length - 1; i > 0; i--) {
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
[array[i], array[j]] = [array[j], array[i]];
|
|
}
|
|
}
|
|
|
|
function processFile(filePath) {
|
|
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
let qCount = 0;
|
|
let ansCounts = {0: 0, 1: 0, 2: 0, 3: 0};
|
|
|
|
const processQuestion = (q) => {
|
|
const correctOpt = q.opts[q.ans];
|
|
shuffleArray(q.opts);
|
|
q.ans = q.opts.indexOf(correctOpt);
|
|
ansCounts[q.ans] = (ansCounts[q.ans] || 0) + 1;
|
|
qCount++;
|
|
};
|
|
|
|
if (data.sets) {
|
|
data.sets.forEach(set => set.questions.forEach(processQuestion));
|
|
} else if (data.questions) {
|
|
data.questions.forEach(processQuestion);
|
|
}
|
|
|
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
console.log(`Processed ${path.basename(filePath)}: ${qCount} questions. Distribution:`, ansCounts);
|
|
}
|
|
|
|
const files = [
|
|
'questions.json',
|
|
'scripts/data/set-dart-dev.json',
|
|
'scripts/data/set-flutter-basic.json',
|
|
'scripts/data/set-flutter-dev.json'
|
|
];
|
|
|
|
files.forEach(f => processFile(path.join(__dirname, '..', f)));
|