Skip to content

Commit

Permalink
Merge pull request #304 from sas-fossdev/fix-powerschool-changes
Browse files Browse the repository at this point in the history
Re-adds percentages and fix powerschool changes. also fixes category weighting.
  • Loading branch information
Suhas Hariharan authored Oct 13, 2021
2 parents 73c3a2a + bb0b837 commit b762e64
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 148 deletions.
153 changes: 78 additions & 75 deletions src/js/__tests__/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*
* @copyright Copyright (c) 2019-2020 Gary Kim <gary@garykim.dev>
*
* @copyright Copyright (c) 2021 Suhas Hariharan <contact@suhas.net>
*
* @author Gary Kim <gary@garykim.dev>
*
* @license GNU AGPL version 3 only
Expand Down Expand Up @@ -190,84 +192,85 @@ test('Grade to Final Percent', t => {
test('Extract Final Percent from Class Page', t => {
const test_cases = [
{
i: "<tbody><tr>\n" +
" \t<td><strong>Final\n" +
" Letter Grade<sup>1</sup>:</strong></td><td>A</td>\n" +
" </tr>\n" +
"\t\t\t<!-- \n" +
" <tr>\n" +
" [if.1=0]<td><strong>\n" +
" Final Percent:\n" +
" </strong></td>\n" +
" <td>\n" +
" <script type=\"text/javascript\">\n" +
" if (\"A\" == \"--\") {\n" +
" document.write(\"&nbsp;\");\n" +
" }\n" +
" else {\n" +
" document.write(\"[decode;004887413;031@;.;81.25] &nbsp;\");\n" +
" }\n" +
" </script>\n" +
"\t\t\t\t</td>\n" +
"\t\t\t\t[/if]\n" +
"\t\t\t</tr>\n" +
"\t\t\t-->\t\n" +
" </tbody>",
o: 81.25,
},
{
i: "<table class=\"linkDescList\">\n" +
" <colgroup><col><col></colgroup>\n" +
" <tbody><tr>\n" +
" \t<td><strong>Final\n" +
" Letter Grade<sup>1</sup>:</strong></td><td>_</td>\n" +
" </tr>\n" +
"\t\t\t<!-- \n" +
" <tr>\n" +
" [if.1=0]<td><strong>\n" +
" Final Percent:\n" +
" </strong></td>\n" +
" <td>\n" +
" <script type=\"text/javascript\">\n" +
" if (\"_\" == \"--\") {\n" +
" document.write(\"&nbsp;\");\n" +
" }\n" +
" else {\n" +
" document.write(\"[decode;004888554;031@;.;_] &nbsp;\");\n" +
" }\n" +
" </script>\n" +
"\t\t\t\t</td>\n" +
"\t\t\t\t[/if]\n" +
"\t\t\t</tr>\n" +
"\t\t\t-->\t\n" +
" </tbody></table>",

i: `<tbody>
<tr>
<td><strong>Final
Letter Grade<sup>1</sup>:</strong></td>
<td>A</td>
</tr>
<!--
<tr>
[if.1=0]<td><strong>
Final Percent:
</strong></td>
<td>
<script type="text/javascript">
if ("A" == "--") {
document.write("&nbsp;");
}
else {
document.write("[decode;0041052333;031@;;82.5] &nbsp;");
}
</script>
</td>
[/if]
</tr>
-->
</tbody>`,
o: 82.5,
},
{
i: `<tbody><tr>
<td><strong>Final
Letter Grade<sup>1</sup>:</strong></td><td>A</td>
</tr>
<!--
<tr>
[if.1=0]<td><strong>
Final Percent:
</strong></td>
<td>
<script type="text/javascript">
if ("A" == "--") {
document.write("&nbsp;");
}
else {
document.write("[decode;004976938;031@;;] &nbsp;");
}
</script>
</td>
[/if]
</tr>
-->
</tbody>`,
o: undefined,
},
{
i: "<tbody><tr>\n" +
" \t<td><strong>Final\n" +
" Letter Grade<sup>1</sup>:</strong></td><td>A</td>\n" +
" </tr>\n" +
"\t\t\t<!-- \n" +
" <tr>\n" +
" [if.1=0]<td><strong>\n" +
" Final Percent:\n" +
" </strong></td>\n" +
" <td>\n" +
" <script type=\"text/javascript\">\n" +
" if (\"A\" == \"--\") {\n" +
" document.write(\"&nbsp;\");\n" +
" }\n" +
" else {\n" +
" document.write(\"[decode;004925338;031@;.;75] &nbsp;\");\n" +
" }\n" +
" </script>\n" +
"\t\t\t\t</td>\n" +
"\t\t\t\t[/if]\n" +
"\t\t\t</tr>\n" +
"\t\t\t-->\t\n" +
" </tbody>",
o: 75,
i: `<tbody><tr>
<td><strong>Final
Letter Grade<sup>1</sup>:</strong></td><td>A+</td>
</tr>
<!--
<tr>
[if.1=0]<td><strong>
Final Percent:
</strong></td>
<td>
<script type="text/javascript">
if ("A+" == "--") {
document.write("&nbsp;");
}
else {
document.write("[decode;004976943;031@;;90] &nbsp;");
}
</script>
</td>
[/if]
</tr>
-->
</tbody>`,
o: 90,
},
];

Expand Down
33 changes: 26 additions & 7 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 Expand Up @@ -132,9 +147,13 @@ export default {
catmap[e] = { weighting: 0, category: e };
});
}
const category_set = new Set(this.categories);
for (var cat in catmap) {
category_set.add(cat);
this.renderWeights.push(catmap[cat]);
}
this.categories = Array.from(category_set);
this.gradetable.updateCategories(this.categories);
},
saveCategoryWeightingLocal () {
saveCategoryWeighting(this.getCategoryMap());
Expand All @@ -159,7 +178,7 @@ export default {
},
changeCategory (c, nc) {
this.gradetable.changeCategory(this.categories[c], nc);
this.categories[c] = nc;
this.$set(this.categories, c, nc);
},
},
};
Expand Down
12 changes: 6 additions & 6 deletions src/js/components/GradeRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->

<template>
<tr :bgcolor="(assignment.id % 2 == 0) ? '#edf3fe' : '#fff'">
<tr :bgcolor="assignment.id % 2 == 0 ? '#edf3fe' : '#fff'">
<td v-html="assignment.date" />
<td
v-if="!assignment.hypo"
Expand Down Expand Up @@ -60,14 +60,14 @@
alt="Missing"
>
</td>
<td width="14">
<td width="35">
<img
v-if="assignment.exempt"
src="/images/icon_exempt.gif"
alt="Exempt"
>
</td>
<td width="19">
<td width="35">
<img
v-if="assignment.excluded"
src="/images/icon_excluded.gif"
Expand Down Expand Up @@ -124,10 +124,10 @@
</tr>
</template>
<script>
import { avaliableGrades } from '../helpers';
import ClassAssignment from '../models/ClassAssignment';
import { avaliableGrades } from "../helpers";
import ClassAssignment from "../models/ClassAssignment";
export default {
name: 'GradeRow',
name: "GradeRow",
props: {
assignment: {
type: ClassAssignment,
Expand Down
26 changes: 19 additions & 7 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 Expand Up @@ -133,7 +138,7 @@ export default {
}
let missing = 0;
for (var cat in catmap) {
if (grade[cat] == null) {
if (grade[cat] === undefined || grade[cat] === null || grade[cat].every((element) => element === -1)) {
if (catmap[cat].weighting !== "") {
missing += catmap[cat].weighting;
}
Expand All @@ -142,11 +147,15 @@ export default {
let percent = 0;
for (cat in grade) {
let sum = 0;
let grade_count = 0;
for (i = 0; i < grade[cat].length; i++) {
sum += grade[cat][i];
if (grade[cat][i] !== -1) {
sum += grade[cat][i];
grade_count++;
}
}
if (catmap[cat].weighting !== "") {
percent += sum / grade[cat].length * catmap[cat].weighting;
if (catmap[cat].weighting !== "" && grade_count !== 0) {
percent += (sum / grade_count) * catmap[cat].weighting;
}
}
if (missing === 100) {
Expand All @@ -166,6 +175,9 @@ export default {
}
}
},
updateCategories (categories) {
this.categories = categories;
},
changeCategory (oc, nc) {
for (var i = 0; i < this.assignments.length; i++) {
if (this.assignments[i].category === oc) {
Expand Down
Loading

0 comments on commit b762e64

Please sign in to comment.