Added level to table
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
} from "@react-pdf/renderer";
|
||||
import { styles } from "./styles";
|
||||
import TestReportFooter from "./test.report.footer";
|
||||
import { ModuleScore } from "@/interfaces/module.scores";
|
||||
import { ModuleScore, StudentData } from "@/interfaces/module.scores";
|
||||
import ProgressBar from "./progress.bar";
|
||||
|
||||
Font.registerHyphenationCallback((word) => [word]);
|
||||
@@ -30,7 +30,8 @@ interface Props {
|
||||
title: string;
|
||||
numberOfStudents: number;
|
||||
institution: string;
|
||||
studentsData: any[];
|
||||
studentsData: StudentData[];
|
||||
showLevel: boolean;
|
||||
}
|
||||
|
||||
const customStyles = StyleSheet.create({
|
||||
@@ -78,6 +79,7 @@ const GroupTestReport = ({
|
||||
numberOfStudents,
|
||||
institution,
|
||||
studentsData,
|
||||
showLevel,
|
||||
}: Props) => {
|
||||
const defaultTextStyle = [styles.textFont, { fontSize: 8 }];
|
||||
const defaultSkillsTextStyle = [styles.textFont, { fontSize: 8 }];
|
||||
@@ -213,12 +215,20 @@ const GroupTestReport = ({
|
||||
customStyles.tableCellHighlight,
|
||||
]}
|
||||
>
|
||||
<Text style={customStyles.tableCell}>Sr</Text>
|
||||
<Text style={[customStyles.tableCell, { maxWidth: "24px" }]}>
|
||||
Sr
|
||||
</Text>
|
||||
<Text style={customStyles.tableCell}>Candidate Name</Text>
|
||||
<Text style={customStyles.tableCell}>Email ID</Text>
|
||||
<Text style={customStyles.tableCell}>Gender</Text>
|
||||
<Text style={customStyles.tableCell}>Date of test</Text>
|
||||
<Text style={customStyles.tableCell}>Result</Text>
|
||||
<Text style={[customStyles.tableCell, { maxWidth: "48px" }]}>
|
||||
Gender
|
||||
</Text>
|
||||
<Text style={[customStyles.tableCell, { maxWidth: "64px" }]}>
|
||||
Date of test
|
||||
</Text>
|
||||
<Text style={[customStyles.tableCell, { maxWidth: "48px" }]}>
|
||||
Result
|
||||
</Text>
|
||||
<Text style={customStyles.tableCell}>Level</Text>
|
||||
</View>
|
||||
{studentsData.map(
|
||||
@@ -228,15 +238,22 @@ const GroupTestReport = ({
|
||||
style={[
|
||||
customStyles.tableCell,
|
||||
customStyles.tableCellHighlight,
|
||||
{ maxWidth: "24px" },
|
||||
]}
|
||||
>
|
||||
{index + 1}
|
||||
</Text>
|
||||
<Text style={customStyles.tableCell}>{name}</Text>
|
||||
<Text style={customStyles.tableCell}>{email}</Text>
|
||||
<Text style={customStyles.tableCell}>{gender}</Text>
|
||||
<Text style={customStyles.tableCell}>{date}</Text>
|
||||
<Text style={customStyles.tableCell}>{result}</Text>
|
||||
<Text style={[customStyles.tableCell, { maxWidth: "48px" }]}>
|
||||
{gender}
|
||||
</Text>
|
||||
<Text style={[customStyles.tableCell, { maxWidth: "64px" }]}>
|
||||
{date}
|
||||
</Text>
|
||||
<Text style={[customStyles.tableCell, { maxWidth: "48px" }]}>
|
||||
{result}
|
||||
</Text>
|
||||
<Text style={customStyles.tableCell}>{level}</Text>
|
||||
</View>
|
||||
)
|
||||
|
||||
@@ -9,3 +9,13 @@ export interface ModuleScore {
|
||||
evaluation?: string,
|
||||
suggestions?: string,
|
||||
}
|
||||
|
||||
export interface StudentData {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
gender: string;
|
||||
date: string;
|
||||
result: string;
|
||||
level?: string;
|
||||
}
|
||||
@@ -19,11 +19,11 @@ import { ref, uploadBytes } from "firebase/storage";
|
||||
import { Stat } from "@/interfaces/user";
|
||||
import { User } from "@/interfaces/user";
|
||||
import { Module } from "@/interfaces";
|
||||
import { ModuleScore } from "@/interfaces/module.scores";
|
||||
import { ModuleScore, StudentData } from "@/interfaces/module.scores";
|
||||
import qrcode from "qrcode";
|
||||
import { SkillExamDetails } from "@/exams/pdf/details/skill.exam";
|
||||
import { LevelExamDetails } from "@/exams/pdf/details/level.exam";
|
||||
import { calculateBandScore } from "@/utils/score";
|
||||
import { calculateBandScore, getLevelScore } from "@/utils/score";
|
||||
import axios from "axios";
|
||||
import { moduleLabels } from "@/utils/moduleUtils";
|
||||
import {
|
||||
@@ -99,6 +99,17 @@ const getScoreAndTotal = (stats: Stat[]) => {
|
||||
);
|
||||
};
|
||||
|
||||
const getLevelScoreForUserExams = (
|
||||
correct: number,
|
||||
total: number,
|
||||
module: Module,
|
||||
focus: "academic" | "general"
|
||||
) => {
|
||||
const bandScore = calculateBandScore(correct, total, module, focus);
|
||||
const [level] = getLevelScore(bandScore);
|
||||
return level;
|
||||
};
|
||||
|
||||
async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// verify if it's a logged user that is trying to export
|
||||
if (req.session.user) {
|
||||
@@ -189,9 +200,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
overallResult
|
||||
);
|
||||
|
||||
const showLevel = baseStat.module === "level";
|
||||
|
||||
// level exams have a different report structure than the skill exams
|
||||
const getCustomData = () => {
|
||||
if (baseStat.module === "level") {
|
||||
if (showLevel) {
|
||||
return {
|
||||
title: "GROUP ENGLISH LEVEL TEST RESULT REPORT ",
|
||||
details: <LevelExamDetails detail={overallDetail} />,
|
||||
@@ -208,7 +221,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const numberOfStudents = data.assignees.length;
|
||||
|
||||
const getStudentsData = async () => {
|
||||
const getStudentsData = async (): Promise<StudentData[]> => {
|
||||
// const usersCol = collection(db, "users");
|
||||
const docsSnap = await getDocs(
|
||||
query(
|
||||
@@ -232,10 +245,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
});
|
||||
const result =
|
||||
exams.length === 0
|
||||
? "N/A"
|
||||
: `${exams[0].score.correct}/${exams[0].score.total}`;
|
||||
|
||||
const { correct, total } = getScoreAndTotal(exams);
|
||||
|
||||
const result = exams.length === 0 ? "N/A" : `${correct}/${total}`;
|
||||
|
||||
return {
|
||||
id,
|
||||
@@ -244,6 +257,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
gender: user?.demographicInformation?.gender || "N/A",
|
||||
date,
|
||||
result,
|
||||
level: showLevel
|
||||
? getLevelScoreForUserExams(
|
||||
correct,
|
||||
total,
|
||||
baseStat.module,
|
||||
user?.focus || "academic"
|
||||
)
|
||||
: "",
|
||||
};
|
||||
});
|
||||
};
|
||||
@@ -266,6 +287,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
numberOfStudents={numberOfStudents}
|
||||
institution="TODO: PLACEHOLDER"
|
||||
studentsData={studentsData}
|
||||
showLevel={showLevel}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -290,6 +312,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
res.status(401).json({ ok: false });
|
||||
return;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ ok: false });
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user