Last active
August 29, 2015 14:14
-
-
Save justincosentino/6239e99e76237212524b to your computer and use it in GitHub Desktop.
MySwat GPA Scraper - Login to mySwarthmore, then: Student Main Menu -> Student Records -> Grades at a Glance and then run this in the console. I'm going to make it a bookmarklet later.
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
var gradeEquiv = { | |
'A+': 4, | |
'A' : 4, | |
'A-': 3.67, | |
'B+': 3.33, | |
'B' : 3, | |
'B-': 2.67, | |
'C+': 2.33, | |
'C' : 2, | |
'C-': 1.67, | |
'D+': 1.33, | |
'D' : 1, | |
'D-': 0.33, | |
'E' : 0 | |
}; | |
function zip(arrays) { | |
return arrays[0].map(function(_,i){ | |
return arrays.map(function(array){return array[i]}) | |
}); | |
} | |
function getTableColumnValues(col){ | |
var columnValues=[]; | |
$('table[id=R378781212054339999]').each(function() { | |
$('tr>td:nth-child('+col+')',$(this)).each(function() { | |
columnValues.push($(this).text()); | |
}); | |
}); | |
return columnValues; | |
} | |
function calculateGPA(info, gradeEquiv){ | |
var c = 0.0; | |
var p = 0.0; | |
for (var i = 0; i < info.length; i++) { | |
credit = parseFloat(info[i][0]); | |
grade = info[i][1]; | |
if (grade != 'CR' && isNaN(grade) && credit > 0) { | |
p += gradeEquiv[grade] * credit; | |
c += credit | |
} | |
} | |
return Math.round(p / c * 100) / 100; | |
} | |
var credits = getTableColumnValues(3); | |
var grades = getTableColumnValues(4); | |
var zipped = zip([credits, grades]); | |
var GPA = calculateGPA(zipped, gradeEquiv); | |
alert("Your GPA is a " + GPA + "/4 after " + credits.reduce(function(a, b) { | |
return parseFloat(a) + parseFloat(b); | |
}) + " credits!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment