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
|
<div
|
||||||
className={clsx(
|
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,
|
className,
|
||||||
)}>
|
)}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {Module} from "@/interfaces";
|
|||||||
|
|
||||||
import Selection from "@/exams/Selection";
|
import Selection from "@/exams/Selection";
|
||||||
import Reading from "@/exams/Reading";
|
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 Listening from "@/exams/Listening";
|
||||||
import Writing from "@/exams/Writing";
|
import Writing from "@/exams/Writing";
|
||||||
import {ToastContainer, toast} from "react-toastify";
|
import {ToastContainer, toast} from "react-toastify";
|
||||||
@@ -134,12 +134,15 @@ export default function ExamPage({page}: Props) {
|
|||||||
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
exam.exercises.map(async (exercise) => {
|
exam.exercises.map(async (exercise) => {
|
||||||
return (exam.module === "writing" ? evaluateWritingAnswer : evaluateSpeakingAnswer)(
|
if (exercise.type === "writing")
|
||||||
exams,
|
return evaluateWritingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!).then((response) => {
|
||||||
exam.id,
|
if (response) {
|
||||||
exercise.id,
|
setUserSolutions([...userSolutions.filter((x) => x.exercise !== exercise.id), response]);
|
||||||
solutions.find((x) => x.exercise === exercise.id)!,
|
}
|
||||||
).then((response) => {
|
});
|
||||||
|
|
||||||
|
if (exercise.type === "interactiveSpeaking" || exercise.type === "speaking")
|
||||||
|
return evaluateSpeakingAnswer(exercise, solutions.find((x) => x.exercise === exercise.id)!).then((response) => {
|
||||||
if (response) {
|
if (response) {
|
||||||
setUserSolutions([...userSolutions.filter((x) => x.exercise !== exercise.id), 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 axios from "axios";
|
||||||
import {speakingReverseMarking, writingReverseMarking} from "./score";
|
import {speakingReverseMarking, writingReverseMarking} from "./score";
|
||||||
|
|
||||||
export const evaluateWritingAnswer = async (exams: Exam[], examId: string, exerciseId: string, solution: UserSolution) => {
|
export const evaluateWritingAnswer = async (exercise: WritingExercise, solution: UserSolution) => {
|
||||||
const writingExam = exams.find((x) => x.id === examId)! as WritingExam;
|
|
||||||
const exercise = writingExam.exercises.find((x) => x.id === exerciseId)! as WritingExercise;
|
|
||||||
|
|
||||||
const response = await axios.post<Evaluation>("/api/evaluate/writing", {
|
const response = await axios.post<Evaluation>("/api/evaluate/writing", {
|
||||||
question: `${exercise.prompt} ${exercise.attachment ? exercise.attachment.description : ""}`.replaceAll("\n", ""),
|
question: `${exercise.prompt} ${exercise.attachment ? exercise.attachment.description : ""}`.replaceAll("\n", ""),
|
||||||
answer: solution.solutions[0].solution.trim().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,
|
missing: 0,
|
||||||
total: 100,
|
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;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const evaluateSpeakingAnswer = async (exams: Exam[], examId: string, exerciseId: string, solution: UserSolution) => {
|
export const evaluateSpeakingAnswer = async (exercise: SpeakingExercise | InteractiveSpeakingExercise, solution: UserSolution) => {
|
||||||
const speakingExam = exams.find((x) => x.id === examId)! as SpeakingExam;
|
|
||||||
const exercise = speakingExam.exercises.find((x) => x.id === exerciseId);
|
|
||||||
|
|
||||||
switch (exercise?.type) {
|
switch (exercise?.type) {
|
||||||
case "speaking":
|
case "speaking":
|
||||||
return await evaluateSpeakingExercise(exercise, exerciseId, solution);
|
return await evaluateSpeakingExercise(exercise, exercise.id, solution);
|
||||||
case "interactiveSpeaking":
|
case "interactiveSpeaking":
|
||||||
return await evaluateInteractiveSpeakingExercise(exerciseId, solution);
|
return await evaluateInteractiveSpeakingExercise(exercise.id, solution);
|
||||||
default:
|
default:
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user