Skip to content

Commit

Permalink
Merge pull request #20 from decoded-cipher/dev
Browse files Browse the repository at this point in the history
Version 3.2
  • Loading branch information
decoded-cipher authored Mar 5, 2024
2 parents 8dbb235 + d38ca40 commit 0ae7446
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 337 deletions.
19 changes: 13 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
node_modules
.env

public/screenshots
public/secure_pdfs
public/analytics
public/data
public/xlsx
public/graphs
public/screenshots/**
public/secure_pdfs/**
public/analytics/**
public/data/**
public/xlsx/**
public/graphs/**

# keep the folder structure
!public/screenshots/.gitkeep
!public/secure_pdfs/.gitkeep
!public/analytics/.gitkeep
!public/xlsx/.gitkeep
!public/graphs/.gitkeep
68 changes: 37 additions & 31 deletions helpers/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = {
let subjectPassFailCount = await getSubjectPassFailCount(exam_id, programme);
let subjectToppers = await getAllSubjectToppers(exam_id, programme);


const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Analysis', {
pageSetup: {
Expand Down Expand Up @@ -180,52 +179,59 @@ module.exports = {
// ------------------------------ Subject-wise Toppers Table ------------------------------ //


let extraRows = 0;
data.subjects.length > classTop5.length ? extraRows = data.subjects.length : extraRows = classTop5.length;

worksheet.mergeCells('A' + (15 + data.subjects.length + classTop5.length) + ':M' + (15 + data.subjects.length + classTop5.length));
worksheet.getCell('A' + (15 + data.subjects.length + classTop5.length)).value = 'Subject-wise Toppers List';
extraRows = 9 + extraRows + data.subjects.length + 5;

worksheet.mergeCells('A' + (16 + data.subjects.length + classTop5.length) + ':E' + (16 + data.subjects.length + classTop5.length));
worksheet.getCell('A' + (16 + data.subjects.length + classTop5.length)).value = 'Subjects';
worksheet.mergeCells('A' + extraRows + ':M' + extraRows);
worksheet.getCell('A' + extraRows).value = 'Subject-wise Toppers List';

worksheet.mergeCells('F' + (16 + data.subjects.length + classTop5.length) + ':H' + (16 + data.subjects.length + classTop5.length));
worksheet.getCell('F' + (16 + data.subjects.length + classTop5.length)).value = 'Name of the Student';
extraRows += 1;

worksheet.getCell('I' + (16 + data.subjects.length + classTop5.length)).value = 'Marks';
worksheet.getCell('J' + (16 + data.subjects.length + classTop5.length)).value = 'Grade';
worksheet.mergeCells('A' + extraRows + ':E' + extraRows);
worksheet.getCell('A' + extraRows).value = 'Subjects';

worksheet.mergeCells('K' + (16 + data.subjects.length + classTop5.length) + ':M' + (16 + data.subjects.length + classTop5.length));
worksheet.getCell('K' + (16 + data.subjects.length + classTop5.length)).value = 'Name of the Teacher';
worksheet.mergeCells('F' + extraRows + ':H' + extraRows);
worksheet.getCell('F' + extraRows).value = 'Name of the Student';

let startRow, endRow, extraRows = 0;
worksheet.getCell('I' + extraRows).value = 'Marks';
worksheet.getCell('J' + extraRows).value = 'Grade';

for (let i = 0; i < subjectToppers.length; i++) {
worksheet.mergeCells('K' + extraRows + ':M' + extraRows);
worksheet.getCell('K' + extraRows).value = 'Name of the Teacher';

startRow = 17 + data.subjects.length + classTop5.length + i;
endRow = 17 + data.subjects.length + classTop5.length + i;
extraRows += 1;

let startRow = endRow = extraRows;

startRow = 17 + data.subjects.length + classTop5.length + i + extraRows;
extraRows += subjectToppers[i].count - 1;
endRow = 17 + data.subjects.length + classTop5.length + i + extraRows;

worksheet.mergeCells('A' + (startRow) + ':E' + (endRow));
worksheet.getCell('A' + (startRow)).value = subjectToppers[i].course;
for (let i = 0; i < subjectToppers.length; i++) {

for (let j = 0; j < subjectToppers[i].toppers.length; j++) {
worksheet.mergeCells('F' + (startRow + j) + ':H' + (startRow + j));
worksheet.getCell('F' + (startRow + j)).value = subjectToppers[i].toppers[j].name;

endRow = startRow + j;
// break;
}

worksheet.mergeCells('I' + (startRow) + ':I' + (endRow));
worksheet.getCell('I' + (startRow)).value = subjectToppers[i].marks;

worksheet.mergeCells('J' + (startRow) + ':J' + (endRow));
worksheet.getCell('J' + (startRow)).value = subjectToppers[i].grade;

worksheet.mergeCells('K' + (startRow) + ':M' + (endRow));
worksheet.getCell('K' + (startRow)).value = "Not Available";


worksheet.mergeCells('A' + (startRow) + ':E' + (endRow));
worksheet.getCell('A' + (startRow)).value = subjectToppers[i].course_name;

worksheet.mergeCells('I' + startRow + ':I' + endRow);
worksheet.getCell('I' + startRow).value = subjectToppers[i].total;

worksheet.mergeCells('J' + startRow + ':J' + endRow);
worksheet.getCell('J' + startRow).value = subjectToppers[i].grade;

worksheet.mergeCells('K' + startRow + ':M' + endRow);
worksheet.getCell('K' + startRow).value = "Not Available";

startRow = endRow + 1;
// break;
}



// ------------------------------ Styling ------------------------------ //
Expand Down
70 changes: 53 additions & 17 deletions helpers/cons_sheet_xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,31 @@ module.exports = {
});
}

});
// if any subject was skipped, then highlight the row
for(let i = 0; i < resultStats.subjects.length; i++) {
if(resultStats.subjects[i].skip.index.includes(rowNumber - 6)) {

let cell_1 = String.fromCharCode(67 + (i * 2));
let cell_2 = String.fromCharCode(68 + (i * 2));

row.getCell(cell_1).fill = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FFF0F0F0' },
bgColor: { argb: 'FFF0F0F0' }
}
row.getCell(cell_2).fill = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: 'FFF0F0F0' },
bgColor: { argb: 'FFF0F0F0' }
}

}
}

// save resultStats to a file
// fs.writeFileSync(path.join(__dirname, '../public/xlsx/analytics.json'), JSON.stringify(resultStats, null, 4), (err) => {
// if (err) {
// console.log("--- [xlsx - generate_XLSX] --- Error in writing resultStats to file: " + err);
// reject({
// status: "error",
// message: "Error in writing resultStats to file: ",
// error: err
// });
// }
// });

});


// Write data to XLSX file
Expand Down Expand Up @@ -319,6 +329,8 @@ module.exports = {

let subject = {
marks : [],
isa : [],
esa : [],
grade : [],
};

Expand All @@ -332,6 +344,11 @@ module.exports = {
index : [],
names : [],
},
skip : {
count : 0,
index : [],
names : [],
},
grades: {
"S" : 0,
"A+" : 0,
Expand All @@ -347,7 +364,10 @@ module.exports = {
for(let j = 0; j < data.length; j++) {

let markHolder = data[j].data.result.subjects[i].total;
let isaHolder = data[j].data.result.subjects[i].internal.isa;
let esaHolder = data[j].data.result.subjects[i].external.esa;
let gradeHolder = data[j].data.result.subjects[i].grade;
let maxHolder = data[j].data.result.subjects[i].max;

// Count the subject wise grades
switch(gradeHolder) {
Expand All @@ -373,25 +393,41 @@ module.exports = {
resultStats.subjects[i].grades["D"]++;
break;
default:
resultStats.subjects[i].grades["F"]++;

if(markHolder === null && maxHolder !== null) {
resultStats.subjects[i].grades["F"]++;
}
}

resultStats.subjects[i].name = data[j].data.result.subjects[i].course;

// Count the subject wise pass and fail
if(markHolder === null) {
resultStats.subjects[i].fail.index.push(j);
resultStats.subjects[i].fail.names.push(data[j].data.name);
resultStats.subjects[i].fail.count++;

if(maxHolder === null) {
resultStats.subjects[i].skip.index.push(j);
resultStats.subjects[i].skip.names.push(data[j].data.name);
resultStats.subjects[i].skip.count++;
} else {
resultStats.subjects[i].fail.index.push(j);
resultStats.subjects[i].fail.names.push(data[j].data.name);
resultStats.subjects[i].fail.count++;
}

} else {
resultStats.subjects[i].pass.count++;
}

// Handling null values in the data with "-" and "F"
markHolder === null ? markHolder = "-" : markHolder = markHolder;
gradeHolder === null ? gradeHolder = "F" : gradeHolder = gradeHolder;
isaHolder === null ? isaHolder = "-" : isaHolder = isaHolder;
esaHolder === null ? esaHolder = "-" : esaHolder = esaHolder;

gradeHolder === null ? (maxHolder === null ? gradeHolder = "-" : gradeHolder = "F") : gradeHolder = gradeHolder;

subject.marks.push(markHolder);
subject.isa.push(isaHolder);
subject.esa.push(esaHolder);
subject.grade.push(gradeHolder);

}
Expand Down
Loading

0 comments on commit 0ae7446

Please sign in to comment.