51 lines
2.3 KiB
JavaScript
51 lines
2.3 KiB
JavaScript
import {students} from "./data.js"
|
|
import {calculateAssignmentAverage} from "./utils.js"
|
|
import {getPassingStudents} from "./analytics.js"
|
|
|
|
const passingStudents = getPassingStudents(students);
|
|
const passingIds = passingStudents.map(student => student.id);
|
|
const tableBody = document.getElementById("studentTableBody");
|
|
|
|
export function renderTable(students, topThree) {
|
|
tableBody.innerHTML = "";
|
|
students.forEach(student => {
|
|
const row = document.createElement("tr");
|
|
|
|
if (topThree[0] && student.id === topThree[0].id) {
|
|
row.classList.add("gold");
|
|
} else if (topThree[1] && student.id === topThree[1].id) {
|
|
row.classList.add("silver");
|
|
} else if (topThree[2] && student.id === topThree[2].id) {
|
|
row.classList.add("bronze");
|
|
}
|
|
|
|
const name = document.createElement("td");
|
|
name.textContent = student.name ?? "-";
|
|
const course = document.createElement("td");
|
|
course.textContent = student.course ?? "-";
|
|
const grade = document.createElement("td");
|
|
grade.textContent = student.grade ?? "-";
|
|
const attendance = document.createElement("td");
|
|
attendance.textContent = student.attendance + "%" ?? "-";
|
|
const assignmentAvg = document.createElement("td");
|
|
assignmentAvg.textContent = calculateAssignmentAverage(...student.assignments);
|
|
const status = document.createElement("td");
|
|
status.textContent = passingIds.includes(student.id) ? "Pass" : "Fail";
|
|
const city = document.createElement("td");
|
|
city.textContent = student.address.city ?? "-";
|
|
row.append(name, course, grade, attendance, assignmentAvg, status, city);
|
|
tableBody.appendChild(row);
|
|
})
|
|
}
|
|
|
|
export function renderSummary(stats, uniqueCourseCount) {
|
|
const summary = document.getElementById("summary");
|
|
summary.innerHTML = "";
|
|
summary.innerHTML += `<h2>Summary</h2>
|
|
<p>Total Students: ${stats.totalStudents}</p>
|
|
<p>Average Grade: ${stats.averageGrade.toFixed(2)}</p>
|
|
<p>Highest Grade: ${stats.highestGrade}</p>
|
|
<p>Lowest Grade: ${stats.lowestGrade}</p>
|
|
<p>Average Attendance: ${stats.averageAttendance.toFixed(2)}%</p>
|
|
<p>Unique Courses: ${uniqueCourseCount}</p>`;
|
|
} |