more setup & add project
This commit is contained in:
1
berkeley-classes-sheet/.clasp.json
Normal file
1
berkeley-classes-sheet/.clasp.json
Normal file
@@ -0,0 +1 @@
|
||||
{"scriptId":"1_C1lw55CptRc-LGTB3PpZtBnHTeqXLhfEbBiDNb4U7SZyTy7k9HbfQgM","rootDir":"/Users/michael/Projects/gsheets-util/berkeley-classes-sheet"}
|
||||
49
berkeley-classes-sheet/Code.js
Normal file
49
berkeley-classes-sheet/Code.js
Normal file
@@ -0,0 +1,49 @@
|
||||
// NOTE: SHEET IS UNDER BERKELEY ACC
|
||||
|
||||
/**
|
||||
* Calculate GPA given grades & units
|
||||
* @param {*} grades Grades column
|
||||
* @param {*} units Class units (weights) column
|
||||
*/
|
||||
function GRADEPOINTS(grades, units) {
|
||||
|
||||
if (grades.length != units.length) {
|
||||
throw Error("Grades & Units columns must have the same length")
|
||||
}
|
||||
else if (grades[0].length != 1 || units[0].length != 1) {
|
||||
throw Error("Grades & Units each must be single columns")
|
||||
}
|
||||
|
||||
let gradeMap = {
|
||||
"A+": 4.0,
|
||||
"A": 4.0,
|
||||
"A-": 3.7,
|
||||
"B+": 3.3,
|
||||
"B": 3,
|
||||
"B-": 2.7,
|
||||
"C+": 2.3,
|
||||
"C": 2.0,
|
||||
"C-": 1.7,
|
||||
"D+": 1.3,
|
||||
"D": 1,
|
||||
"D-": 0.7,
|
||||
"F": 0.0,
|
||||
}
|
||||
|
||||
let gpSum = 0;
|
||||
let denom = 0;
|
||||
for (let i = 0; i < grades.length; i++) {
|
||||
let grade = grades[i][0];
|
||||
let unitCount = units[i][0]
|
||||
if (Object.keys(gradeMap).includes(grade)) {
|
||||
gpSum += gradeMap[grade] * unitCount;
|
||||
denom += unitCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (denom == 0) {
|
||||
throw Error("No valid values found in grades col")
|
||||
}
|
||||
|
||||
return gpSum / denom;
|
||||
}
|
||||
6
berkeley-classes-sheet/appsscript.json
Normal file
6
berkeley-classes-sheet/appsscript.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"timeZone": "America/Chicago",
|
||||
"dependencies": {},
|
||||
"exceptionLogging": "STACKDRIVER",
|
||||
"runtimeVersion": "V8"
|
||||
}
|
||||
Reference in New Issue
Block a user