Skip to content

Commit

Permalink
fixed powerschool percentages functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhas Hariharan committed Oct 5, 2021
1 parent 44b2b73 commit eaa5e52
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 41 deletions.
27 changes: 21 additions & 6 deletions src/js/components/CategoryWeighting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@
:bgcolor="(index % 2 == 0) ? '#edf3fe' : '#fff'"
>
<td v-if="category.newc">
<input v-model="category.category" @change="changeCategory(index, category.category)">
<button @click="delCategory(index)">Delete</button>
<input
v-model="category.category"
@change="changeCategory(index, category.category)"
>
<button @click="delCategory(index)">
Delete
</button>
</td>
<td v-else v-html="category.category" />
<td
v-else
v-html="category.category"
/>
<td>
<input
v-model.number="category.weighting"
Expand All @@ -61,7 +69,10 @@
</tr>
</tbody>
</table>
<button style="margin-left: 20px" @click="addCategory();">
<button
style="margin-left: 20px"
@click="addCategory();"
>
Add Category
</button>
<label v-if="categorySum != 100">Category weightings do not sum to 100%</label>
Expand All @@ -71,8 +82,12 @@
>
Save Weighting
</button>
<h2 v-if="categorySum==100">{{ hypo.grade }} ({{ hypo.fp }})<br></h2>
<div v-if="categorySum!=100"><br></div>
<h2 v-if="categorySum==100">
{{ hypo.grade }} ({{ hypo.fp }})<br>
</h2>
<div v-if="categorySum!=100">
<br>
</div>
<p>Note: Since teachers can adjust the weighting of each assignment as well, this number is not necessarily accurate. In addition, early in the year some categories(i.e the exam category) may contain no grades and the percentages would need to be adjusted accordingly.</p>
</div>
</template>
Expand Down
11 changes: 8 additions & 3 deletions src/js/components/GradeTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@
<th class="center">
Grd
</th>
<th v-if="categoryWeighting">Exmp</th>
<th v-if="categoryWeighting">
Exmp
</th>
</tr>
<grade-row
v-for="assignment in assignments"
:key="assignment.id"
:assignment="assignment"
:categories="categories"
:categoryWeighting="categoryWeighting"
:category-weighting="categoryWeighting"
/>
<tr>
<td
Expand Down Expand Up @@ -87,7 +89,10 @@
</tr>
</tbody>
</table>
<button v-if="categoryWeighting" @click="addAssignment();">
<button
v-if="categoryWeighting"
@click="addAssignment();"
>
Add Assignment
</button>
</div>
Expand Down
26 changes: 25 additions & 1 deletion src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function extractFinalPercent (html) {
let current_string = html.match(/(?=document\.write).*/g)[1];
current_string = /\[.*\]/g.exec(current_string)[0].slice(1, -1);
const temp = current_string.split(";");
number = Math.max(isNaN(temp[temp.length - 2]) ? -Infinity : parseFloat(temp[temp.length - 2]), isNaN(temp[temp.length - 1]) ? -Infinity : parseFloat(temp[temp.length - 1]));
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);
} catch (e) {
return;
}
Expand All @@ -160,6 +160,29 @@ function extractFinalPercent (html) {
return number;
}

/**
* Extract the final percent from the course page html.
* @param {Number} frn course id used to get course percent
* @param {String} semester string representing semester that the request is for
* @returns {Number|undefined} The final percent
*/
async function getFinalPercent (frn, semester) {
let number;
try {
await fetch(`https://powerschool.sas.edu.sg/guardian/scores_ms_guardian.html?frn=${frn}&fg=${semester}`, { credentials: "same-origin" }).then(response => response.text()).then(response => {
const page = document.implementation.createHTMLDocument();
page.documentElement.innerHTML = response;
number = extractFinalPercent(page.querySelector('table.linkDescList').innerHTML);
});
} catch (e) {
return;
}
if (number === null) {
return;
}
return number;
}

/**
* Extract all grade categories from the course page html.
* @param {String} html course page html
Expand Down Expand Up @@ -344,6 +367,7 @@ export {
getSavedCategoryWeighting,
saveCategoryWeighting,
extractFinalPercent,
getFinalPercent,
extractGradeCategories,
extractAssignmentList,
assignments,
Expand Down
72 changes: 41 additions & 31 deletions src/js/saspowerschoolff.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const browser = require('webextension-polyfill');
import {
assignments,
calculate_gpa,
extractFinalPercent,
getFinalPercent,
extractGradeCategories,
gradeToGPA,
saveGradesLocally,
Expand Down Expand Up @@ -83,13 +83,12 @@ function main () {
}
}

function main_page () {
async function main_page () {
const student_name = getStudentName();
const { sem1_col, sem2_col } = getSemesterCols();
const second_semester = isSecondSemester(sem2_col);
const current_term = getCurrentTerm();
const { courses, promises_grade_calc_list } = getCourses(second_semester, sem1_col, sem2_col);

const { courses, promises_grade_calc_list } = await getCourses(second_semester, sem1_col, sem2_col);
showCurrentGPA(second_semester, courses, promises_grade_calc_list);

if (second_semester) {
Expand All @@ -110,9 +109,10 @@ function main_page () {
});
}

function class_page () {
async function class_page () {
// Show final percent
const number = extractFinalPercent($("table.linkDescList").html());
const currentUrl = new URL(document.location.href);
const number = await getFinalPercent(currentUrl.searchParams.get("frn"), currentUrl.searchParams.get("fg")) || "";
if (!number) {
return;
}
Expand Down Expand Up @@ -291,7 +291,7 @@ function getCurrentTerm () {
* @param sem2_col The column of the second semester
* @returns {Course[]} array of Course objects representing the Courses of the user
*/
function getCourses (second_semester, sem1_col, sem2_col) {
async function getCourses (second_semester, sem1_col, sem2_col) {
const $grade_rows = $('#quickLookup table.grid').find('tr');
const courses = [];
const promises_grade_calc_list = [];
Expand All @@ -305,18 +305,22 @@ function getCourses (second_semester, sem1_col, sem2_col) {
if ($first_grade.length === 1) {
if (gradeToGPA($first_grade.text()) !== -1) {
promises_grade_calc_list.push(new Promise((resolve, reject) => {
fetch(`https://powerschool.sas.edu.sg/guardian/${$first_grade.attr('href')}`, { credentials: "same-origin" }).then(response => response.text()).then(response => {
const page = document.implementation.createHTMLDocument();
page.documentElement.innerHTML = response;
const finalPercent = extractFinalPercent(page.querySelector('table.linkDescList').innerHTML) || "";
if (gradeToGPA($first_grade.text()) !== -1) {
new (Vue.extend(ClassGrade))({
propsData: {
course: new Course("", `https://powerschool.sas.edu.sg/guardian/${$first_grade.attr('href')}`, $first_grade.text(), finalPercent),
},
}).$mount($first_grade.get(0));
const currentUrlString = `https://powerschool.sas.edu.sg/guardian/${$first_grade.attr('href')}`;
const currentUrl = new URL(currentUrlString);
getFinalPercent(currentUrl.searchParams.get("frn"), currentUrl.searchParams.get("fg")).then(finalPercent => {
if (!finalPercent) {
finalPercent = "";
}
resolve("Success");
fetch(currentUrlString, { credentials: "same-origin" }).then(response => response.text()).then(response => {
if (gradeToGPA($first_grade.text()) !== -1) {
new (Vue.extend(ClassGrade))({
propsData: {
course: new Course("", currentUrlString, $first_grade.text(), finalPercent),
},
}).$mount($first_grade.get(0));
}
resolve("Success");
});
});
}));
}
Expand All @@ -328,20 +332,26 @@ function getCourses (second_semester, sem1_col, sem2_col) {
const temp = $course.parents().eq(1).children("td[align=left]").text().match(".*(?=Details)")[0];
if (gradeToGPA($course.text()) !== -1) {
promises_grade_calc_list.push(new Promise((resolve, reject) => {
fetch(`https://powerschool.sas.edu.sg/guardian/${$course.attr('href')}`, { credentials: "same-origin" }).then(response => response.text()).then(response => {
const page = document.implementation.createHTMLDocument();
page.documentElement.innerHTML = response;
const finalPercent = extractFinalPercent(page.querySelector('table.linkDescList').innerHTML) || "";
const assignment_list = assignments(page.querySelector('body'));
courses.push(new Course(temp.trim(), `https://powerschool.sas.edu.sg/guardian/${$course.attr('href')}`, $course.text(), finalPercent, assignment_list));
if (gradeToGPA($course.text()) !== -1) {
new (Vue.extend(ClassGrade))({
propsData: {
course: courses[courses.length - 1],
},
}).$mount($course.get(0));
const currentUrlString = `https://powerschool.sas.edu.sg/guardian/${$course.attr('href')}`;
const currentUrl = new URL(currentUrlString);
getFinalPercent(currentUrl.searchParams.get("frn"), currentUrl.searchParams.get("fg")).then(finalPercent => {
if (!finalPercent) {
finalPercent = "";
}
resolve("Success");
fetch(currentUrlString, { credentials: "same-origin" }).then(response => response.text()).then(response => {
const page = document.implementation.createHTMLDocument();
page.documentElement.innerHTML = response;
const assignment_list = assignments(page.querySelector('body'));
courses.push(new Course(temp.trim(), currentUrlString, $course.text(), finalPercent, assignment_list));
if (gradeToGPA($course.text()) !== -1) {
new (Vue.extend(ClassGrade))({
propsData: {
course: courses[courses.length - 1],
},
}).$mount($course.get(0));
}
resolve("Success");
});
});
}));
}
Expand Down

0 comments on commit eaa5e52

Please sign in to comment.