Skip to content

Commit ac0cfa7

Browse files
committed
bug: mapping nd mcq total
1 parent dc3c6a7 commit ac0cfa7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

frontend/src/pages/responses.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ export default function AdminResponses() {
2121
const [loading, setLoading] = useState(true);
2222
const normalize = (v) => String(v ?? "").trim();
2323

24+
const countAppearedMcqs = (user, mcqQuestions) => {
25+
const answers = round === 1 ? user.round1 || [] : user.round2 || [];
26+
const mcqIds = new Set(
27+
mcqQuestions.map(q => String(q.id || q.uuid))
28+
);
29+
30+
// count only answers whose questionId belongs to MCQs
31+
return answers.filter(a => mcqIds.has(String(a.questionId))).length;
32+
};
33+
2434

2535
const fetchQuestions = async () => {
2636
const res = await api.get("/admin/questions", {
@@ -80,13 +90,15 @@ export default function AdminResponses() {
8090
const { mcq, desc } = await fetchQuestions();
8191

8292
const computed = raw.map((user) => {
93+
const appearedMcqs = countAppearedMcqs(user, mcq);
8394
const answersMap = extractAnswers(user);
8495
return {
8596
...user,
8697
answersMap,
8798
score: calculateScore(answersMap, mcq),
8899
mcqQuestions: mcq,
89-
descQuestions: desc
100+
descQuestions: desc,
101+
appearedMcqs
90102
};
91103
});
92104

@@ -150,7 +162,7 @@ export default function AdminResponses() {
150162
<option value="EVENTS">EVENTS</option>
151163
<option value="PNM">PNM</option>
152164
<option value="UI/UX">UI/UX</option>
153-
<option value="VIDEO">Video Editing</option>
165+
<option value="VIDEO EDITING">Video Editing</option>
154166
</select>
155167

156168
<select className="p-3 rounded-xl bg-black border border-neutral-700" value={round} onChange={(e) => setRound(Number(e.target.value))}>
@@ -193,7 +205,7 @@ export default function AdminResponses() {
193205
<summary className="cursor-pointer flex flex-col sm:flex-row justify-between gap-4 p-4 sm:p-6">
194206
<div>
195207
<p className="break-all font-semibold text-lg">{user.email}</p>
196-
<p className="text-yellow-400 text-sm">Score: {user.score}</p>
208+
<p className="text-yellow-400 text-sm">Score: {user.score} / {user.appearedMcqs}</p>
197209
</div>
198210
<div className="flex gap-3" onClick={(e) => e.stopPropagation()}>
199211
<button onClick={() => markUser(user.email, "qualified")} className="bg-green-600 px-4 py-2 rounded-xl text-sm font-semibold">

0 commit comments

Comments
 (0)