Improved a bit of the evaluation system
This commit is contained in:
@@ -37,7 +37,7 @@ export default function Layout({user, children, className, navDisabled = false,
|
||||
/>
|
||||
<div
|
||||
className={clsx(
|
||||
"w-full min-h-full h-fit md:mr-8 bg-white shadow-md rounded-2xl p-4 xl:p-12 pb-8 flex flex-col gap-8 md:gap-12 relative overflow-hidden mt-2",
|
||||
"w-full min-h-full h-fit md:mr-8 bg-white shadow-md rounded-2xl p-4 xl:p-10 pb-8 flex flex-col gap-8 md:gap-12 relative overflow-hidden mt-2",
|
||||
className,
|
||||
)}>
|
||||
{children}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {Module} from "@/interfaces";
|
||||
|
||||
import Selection from "@/exams/Selection";
|
||||
import Reading from "@/exams/Reading";
|
||||
import {Exam, UserSolution} from "@/interfaces/exam";
|
||||
import {Exam, InteractiveSpeakingExercise, SpeakingExercise, UserSolution, WritingExercise} from "@/interfaces/exam";
|
||||
import Listening from "@/exams/Listening";
|
||||
import Writing from "@/exams/Writing";
|
||||
import {ToastContainer, toast} from "react-toastify";
|
||||
@@ -134,12 +134,15 @@ export default function ExamPage({page}: Props) {
|
||||
|
||||
Promise.all(
|
||||
exam.exercises.map(async (exercise) => {
|
||||
return (exam.module === "writing" ? evaluateWritingAnswer : evaluateSpeakingAnswer)(
|
||||
exams,
|
||||
exam.id,
|
||||
exercise.id,
|
||||
solutions.find((x) => x.exercise === exercise.id)!,
|
||||
).then((response) => {
|
||||
if (exercise.type === "writing")
|
||||
return evaluateWritingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!).then((response) => {
|
||||
if (response) {
|
||||
setUserSolutions([...userSolutions.filter((x) => x.exercise !== exercise.id), response]);
|
||||
}
|
||||
});
|
||||
|
||||
if (exercise.type === "interactiveSpeaking" || exercise.type === "speaking")
|
||||
return evaluateSpeakingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!).then((response) => {
|
||||
if (response) {
|
||||
setUserSolutions([...userSolutions.filter((x) => x.exercise !== exercise.id), response]);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import {Evaluation, Exam, SpeakingExam, SpeakingExercise, UserSolution, WritingExam, WritingExercise} from "@/interfaces/exam";
|
||||
import {
|
||||
Evaluation,
|
||||
Exam,
|
||||
InteractiveSpeakingExercise,
|
||||
SpeakingExam,
|
||||
SpeakingExercise,
|
||||
UserSolution,
|
||||
WritingExam,
|
||||
WritingExercise,
|
||||
} from "@/interfaces/exam";
|
||||
import axios from "axios";
|
||||
import {speakingReverseMarking, writingReverseMarking} from "./score";
|
||||
|
||||
export const evaluateWritingAnswer = async (exams: Exam[], examId: string, exerciseId: string, solution: UserSolution) => {
|
||||
const writingExam = exams.find((x) => x.id === examId)! as WritingExam;
|
||||
const exercise = writingExam.exercises.find((x) => x.id === exerciseId)! as WritingExercise;
|
||||
|
||||
export const evaluateWritingAnswer = async (exercise: WritingExercise, solution: UserSolution) => {
|
||||
const response = await axios.post<Evaluation>("/api/evaluate/writing", {
|
||||
question: `${exercise.prompt} ${exercise.attachment ? exercise.attachment.description : ""}`.replaceAll("\n", ""),
|
||||
answer: solution.solutions[0].solution.trim().replaceAll("\n", " "),
|
||||
@@ -19,22 +25,19 @@ export const evaluateWritingAnswer = async (exams: Exam[], examId: string, exerc
|
||||
missing: 0,
|
||||
total: 100,
|
||||
},
|
||||
solutions: [{id: exerciseId, solution: solution.solutions[0].solution, evaluation: response.data}],
|
||||
solutions: [{id: exercise.id, solution: solution.solutions[0].solution, evaluation: response.data}],
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const evaluateSpeakingAnswer = async (exams: Exam[], examId: string, exerciseId: string, solution: UserSolution) => {
|
||||
const speakingExam = exams.find((x) => x.id === examId)! as SpeakingExam;
|
||||
const exercise = speakingExam.exercises.find((x) => x.id === exerciseId);
|
||||
|
||||
export const evaluateSpeakingAnswer = async (exercise: SpeakingExercise | InteractiveSpeakingExercise, solution: UserSolution) => {
|
||||
switch (exercise?.type) {
|
||||
case "speaking":
|
||||
return await evaluateSpeakingExercise(exercise, exerciseId, solution);
|
||||
return await evaluateSpeakingExercise(exercise, exercise.id, solution);
|
||||
case "interactiveSpeaking":
|
||||
return await evaluateInteractiveSpeakingExercise(exerciseId, solution);
|
||||
return await evaluateInteractiveSpeakingExercise(exercise.id, solution);
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user