Last active
June 7, 2018 17:00
-
-
Save Seth-Johnson/4c8b20cfcd08f992b33e2b39c8bbf539 to your computer and use it in GitHub Desktop.
Calculates the average class grade based on the mean of each individual assignment. WIP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Canvas average class grade | |
// @namespace sethj@ubuntu.com | |
// @version 0.1a | |
// @description Calculate class average grade | |
// @author Seth Johnson | |
// @match https://egator.greenriver.edu/courses/*/grades | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// We're storing the rubric here in a category:decimal_percentage dictionary. | |
var rubric = {}; | |
var mean_grades = {}; | |
var weighted_grades = [] | |
// grab the rubric from the page. Convert the percentages into decimals for later. We'll also replace any strings in the category names with underscores. | |
$('.summary').find('tbody > tr').each(function() { | |
var category = $(this).find('th').text().replace(' ', '_'); | |
mean_grades[category] = []; | |
rubric[category] = (parseInt($(this).find('td').text()) * .01) | |
}) | |
//DEBUG console.log(mean_grades); | |
//DEBUG console.log(rubric); | |
$('.grade_details').each(function() { | |
//DEBUG console.log($(this)); | |
var category = $(this).prev().prev().find('.context').text().replace(' ', '_'); | |
//DEBUG console.log(category); | |
var meanPoints = $(this).find('tbody').find('td').filter(':first').text().split(':')[1]; | |
var totalPoints = $(this).prev().prev().find('.points_possible').text(); | |
//console.log("Total is: " + totalPoints); | |
if (typeof meanPoints != "undefined" && meanPoints != NaN) { | |
meanPoints = parseFloat(meanPoints.replace(/,/g, '')); | |
totalPoints = parseFloat(totalPoints.replace(/,/g, '')); | |
var meanGrade = ((meanPoints / totalPoints) * 100).toPrecision(4); | |
//DEBUGconsole.log("Mean is: " + meanGrade); | |
mean_grades[category].push(meanGrade) | |
} else { | |
return; | |
} | |
//DEBUG console.log(mean_grades); | |
//console.log(meanGrade); //DEBUG | |
//console.log(typeof(meanGrade)); //DEBUG | |
}) | |
for (var category_i in mean_grades) { | |
var category = mean_grades[category_i]; | |
//console.log("Category is: " + category_i); | |
//console.log("Data is: ");console.log(category); //DEBUG | |
for (var grade_i in category) { | |
var grade = mean_grades[category_i][grade_i]; | |
var adjusted_grade = (grade * rubric[category_i]).toPrecision(4); | |
weighted_grades.push(parseFloat(adjusted_grade)); | |
//console.log("Grade is: " + grade); | |
//console.log("Adjusted is: " + adjusted_grade); | |
} | |
} | |
console.log(weighted_grades); | |
const reducer = (accumulator, currVal) => accumulator + currVal; | |
console.log(weighted_grades.reduce(reducer).toFixed(2)); | |
console.log(typeof(weighted_grades.reduce(reducer))); | |
console.log(weighted_grades.length); | |
var class_average = weighted_grades.reduce(reducer) / weighted_grades.length; | |
console.log(class_average); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment