Unfinished grading attempt at solving it
This commit is contained in:
@@ -22,7 +22,6 @@ import ShortUniqueId from "short-unique-id";
|
||||
import { ExamProps } from "@/exams/types";
|
||||
import useExamStore from "@/stores/exam";
|
||||
import useEvaluationPolling from "@/hooks/useEvaluationPolling";
|
||||
import PracticeModal from "@/components/PracticeModal";
|
||||
|
||||
interface Props {
|
||||
page: "exams" | "exercises";
|
||||
@@ -37,6 +36,7 @@ export default function ExamPage({ page, user, destination = "/", hideSidebar =
|
||||
const [avoidRepeated, setAvoidRepeated] = useState(false);
|
||||
const [showAbandonPopup, setShowAbandonPopup] = useState(false);
|
||||
const [pendingExercises, setPendingExercises] = useState<string[]>([]);
|
||||
const [shouldPoll, setShouldPoll] = useState(false);
|
||||
|
||||
const {
|
||||
exam, setExam,
|
||||
@@ -60,7 +60,6 @@ export default function ExamPage({ page, user, destination = "/", hideSidebar =
|
||||
setFlags,
|
||||
setShuffles,
|
||||
evaluated,
|
||||
setEvaluated,
|
||||
} = useExamStore();
|
||||
|
||||
const [isFetchingExams, setIsFetchingExams] = useState(false);
|
||||
@@ -150,8 +149,10 @@ export default function ExamPage({ page, user, destination = "/", hideSidebar =
|
||||
useEffect(() => {
|
||||
if (flags.finalizeExam && moduleIndex !== -1) {
|
||||
setModuleIndex(-1);
|
||||
|
||||
|
||||
}
|
||||
}, [flags, moduleIndex, setModuleIndex]);
|
||||
}, [flags.finalizeExam, moduleIndex, setModuleIndex]);
|
||||
|
||||
useEffect(() => {
|
||||
if (flags.finalizeExam && !flags.pendingEvaluation && pendingExercises.length === 0) {
|
||||
|
||||
@@ -6,7 +6,9 @@ import axios from "axios";
|
||||
import formidable from "formidable-serverless";
|
||||
import fs from "fs";
|
||||
import FormData from 'form-data';
|
||||
import client from "@/lib/mongodb";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
@@ -66,6 +68,34 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there is one eval for the current exercise
|
||||
const previousEval = await db.collection("evaluation").findOne({
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
})
|
||||
|
||||
// If there is delete it
|
||||
if (previousEval) {
|
||||
await db.collection("evaluation").deleteOne({
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
})
|
||||
}
|
||||
|
||||
// Insert the new eval for the backend to place it's result
|
||||
await db.collection("evaluation").insertOne(
|
||||
{
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
type: "speaking_interactive",
|
||||
task: fields.task,
|
||||
status: "pending"
|
||||
}
|
||||
);
|
||||
|
||||
await axios.post(
|
||||
`${process.env.BACKEND_URL}/grade/speaking/${fields.task}`,
|
||||
formData,
|
||||
|
||||
@@ -6,6 +6,9 @@ import axios from "axios";
|
||||
import formidable from "formidable-serverless";
|
||||
import fs from "fs";
|
||||
import FormData from 'form-data';
|
||||
import client from "@/lib/mongodb";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
@@ -41,6 +44,34 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
formData.append('audio_1', buffer, 'audio_1.wav');
|
||||
fs.rmSync(audioFile.path);
|
||||
|
||||
// Check if there is one eval for the current exercise
|
||||
const previousEval = await db.collection("evaluation").findOne({
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
})
|
||||
|
||||
// If there is delete it
|
||||
if (previousEval) {
|
||||
await db.collection("evaluation").deleteOne({
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
})
|
||||
}
|
||||
|
||||
// Insert the new eval for the backend to place it's result
|
||||
await db.collection("evaluation").insertOne(
|
||||
{
|
||||
user: fields.userId,
|
||||
session_id: fields.sessionId,
|
||||
exercise_id: fields.exerciseId,
|
||||
type: "speaking",
|
||||
task: 2,
|
||||
status: "pending"
|
||||
}
|
||||
);
|
||||
|
||||
await axios.post(
|
||||
`${process.env.BACKEND_URL}/grade/speaking/2`,
|
||||
formData,
|
||||
|
||||
@@ -17,18 +17,13 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {sessionId, userId, exerciseIds} = req.query;
|
||||
const exercises = (exerciseIds! as string).split(',');
|
||||
const finishedEvaluations = await db.collection("evaluation").find({
|
||||
const { sessionId, userId } = req.query;
|
||||
|
||||
const singleEval = await db.collection("evaluation").findOne({
|
||||
session_id: sessionId,
|
||||
user: userId,
|
||||
$or: [
|
||||
{ status: "completed" },
|
||||
{ status: "error" }
|
||||
],
|
||||
exercise_id: { $in: exercises }
|
||||
}).toArray();
|
||||
status: "pending",
|
||||
});
|
||||
|
||||
const finishedExerciseIds = finishedEvaluations.map(evaluation => evaluation.exercise_id);
|
||||
res.status(200).json({ finishedExerciseIds });
|
||||
res.status(200).json({ hasPendingEvaluation: singleEval !== null});
|
||||
}
|
||||
@@ -3,6 +3,9 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import axios from "axios";
|
||||
import client from "@/lib/mongodb";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
interface Body {
|
||||
userId: string;
|
||||
@@ -22,8 +25,36 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { task, ...body} = req.body as Body;
|
||||
const taskNumber = task.toString() !== "1" && task.toString() !== "2" ? "1" : task.toString();
|
||||
const body = req.body as Body;
|
||||
const taskNumber = body.task.toString() !== "1" && body.task.toString() !== "2" ? "1" : body.task.toString();
|
||||
|
||||
// Check if there is one eval for the current exercise
|
||||
const previousEval = await db.collection("evaluation").findOne({
|
||||
user: body.userId,
|
||||
session_id: body.sessionId,
|
||||
exercise_id: body.exerciseId,
|
||||
})
|
||||
|
||||
// If there is delete it
|
||||
if (previousEval) {
|
||||
await db.collection("evaluation").deleteOne({
|
||||
user: body.userId,
|
||||
session_id: body.sessionId,
|
||||
exercise_id: body.exerciseId,
|
||||
})
|
||||
}
|
||||
|
||||
// Insert the new eval for the backend to place it's result
|
||||
await db.collection("evaluation").insertOne(
|
||||
{
|
||||
user: body.userId,
|
||||
session_id: body.sessionId,
|
||||
exercise_id: body.exerciseId,
|
||||
type: "writing",
|
||||
task: body.task,
|
||||
status: "pending"
|
||||
}
|
||||
);
|
||||
|
||||
await axios.post(`${process.env.BACKEND_URL}/grade/writing/${taskNumber}`, body, {
|
||||
headers: {
|
||||
|
||||
42
src/pages/api/stats/updateDisabled.ts
Normal file
42
src/pages/api/stats/updateDisabled.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import client from "@/lib/mongodb";
|
||||
import { withIronSessionApiRoute } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { Stat } from "@/interfaces/user";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { UserSolution } from "@/interfaces/exam";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === "POST") return post(req, res);
|
||||
}
|
||||
|
||||
interface Body {
|
||||
solutions: UserSolution[];
|
||||
sessionID: string;
|
||||
}
|
||||
|
||||
async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const user = await requestUser(req, res)
|
||||
if (!user) return res.status(401).json({ ok: false });
|
||||
|
||||
const { solutions, sessionID } = req.body as Body;
|
||||
|
||||
const disabledStats = await db.collection("stats").find({ user: user.id, session: sessionID, disabled: true }).toArray();
|
||||
|
||||
await Promise.all(disabledStats.map(async (stat) => {
|
||||
const matchingSolution = solutions.find(s => s.exercise === stat.exercise);
|
||||
if (matchingSolution) {
|
||||
await db.collection("stats").updateOne(
|
||||
{ id: stat.id },
|
||||
{ $set: { ...matchingSolution } }
|
||||
);
|
||||
}
|
||||
}));
|
||||
|
||||
return res.status(200).json({ ok: true });
|
||||
}
|
||||
Reference in New Issue
Block a user