Created
April 26, 2021 23:33
-
-
Save samarthdave/696556f24067b00c992d5aedbd492679 to your computer and use it in GitHub Desktop.
Canvas Grades Script
This file contains hidden or 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
// in general, don't just copy and paste scripts from the internet | |
// but this one is pretty useful if I do say so myself; you can trust it ;) | |
// USAGE: | |
// Canvas > CSCE 430 > Grades > Open Inspector/DevTools > Paste into Console | |
var TABLE_SELECTOR = '.student_assignment.assignment_graded.editable'; | |
var NUM_PSETS = 14; | |
var NUM_LABS_ = 14; | |
function ReadTable() { | |
var table_rows = $(TABLE_SELECTOR); | |
for (var i = 0; i < table_rows.length; i++) { | |
//for (var i = 0; i < 10; i++) { | |
var $row = table_rows[i]; | |
var items = $row.children; | |
if (items.length == 0) { continue; } | |
var title = $(items[0]).find("a").text(); | |
var original = $(items[3].children[0]).find(".original_score").text().trim(); | |
var total = items[4].textContent.trim(); | |
HandleRow(title, original, total); | |
// console.log(total_score.innerText.trim()); | |
} | |
} | |
var psets = new Array(NUM_PSETS + 1); | |
var labs_ = new Array(NUM_PSETS + 1); | |
function HandleRow(ti, orig, total) { | |
var title = ti.toLowerCase(); | |
var is_problem = title.includes("problem"); | |
var is_lab = title.includes("lab"); | |
if (!is_problem && !is_lab) return; | |
var index = is_problem ? title.substr(12, 2) : title.substr(5, 2); | |
index = parseInt(index); | |
orig = parseInt(orig); | |
if (title.includes("problem")) { | |
if (psets[index] == undefined) psets[index] = { base: 0, solved: 0, upsolved: 0 }; | |
if (title.includes("upsolved")) { psets[index].upsolved = orig; } | |
else if (title.includes("solved")) { psets[index].solved = orig; } | |
else if (title.includes("base")) { psets[index].base = orig; } | |
} else if (title.includes("lab")) { | |
if (labs_[index] == undefined) labs_[index] = { base: 0, solved: 0, upsolved: 0 }; | |
if (title.includes("upsolved")) { labs_[index].upsolved = orig; } | |
else if (title.includes("solved")) { labs_[index].solved = orig; } | |
else if (title.includes("base")) { labs_[index].base = orig; } | |
} | |
} | |
ReadTable(); | |
console.log(psets) | |
console.log(labs_) | |
// pad left string | |
// https://stackoverflow.com/questions/2686855/is-there-a-javascript-function-that-can-pad-a-string-to-get-to-a-determined-leng | |
String.prototype.pad = function (v) { return String(" ".repeat(v) + this).slice(-v); }; | |
console.log("PSET | SOLVED | UPSOLVED | BASE | WEIGHTED %"); | |
for (var i = 0; i < psets.length; i++) { | |
if (!psets[i]) continue; | |
var solved = psets[i].solved ? psets[i].solved.toString() : "0"; | |
var base = psets[i].base ? psets[i].base.toString() : "0"; | |
var upsolved = psets[i].upsolved ? psets[i].upsolved.toString() : "0"; | |
var percent = (psets[i].upsolved * 0.5 + psets[i].solved) / psets[i].base * 100; | |
var conditional = percent < 50 ? " *****" : ""; | |
percent = isNaN(percent) ? "--" : percent.toFixed(2); | |
var out = `${i.toString().pad(4)} | ${solved.pad(6)} | ${upsolved.pad(8)} | ${base.pad(4)} | ${percent} ${conditional}`; | |
console.log(out); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment