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