Last active
October 8, 2018 19:10
-
-
Save LevitatingBusinessMan/53104b2957d14a447252aa02e2d9aa22 to your computer and use it in GitHub Desktop.
Magister Grade Calculator
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
//Example: node <script.js> "<school>" <username> <password> | |
const { default: magister, getSchools } = require('magister2.js'); | |
const chalk = require('chalk'); | |
process.stdout.write('\033c'); | |
let school = process.argv[2]; | |
let username = process.argv[3]; | |
let password = process.argv[4]; | |
getSchools(school) | |
.then((schools) => schools[0]) | |
.then(school => magister({school,username,password})) | |
.then(async m => { | |
console.log(m.profileInfo.firstName + " " + m.profileInfo.lastName + ":") | |
let courses = await m.courses(); | |
let course = courses[courses.length-1]; | |
let grades = await course.grades(); | |
let classes = {}; | |
grades.forEach(grade => { | |
//Remove workattitude grades and averages | |
if ( | |
grade.type.header === "PR" || | |
grade.type.header.startsWith("Eind") || | |
isNaN(parseInt(grade.grade)) | |
) return; | |
let className = grade.class.abbreviation; | |
if (!classes[className]) | |
classes[className] = []; | |
let {grade: value, weight} = grade; | |
classes[className].push({ | |
value: value.replace(',','.'), | |
weight: weight | |
}); | |
}); | |
for (let nameOfClass in classes) { | |
let grades = classes[nameOfClass]; | |
let total_points = 0; | |
let count = 0; | |
for (let i=0;i<grades.length;i++){ | |
total_points += grades[i].value * grades[i].weight; | |
count += grades[i].weight; | |
} | |
let requiredGrade = [ | |
Math.round(((5.5 * (count + 1) - total_points) / 1) *100)/100, | |
Math.round(((5.5 * (count + 2) - total_points) / 2) *100)/100, | |
Math.round(((5.5 * (count + 3) - total_points) / 3) *100)/100 | |
] | |
for (let i=0;i<requiredGrade.length;i++) { | |
if (requiredGrade[i] < 1) | |
requiredGrade[i] = chalk.greenBright(1); | |
if (requiredGrade[i] < 3.5 && !isNaN(requiredGrade[i])) | |
requiredGrade[i] = chalk.green(requiredGrade[i]); | |
if (requiredGrade[i] < 4.5 && !isNaN(requiredGrade[i])) | |
requiredGrade[i] = chalk.yellowBright(requiredGrade[i]); | |
if (!isNaN(requiredGrade[i])) | |
requiredGrade[i] = chalk.red(requiredGrade[i]); | |
} | |
console.log(`${nameOfClass} 1: ${requiredGrade[0]}, 2: ${requiredGrade[1]}, 3: ${requiredGrade[2]}`); | |
} | |
}) |
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
{ | |
"name": "gradeCalc", | |
"version": "1.0.0", | |
"description": "Magister Grade Calculator", | |
"main": "grade_calc.js", | |
"dependencies": { | |
"chalk": "^2.4.1", | |
"magister2.js": "^2.0.0-alpha5" | |
}, | |
"author": "LevitatingBusinessMan", | |
"license": "MIT" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment