Commented all related to shuffle

This commit is contained in:
Carlos Mesquita
2024-08-19 16:42:14 +01:00
parent bcb1a0f914
commit 8669ef462d
4 changed files with 71 additions and 61 deletions

View File

@@ -171,7 +171,7 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
const { partIndex, setPartIndex } = useExamStore((state) => state);
const { exerciseIndex, setExerciseIndex } = useExamStore((state) => state);
const [storeQuestionIndex, setStoreQuestionIndex] = useExamStore((state) => [state.questionIndex, state.setQuestionIndex]);
const [shuffleMaps, setShuffleMaps] = useExamStore((state) => [state.shuffleMaps, state.setShuffleMaps])
//const [shuffleMaps, setShuffleMaps] = useExamStore((state) => [state.shuffleMaps, state.setShuffleMaps])
const [currentExercise, setCurrentExercise] = useState<Exercise>();
const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0));
@@ -180,11 +180,11 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
const [contextWord, setContextWord] = useState<string | undefined>(undefined);
const [contextWordLine, setContextWordLine] = useState<number | undefined>(undefined);
useEffect(() => {
/*useEffect(() => {
if (showSolutions && userSolutions[exerciseIndex].shuffleMaps) {
setShuffleMaps(userSolutions[exerciseIndex].shuffleMaps as ShuffleMap[])
}
}, [showSolutions])
}, [showSolutions])*/
useEffect(() => {
if (hasExamEnded && exerciseIndex === -1) {
@@ -214,8 +214,9 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
userSolutions: userSolutions.find((x) => x.exercise === exercise.id)?.solutions || [],
};
if (exam.shuffle && exercise.type === "multipleChoice") {
/*if (exam.shuffle && exercise.type === "multipleChoice") {
if (shuffleMaps.length == 0 && !showSolutions) {
console.log("Shuffling answers");
const newShuffleMaps: ShuffleMap[] = [];
exercise.questions = exercise.questions.map(question => {
@@ -242,6 +243,7 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
setShuffleMaps(newShuffleMaps);
} else {
console.log("Retrieving shuffles");
exercise.questions = exercise.questions.map(question => {
const questionShuffleMap = shuffleMaps.find(map => map.id === question.id);
if (questionShuffleMap) {
@@ -261,20 +263,21 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
exercise.words = exercise.words.map(word => {
if ('options' in word) {
const options = { ...word.options };
const shuffledKeys = Object.keys(options).sort(() => Math.random() - 0.5);
const originalKeys = Object.keys(options);
const shuffledKeys = [...originalKeys].sort(() => Math.random() - 0.5);
const newOptions = shuffledKeys.reduce((acc, key, index) => {
acc[key as keyof typeof options] = options[shuffledKeys[index] as keyof typeof options];
acc[key as keyof typeof options] = options[originalKeys[index] as keyof typeof options];
return acc;
}, {} as { [key in keyof typeof options]: string });
const optionMapping = shuffledKeys.reduce((acc, key, index) => {
acc[key as keyof typeof options] = Object.keys(options)[index] as keyof typeof options;
const optionMapping = originalKeys.reduce((acc, key, index) => {
acc[key as keyof typeof options] = shuffledKeys[index];
return acc;
}, {} as { [key in keyof typeof options]: string });
newShuffleMaps.push({ id: word.id, map: optionMapping });
return { ...word, options: newOptions };
}
return word;
@@ -283,20 +286,17 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
setShuffleMaps(newShuffleMaps);
}
}
*/
return exercise;
};
useEffect(() => {
const newExercise = getExercise();
setCurrentExercise(newExercise);
//console.log("Getting another exercise");
//setShuffleMaps([]);
setCurrentExercise(getExercise());
}, [partIndex, exerciseIndex]);
//useShuffledMultipleChoiceOptions(currentExercise, exam.shuffle, storeQuestionIndex, shuffleMaps, setShuffleMaps, setCurrentExercise);
//useShuffledFillBlanksOptions(currentExercise, exam.shuffle, storeQuestionIndex, shuffleMaps, setShuffleMaps, setCurrentExercise);
useEffect(() => {
const regex = /.*?['"](.*?)['"] in line (\d+)\?$/;
if (currentExercise && currentExercise.type === "multipleChoice") {
@@ -321,7 +321,7 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
setContextWord(undefined);
}
}
}, [storeQuestionIndex, contextWordLine, exerciseIndex, partIndex, shuffleMaps]);
}, [storeQuestionIndex, contextWordLine, exerciseIndex, partIndex]); //, shuffleMaps]);
const nextExercise = (solution?: UserSolution) => {
scrollToTop();
@@ -362,9 +362,9 @@ export default function Level({ exam, showSolutions = false, onFinish, editing =
if (solution) {
let stat = { ...solution, module: "level" as Module, exam: exam.id }
if (exam.shuffle) {
/*if (exam.shuffle) {
stat.shuffleMaps = shuffleMaps
}
}*/
onFinish([...userSolutions.filter((x) => x.exercise !== solution.exercise), { ...stat }]);
} else {
onFinish(userSolutions);