Updated the Writing exercise to have the evaluation in the user solutions instead of the exercise itself
This commit is contained in:
@@ -82,23 +82,23 @@ export default function Page() {
|
||||
}, [selectedModules, setExams, exams]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (selectedModules.length > 0 && exams.length === 0 && moduleIndex >= selectedModules.length && !hasBeenUploaded) {
|
||||
const newStats: Stat[] = userSolutions.map((solution) => ({
|
||||
...solution,
|
||||
session: sessionId,
|
||||
exam: solution.exam!,
|
||||
module: solution.module!,
|
||||
user: user?.id || "",
|
||||
date: new Date().getTime(),
|
||||
}));
|
||||
if (selectedModules.length > 0 && exams.length !== 0 && moduleIndex >= selectedModules.length && !hasBeenUploaded) {
|
||||
const newStats: Stat[] = userSolutions.map((solution) => ({
|
||||
...solution,
|
||||
session: sessionId,
|
||||
exam: solution.exam!,
|
||||
module: solution.module!,
|
||||
user: user?.id || "",
|
||||
date: new Date().getTime(),
|
||||
}));
|
||||
|
||||
axios
|
||||
.post<{ok: boolean}>("/api/stats", newStats)
|
||||
.then((response) => setHasBeenUploaded(response.data.ok))
|
||||
.catch(() => setHasBeenUploaded(false));
|
||||
}
|
||||
})();
|
||||
console.log("GOING TO SAVE");
|
||||
|
||||
axios
|
||||
.post<{ok: boolean}>("/api/stats", newStats)
|
||||
.then((response) => setHasBeenUploaded(response.data.ok))
|
||||
.catch(() => setHasBeenUploaded(false));
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selectedModules, moduleIndex, hasBeenUploaded]);
|
||||
|
||||
@@ -123,21 +123,20 @@ export default function Page() {
|
||||
}
|
||||
};
|
||||
|
||||
const evaluateWritingAnswer = async (examId: string, exerciseId: string, answer: string) => {
|
||||
const evaluateWritingAnswer = async (examId: string, exerciseId: string, solution: UserSolution) => {
|
||||
const writingExam = exams.find((x) => x.id === examId)!;
|
||||
const exercise = writingExam.exercises.find((x) => x.id === exerciseId)! as WritingExercise;
|
||||
|
||||
const response = await axios.post("/api/exam/writing/evaluate", {
|
||||
question: `${exercise.prompt} ${exercise.attachment ? exercise.attachment.description : ""}`.replaceAll("\n", ""),
|
||||
answer: answer.trim().replaceAll("\n", " "),
|
||||
answer: solution.solutions[0].solution.trim().replaceAll("\n", " "),
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
writingExam.exercises = [
|
||||
...writingExam.exercises.filter((x) => x.id !== exerciseId),
|
||||
Object.assign(exercise, {evaluation: response.data}),
|
||||
];
|
||||
setExams([...exams.filter((x) => x.id !== examId), writingExam].sort(sortByModule));
|
||||
setUserSolutions([
|
||||
...userSolutions.filter((x) => x.exercise !== exerciseId),
|
||||
{...solution, solutions: [{id: exerciseId, solution: solution.solutions[0].solution, evaluation: response.data}]},
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -153,13 +152,13 @@ export default function Page() {
|
||||
const solutionIds = solutions.map((x) => x.exercise);
|
||||
|
||||
if (exam && exam.module === "writing" && solutions.length > 0 && !showSolutions) {
|
||||
setHasBeenUploaded(true);
|
||||
setIsEvaluationLoading(true);
|
||||
Promise.all(
|
||||
exam.exercises.map((exercise) =>
|
||||
evaluateWritingAnswer(exam.id, exercise.id, solutions.find((x) => x.exercise === exercise.id)!.solutions[0]),
|
||||
),
|
||||
exam.exercises.map((exercise) => evaluateWritingAnswer(exam.id, exercise.id, solutions.find((x) => x.exercise === exercise.id)!)),
|
||||
).finally(() => {
|
||||
setIsEvaluationLoading(false);
|
||||
setHasBeenUploaded(false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user