Skip to content

Commit 3fde949

Browse files
author
Suhas Hariharan
authored
Merge pull request #313 from sas-fossdev/fix-percentages-and-cumulative-calculation
Fix percentages not showing and cumulative GPA double including finished semester
2 parents 78b066c + 3e56d4d commit 3fde949

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

src/js/components/CumulativeGPA.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,18 @@ export default {
170170
semester.innerHTML = data2;
171171
element_list = semester.getElementsByClassName("box-round")[0].getElementsByTagName("table")[0];
172172
element_list = element_list.getElementsByTagName("tbody")[0].getElementsByTagName("tr");
173-
for (let t = 2; t < element_list.length; t++) {
173+
for (let t = 0; t < element_list.length; t++) {
174174
if (element_list[t].innerText.trim() === ("S2")) {
175-
most_recent_term = "S2";
176175
all_courses.push(courses);
177176
if (i === 0) {
177+
most_recent_term = "S2";
178178
current_term_grades.push(courses);
179179
}
180180
courses = [];
181181
} else if (element_list[t].innerText.trim() === ("S1")) {
182-
most_recent_term = "S1";
182+
if (i === 0) {
183+
most_recent_term = "S1";
184+
}
183185
}
184186
if (element_list[t].getElementsByTagName("th").length > 0) {
185187
continue;

src/js/helpers.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function extractFinalPercent (html) {
150150
let current_string = html.match(/(?=document\.write).*/g)[1];
151151
current_string = /\[.*\]/g.exec(current_string)[0].slice(1, -1);
152152
const temp = current_string.split(";");
153-
number = Math.max(isNaN(temp[temp.length - 2]) || temp[temp.length - 2] ? parseFloat(temp[temp.length - 2]) : -Infinity, isNaN(temp[temp.length - 1]) || temp[temp.length - 1] ? parseFloat(temp[temp.length - 1]) : -Infinity);
153+
number = Math.max(isNaN(parseFloat(temp[temp.length - 2])) ? -Infinity : parseFloat(temp[temp.length - 2]), isNaN(parseFloat(temp[temp.length - 1])) ? -Infinity : parseFloat(temp[temp.length - 1]));
154154
} catch (e) {
155155
return;
156156
}
@@ -244,13 +244,12 @@ function assignmentsFromNode (node) {
244244

245245
/**
246246
* Return Assignment instances for the given class page.
247-
* @param {String} student_id student id for the current user
248-
* @param {String} sectino_id section id for the course being requested
249-
* @param {String} start_date start date in YYYY-MM-DD format
250-
* @param {String} end_date end date in YYYY-MM-DD format
247+
* @param {String} studentId student id for the current user
248+
* @param {String} sectionId section id for the course being requested
249+
* @param {String} currentSemester currentSemester the current semester (either S1 or S2)
251250
* @returns {Assignment[]} Assignments in this course
252251
*/
253-
function assignmentsFromAPI (studentId, sectionId, startDate, endDate) {
252+
function assignmentsFromAPI (studentId, sectionId, currentSemester) {
254253
const assignmentList = [];
255254
try {
256255
fetch('https://powerschool.sas.edu.sg/ws/xte/assignment/lookup', {
@@ -261,8 +260,7 @@ function assignmentsFromAPI (studentId, sectionId, startDate, endDate) {
261260
body: JSON.stringify({
262261
"student_ids": [studentId],
263262
"section_ids": [sectionId],
264-
"start_date": startDate,
265-
"end_date": endDate,
263+
"store_codes": [currentSemester],
266264
}),
267265
credentials: "same-origin",
268266
}).then(response => response.json()).then(response => {

src/js/saspowerschoolff.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,14 @@ async function getCourses (second_semester, sem1_col, sem2_col) {
348348
const page = document.implementation.createHTMLDocument();
349349
page.documentElement.innerHTML = response;
350350
const sectionId = page.querySelector("div[data-pss-student-assignment-scores]").getAttribute("data-sectionid");
351-
let startDate = currentUrl.searchParams.get("begdate");
352-
startDate = startDate.split("/")[2] + "-" + startDate.split("/")[0] + "-" + startDate.split("/")[1];
353-
let endDate = currentUrl.searchParams.get("enddate");
354-
endDate = endDate.split("/")[2] + "-" + endDate.split("/")[0] + "-" + endDate.split("/")[1];
355351
const studentId = page.querySelector("div .xteContentWrapper").getAttribute("data-ng-init").split("\n")[0].split("= '")[1].replace("';", "").substring(3);
356-
const assignment_list = assignmentsFromAPI(studentId, sectionId, startDate, endDate);
352+
let currentSemester;
353+
if (second_semester) {
354+
currentSemester = "S2";
355+
} else {
356+
currentSemester = "S1";
357+
}
358+
const assignment_list = assignmentsFromAPI(studentId, sectionId, currentSemester);
357359
courses.push(new Course(temp.trim(), currentUrlString, $course.text(), finalPercent, assignment_list));
358360
if (gradeToGPA($course.text()) !== -1) {
359361
new (Vue.extend(ClassGrade))({

0 commit comments

Comments
 (0)