From 2ee256436e6a34c113bbae1c1d839e6a6655eefd Mon Sep 17 00:00:00 2001 From: Suhas Hariharan Date: Wed, 2 Sep 2020 21:48:15 +0800 Subject: [PATCH 1/3] fixed cumulative gpa calculation and regular gpa calculation Signed-off-by: Suhas Hariharan --- src/js/components/CumulativeGPA.vue | 16 ++++++++++++---- src/js/helpers.js | 2 +- src/js/saspowerschoolff.js | 6 ++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/js/components/CumulativeGPA.vue b/src/js/components/CumulativeGPA.vue index e4135186..430f371e 100644 --- a/src/js/components/CumulativeGPA.vue +++ b/src/js/components/CumulativeGPA.vue @@ -128,7 +128,9 @@ export default { } this.currently = CURRENTLY.CALCULATING; - const gpa = await this.calculate_cumulative_gpa(this.courses, this.currentTerm, this.secondSemester).catch(() => null); + const gpa = await this.calculate_cumulative_gpa(this.courses, this.currentTerm, this.secondSemester).catch((err) => { + console.log("Error in cumulative GPA calculation " + err); + }); if (gpa) { this.gpa = gpa.toFixed(2); this.currently = CURRENTLY.DONE; @@ -149,7 +151,13 @@ export default { .then(data => { const el = document.createElement("html"); el.innerHTML = data; - const current_term_history = el.getElementsByClassName("selected")[0].textContent.split(" - ")[0]; + let current_term_history = el.getElementsByClassName("selected"); + if (current_term_history.length !=0) { + current_term_history=current_term_history[0].textContent.split(" - ")[0]; + } + else { + current_term_history=undefined; + } const tabs = el.getElementsByClassName("tabs")[0].getElementsByTagName("li"); // Iterate until the end of tabs or until no longer at a high school semester for (let i = 0; i < tabs.length && /HS$/.test(tabs[i].innerText); i++) { @@ -190,7 +198,7 @@ export default { })); } // Calculates cumulative GPA based on credit hours per semester and gpa for each semester. - + console.log("got this far in calculation"); const cumulative_gpa = Promise.all(fetches).then(function () { let include_current_semester = false; if (current_courses.length !== 0) { @@ -206,7 +214,7 @@ export default { } else if (current_term_history === current_term && include_current_semester && current_term_grades.length === 1 && current_semester === false) { all_courses.splice(all_courses.indexOf(current_term_grades[0]), 1); } - + if (include_current_semester) { all_courses.push(current_courses); } diff --git a/src/js/helpers.js b/src/js/helpers.js index 2006104d..0bdefe9b 100644 --- a/src/js/helpers.js +++ b/src/js/helpers.js @@ -187,7 +187,7 @@ async function getSavedGrades (username) { const courses = []; const course_list = (await browser.storage.local.get("USERDATA_" + username))["USERDATA_" + username] || []; course_list.forEach(course => { - courses.push(new Course(course.name, course.link, course_list.grade, course_list.finalPercent, course_list.assignments)); + courses.push(new Course(course.name, course.link, course.grade, course.finalPercent, course.assignments)); }); return courses; } diff --git a/src/js/saspowerschoolff.js b/src/js/saspowerschoolff.js index dbb93357..395eff2a 100644 --- a/src/js/saspowerschoolff.js +++ b/src/js/saspowerschoolff.js @@ -96,6 +96,12 @@ function main_page () { } curr += parseInt(e.getAttribute('colspan')) || 1; }); + second_semester=false; + for (let t=0; t<$grade_rows.length; t++) { + if (gradeToGPA($grade_rows.eq(t).find('td').get(s2col)) !== -1) { + second_semester=true; + } + } } for (let i = 0; i < $grade_rows.length; i++) { let $course; From e9e50a360ba3b2bfa8742518dc78fc7027707946 Mon Sep 17 00:00:00 2001 From: Suhas Hariharan Date: Wed, 2 Sep 2020 21:49:58 +0800 Subject: [PATCH 2/3] removed debug Signed-off-by: Suhas Hariharan --- src/js/components/CumulativeGPA.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/components/CumulativeGPA.vue b/src/js/components/CumulativeGPA.vue index 430f371e..bd8b59eb 100644 --- a/src/js/components/CumulativeGPA.vue +++ b/src/js/components/CumulativeGPA.vue @@ -198,7 +198,6 @@ export default { })); } // Calculates cumulative GPA based on credit hours per semester and gpa for each semester. - console.log("got this far in calculation"); const cumulative_gpa = Promise.all(fetches).then(function () { let include_current_semester = false; if (current_courses.length !== 0) { From 5319c66e21cb1a265d4329c14cd6cc9193e217df Mon Sep 17 00:00:00 2001 From: Suhas Hariharan Date: Wed, 2 Sep 2020 21:58:51 +0800 Subject: [PATCH 3/3] fixed lint Signed-off-by: Suhas Hariharan --- src/js/components/CumulativeGPA.vue | 11 +++++------ src/js/saspowerschoolff.js | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/js/components/CumulativeGPA.vue b/src/js/components/CumulativeGPA.vue index bd8b59eb..a0fb904d 100644 --- a/src/js/components/CumulativeGPA.vue +++ b/src/js/components/CumulativeGPA.vue @@ -152,11 +152,10 @@ export default { const el = document.createElement("html"); el.innerHTML = data; let current_term_history = el.getElementsByClassName("selected"); - if (current_term_history.length !=0) { - current_term_history=current_term_history[0].textContent.split(" - ")[0]; - } - else { - current_term_history=undefined; + if (current_term_history.length !== 0) { + current_term_history = current_term_history[0].textContent.split(" - ")[0]; + } else { + current_term_history = undefined; } const tabs = el.getElementsByClassName("tabs")[0].getElementsByTagName("li"); // Iterate until the end of tabs or until no longer at a high school semester @@ -213,7 +212,7 @@ export default { } else if (current_term_history === current_term && include_current_semester && current_term_grades.length === 1 && current_semester === false) { all_courses.splice(all_courses.indexOf(current_term_grades[0]), 1); } - + if (include_current_semester) { all_courses.push(current_courses); } diff --git a/src/js/saspowerschoolff.js b/src/js/saspowerschoolff.js index 395eff2a..915754b5 100644 --- a/src/js/saspowerschoolff.js +++ b/src/js/saspowerschoolff.js @@ -96,10 +96,10 @@ function main_page () { } curr += parseInt(e.getAttribute('colspan')) || 1; }); - second_semester=false; - for (let t=0; t<$grade_rows.length; t++) { + second_semester = false; + for (let t = 0; t < $grade_rows.length; t++) { if (gradeToGPA($grade_rows.eq(t).find('td').get(s2col)) !== -1) { - second_semester=true; + second_semester = true; } } }