Skip to content

Instantly share code, notes, and snippets.

@twobiers
Last active June 7, 2023 12:40
Show Gist options
  • Save twobiers/d9c70cf398fba0fa050410f7b62f9ce1 to your computer and use it in GitHub Desktop.
Save twobiers/d9c70cf398fba0fa050410f7b62f9ce1 to your computer and use it in GitHub Desktop.
Get GPA from Academic records in HIS (Hochschul-Informations-System)
const parseCell = (cell) => Number(cell.textContent.trim().replace(",", "."));
const grades = Array.from(document.querySelectorAll(".content > table")[1].querySelectorAll("tr"))
.filter((tr) => tr.querySelector(".tabelle1_aligncenter")) // No "Groups"
.filter((tr) => parseCell(tr.children[5]) > 0) // Only rows where a grade is available
.filter((tr) => tr.children[6].textContent.trim() === "BE") // Only passed exams
.reduce((acc, curr) => {
acc.grades.push(parseCell(curr.children[5]));
acc.ects.push(parseCell(curr.children[7]));
return acc;
}, { grades: [], ects: [] });
if(grades.grades.length !== grades.ects.length) throw new Error("Couldn't parse grades/ects");
const ectsSum = grades.ects.reduce((acc, curr) => acc + curr, 0);
const gradeSum = grades.grades.reduce((acc, curr, idx) => acc + (curr * grades.ects[idx]), 0);
const gpa = ectsSum === 0 ? 0.0 : gradeSum / ectsSum;
console.log(`%c GPA: ${gpa} ECTS: ${ectsSum}`, 'background: #222; color: #bada55');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment