Skip to content

Commit c7ca367

Browse files
committed
fix: malpractice bugs
1 parent d7844cf commit c7ca367

File tree

3 files changed

+246
-63
lines changed

3 files changed

+246
-63
lines changed

src/core/csvValidation.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ export const validateCSV = (data: string): string | true => {
4747
return `Invalid line ${i - 1} attendance`;
4848
// line[7] = should be either empty or "Withheld" | "With held for Malpractice"
4949
if (
50-
line[7] !== "" &&
51-
line[7] !== "Withheld" &&
52-
line[7] !== "With held for Malpractice"
53-
)
50+
[
51+
"",
52+
"Withheld",
53+
"With held for Malpractice",
54+
'"Withheld"',
55+
'"With held for Malpractice"',
56+
].includes(line[7]) === false
57+
) {
5458
return `Invalid line ${i - 1} withheld`;
59+
}
5560
// line[8] = should be a number if line[7] is empty
5661
if (line[7] === "" && isNaN(Number(line[8])))
5762
return `Invalid line ${i - 1} internal mark`;

src/core/main.ts

+38-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum Grade {
1111
S = "S",
1212
}
1313

14-
export type AllGrades = Grade | "Absent" | "Withheld";
14+
export type AllGrades = Grade | "Absent" | "Withheld" | "Malpractice";
1515

1616
export interface ResultType {
1717
registerNo: number;
@@ -21,7 +21,11 @@ export interface ResultType {
2121
course: string;
2222
examType: "Regular" | "Supplementary";
2323
attendance: "Present" | "Absent";
24-
withheld: "Withheld" | "With held for Malpractice" | null;
24+
withheld:
25+
| "Withheld"
26+
| "With held for Malpractice"
27+
| '"With held for Malpractice"'
28+
| null;
2529
iMark: number | null;
2630
grade: Grade | null;
2731
result: "P" | "F" | null;
@@ -37,7 +41,7 @@ interface FormattedType {
3741
grades: {
3842
[key: courseName]: AllGrades | null;
3943
};
40-
withheld: "Withheld" | "With held for Malpractice" | null;
44+
// withheld: "Withheld" | "With held for Malpractice" | null;
4145
}
4246

4347
export const parseCsv = (
@@ -103,17 +107,37 @@ export const formatData = (data: ResultType[]): FormattedType[] => {
103107
: item.attendance === "Absent"
104108
? "Absent"
105109
: item.withheld === "With held for Malpractice"
106-
? Grade.F
110+
? "Malpractice"
111+
: item.withheld === '"With held for Malpractice"'
112+
? "Malpractice"
107113
: item.withheld === "Withheld"
108114
? "Withheld"
109115
: null,
110116
},
111-
withheld: item.withheld,
117+
// withheld:
118+
// item.withheld === "With held for Malpractice"
119+
// ? "With held for Malpractice"
120+
// : item.withheld === '"With held for Malpractice"'
121+
// ? "With held for Malpractice"
122+
// : item.withheld === "Withheld"
123+
// ? "Withheld"
124+
// : null,
112125
});
113126
} else {
114-
formattedData[index].grades[item.course] = item.grade;
127+
formattedData[index].grades[item.course] = item.grade
128+
? item.grade
129+
: item.attendance === "Absent"
130+
? "Absent"
131+
: item.withheld === "With held for Malpractice"
132+
? "Malpractice"
133+
: item.withheld === '"With held for Malpractice"'
134+
? "Malpractice"
135+
: item.withheld === "Withheld"
136+
? "Withheld"
137+
: null;
115138
}
116139
});
140+
117141
return formattedData;
118142
};
119143

@@ -171,7 +195,7 @@ const calculateGradesCountInEachCourse = (data: FormattedType[]) => {
171195
E: 0,
172196
F: 0,
173197
Withheld: 0,
174-
"With held for Malpractice": 0,
198+
Malpractice: 0,
175199
Absent: 0,
176200
};
177201
});
@@ -193,7 +217,7 @@ const calculateGradesCountInEachCourse = (data: FormattedType[]) => {
193217
E: number;
194218
F: number;
195219
Withheld: number;
196-
"With held for Malpractice": number;
220+
Malpractice: number;
197221
Absent: number;
198222
}[] = [];
199223

@@ -349,7 +373,7 @@ const createResultWorksheet = (data: FormattedType[]) => {
349373
xlsx.utils.sheet_add_json(ws, gradeData, {
350374
// skipHeader: false,
351375
origin: {
352-
c: 3, // start from 4th column so later it can be merged
376+
c: 2, // start from 4th column so later it can be merged
353377
r: reFormattedData.length + 7,
354378
},
355379

@@ -363,7 +387,7 @@ const createResultWorksheet = (data: FormattedType[]) => {
363387
"E",
364388
"F",
365389
"Withheld",
366-
"With held for Malpractice",
390+
"Malpractice",
367391
"Absent",
368392
],
369393
});
@@ -434,8 +458,11 @@ const createResultWorksheet = (data: FormattedType[]) => {
434458
if (cell.t === "s" && cell.v === "Withheld") {
435459
cell.s = { ...cell.s, fill: { fgColor: { rgb: "fba7cf" } } };
436460
}
461+
if (cell.t === "s" && cell.v === "Malpractice") {
462+
cell.s = { ...cell.s, fill: { fgColor: { rgb: "d7fc00" } } };
463+
}
437464
// set cell width to minimum text width
438-
if (R == 4) console.log(cell);
465+
// if (R == 4) console.log(cell);
439466
if (cell.t === "s" && [1, 2].includes(C)) {
440467
if (!ws["!cols"]) ws["!cols"] = [];
441468
ws["!cols"][C] = { wch: cell.v.length + 5 };

0 commit comments

Comments
 (0)