Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save GlitchCat/6827cd0c80c8a93c360902b48dd67883 to your computer and use it in GitHub Desktop.

Select an option

Save GlitchCat/6827cd0c80c8a93c360902b48dd67883 to your computer and use it in GitHub Desktop.
Calculate your average on Progress (https://progresswww.nl/)
// Quick and dirty script that calculates your average on the results page on Progress
// Simply copy this into your console and a popup should appear with your average
(function(){
function get_average(weighted = false){
const marks = [...document.querySelectorAll("#wrapper > div.prg_sidebarWithContent > div > div.prg_container > div > div.prg_box__content > table > tbody > tr")]
.filter((row) => row.children.length > 1 )
.map((row) => ({
"grade": parseFloat(row.children[4].innerText.replace(",", ".")),
"weight": parseFloat(row.children[5].innerText.replace(",", "."))
}))
// Skip all the grades that do not have a mark, or do not correlate to any ECs
.filter((mark) => !isNaN(mark.grade) && !isNaN(mark.weight));
// The total grade is a combination of all the grades
// If we are calculating the weighted average, each grade is multiplied by the amount of ECs associated with the grade
const totalGrade = marks
.map((mark) => mark.grade * (weighted ? mark.weight : 1))
.reduce((firstMark, secondMark) => firstMark + secondMark, 0);
// The total weight is the amount of grades when we are calculating the unweighted average
// For the weighted average we should add all the ECs together
const totalWeight = marks
.map((mark) => weighted ? mark.weight : 1)
.reduce((firstWeight, secondWeight) => firstWeight + secondWeight, 0);
return Math.round(totalGrade / totalWeight * 100) / 100;
}
alert("Your average: " + get_average() + "\nYour weighted average: " + get_average(true));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment