Skip to content

Commit b762e64

Browse files
author
Suhas Hariharan
authored
Merge pull request #304 from sas-fossdev/fix-powerschool-changes
Re-adds percentages and fix powerschool changes. also fixes category weighting.
2 parents 73c3a2a + bb0b837 commit b762e64

File tree

6 files changed

+211
-148
lines changed

6 files changed

+211
-148
lines changed

src/js/__tests__/parsers.js

Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
*
33
* @copyright Copyright (c) 2019-2020 Gary Kim <[email protected]>
44
*
5+
* @copyright Copyright (c) 2021 Suhas Hariharan <[email protected]>
6+
*
57
* @author Gary Kim <[email protected]>
68
*
79
* @license GNU AGPL version 3 only
@@ -190,84 +192,85 @@ test('Grade to Final Percent', t => {
190192
test('Extract Final Percent from Class Page', t => {
191193
const test_cases = [
192194
{
193-
i: "<tbody><tr>\n" +
194-
" \t<td><strong>Final\n" +
195-
" Letter Grade<sup>1</sup>:</strong></td><td>A</td>\n" +
196-
" </tr>\n" +
197-
"\t\t\t<!-- \n" +
198-
" <tr>\n" +
199-
" [if.1=0]<td><strong>\n" +
200-
" Final Percent:\n" +
201-
" </strong></td>\n" +
202-
" <td>\n" +
203-
" <script type=\"text/javascript\">\n" +
204-
" if (\"A\" == \"--\") {\n" +
205-
" document.write(\"&nbsp;\");\n" +
206-
" }\n" +
207-
" else {\n" +
208-
" document.write(\"[decode;004887413;031@;.;81.25] &nbsp;\");\n" +
209-
" }\n" +
210-
" </script>\n" +
211-
"\t\t\t\t</td>\n" +
212-
"\t\t\t\t[/if]\n" +
213-
"\t\t\t</tr>\n" +
214-
"\t\t\t-->\t\n" +
215-
" </tbody>",
216-
o: 81.25,
217-
},
218-
{
219-
i: "<table class=\"linkDescList\">\n" +
220-
" <colgroup><col><col></colgroup>\n" +
221-
" <tbody><tr>\n" +
222-
" \t<td><strong>Final\n" +
223-
" Letter Grade<sup>1</sup>:</strong></td><td>_</td>\n" +
224-
" </tr>\n" +
225-
"\t\t\t<!-- \n" +
226-
" <tr>\n" +
227-
" [if.1=0]<td><strong>\n" +
228-
" Final Percent:\n" +
229-
" </strong></td>\n" +
230-
" <td>\n" +
231-
" <script type=\"text/javascript\">\n" +
232-
" if (\"_\" == \"--\") {\n" +
233-
" document.write(\"&nbsp;\");\n" +
234-
" }\n" +
235-
" else {\n" +
236-
" document.write(\"[decode;004888554;031@;.;_] &nbsp;\");\n" +
237-
" }\n" +
238-
" </script>\n" +
239-
"\t\t\t\t</td>\n" +
240-
"\t\t\t\t[/if]\n" +
241-
"\t\t\t</tr>\n" +
242-
"\t\t\t-->\t\n" +
243-
" </tbody></table>",
195+
196+
i: `<tbody>
197+
<tr>
198+
<td><strong>Final
199+
Letter Grade<sup>1</sup>:</strong></td>
200+
<td>A</td>
201+
</tr>
202+
<!--
203+
<tr>
204+
[if.1=0]<td><strong>
205+
Final Percent:
206+
</strong></td>
207+
<td>
208+
<script type="text/javascript">
209+
if ("A" == "--") {
210+
document.write("&nbsp;");
211+
}
212+
else {
213+
document.write("[decode;0041052333;031@;;82.5] &nbsp;");
214+
}
215+
</script>
216+
</td>
217+
[/if]
218+
</tr>
219+
-->
220+
</tbody>`,
221+
o: 82.5,
222+
},
223+
{
224+
i: `<tbody><tr>
225+
<td><strong>Final
226+
Letter Grade<sup>1</sup>:</strong></td><td>A</td>
227+
</tr>
228+
<!--
229+
<tr>
230+
[if.1=0]<td><strong>
231+
Final Percent:
232+
</strong></td>
233+
<td>
234+
<script type="text/javascript">
235+
if ("A" == "--") {
236+
document.write("&nbsp;");
237+
}
238+
else {
239+
document.write("[decode;004976938;031@;;] &nbsp;");
240+
}
241+
</script>
242+
</td>
243+
[/if]
244+
</tr>
245+
-->
246+
</tbody>`,
244247
o: undefined,
245248
},
246249
{
247-
i: "<tbody><tr>\n" +
248-
" \t<td><strong>Final\n" +
249-
" Letter Grade<sup>1</sup>:</strong></td><td>A</td>\n" +
250-
" </tr>\n" +
251-
"\t\t\t<!-- \n" +
252-
" <tr>\n" +
253-
" [if.1=0]<td><strong>\n" +
254-
" Final Percent:\n" +
255-
" </strong></td>\n" +
256-
" <td>\n" +
257-
" <script type=\"text/javascript\">\n" +
258-
" if (\"A\" == \"--\") {\n" +
259-
" document.write(\"&nbsp;\");\n" +
260-
" }\n" +
261-
" else {\n" +
262-
" document.write(\"[decode;004925338;031@;.;75] &nbsp;\");\n" +
263-
" }\n" +
264-
" </script>\n" +
265-
"\t\t\t\t</td>\n" +
266-
"\t\t\t\t[/if]\n" +
267-
"\t\t\t</tr>\n" +
268-
"\t\t\t-->\t\n" +
269-
" </tbody>",
270-
o: 75,
250+
i: `<tbody><tr>
251+
<td><strong>Final
252+
Letter Grade<sup>1</sup>:</strong></td><td>A+</td>
253+
</tr>
254+
<!--
255+
<tr>
256+
[if.1=0]<td><strong>
257+
Final Percent:
258+
</strong></td>
259+
<td>
260+
<script type="text/javascript">
261+
if ("A+" == "--") {
262+
document.write("&nbsp;");
263+
}
264+
else {
265+
document.write("[decode;004976943;031@;;90] &nbsp;");
266+
}
267+
</script>
268+
</td>
269+
[/if]
270+
</tr>
271+
-->
272+
</tbody>`,
273+
o: 90,
271274
},
272275
];
273276

src/js/components/CategoryWeighting.vue

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,18 @@
4646
:bgcolor="(index % 2 == 0) ? '#edf3fe' : '#fff'"
4747
>
4848
<td v-if="category.newc">
49-
<input v-model="category.category" @change="changeCategory(index, category.category)">
50-
<button @click="delCategory(index)">Delete</button>
49+
<input
50+
v-model="category.category"
51+
@change="changeCategory(index, category.category)"
52+
>
53+
<button @click="delCategory(index)">
54+
Delete
55+
</button>
5156
</td>
52-
<td v-else v-html="category.category" />
57+
<td
58+
v-else
59+
v-html="category.category"
60+
/>
5361
<td>
5462
<input
5563
v-model.number="category.weighting"
@@ -61,7 +69,10 @@
6169
</tr>
6270
</tbody>
6371
</table>
64-
<button style="margin-left: 20px" @click="addCategory();">
72+
<button
73+
style="margin-left: 20px"
74+
@click="addCategory();"
75+
>
6576
Add Category
6677
</button>
6778
<label v-if="categorySum != 100">Category weightings do not sum to 100%</label>
@@ -71,8 +82,12 @@
7182
>
7283
Save Weighting
7384
</button>
74-
<h2 v-if="categorySum==100">{{ hypo.grade }} ({{ hypo.fp }})<br></h2>
75-
<div v-if="categorySum!=100"><br></div>
85+
<h2 v-if="categorySum==100">
86+
{{ hypo.grade }} ({{ hypo.fp }})<br>
87+
</h2>
88+
<div v-if="categorySum!=100">
89+
<br>
90+
</div>
7691
<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>
7792
</div>
7893
</template>
@@ -132,9 +147,13 @@ export default {
132147
catmap[e] = { weighting: 0, category: e };
133148
});
134149
}
150+
const category_set = new Set(this.categories);
135151
for (var cat in catmap) {
152+
category_set.add(cat);
136153
this.renderWeights.push(catmap[cat]);
137154
}
155+
this.categories = Array.from(category_set);
156+
this.gradetable.updateCategories(this.categories);
138157
},
139158
saveCategoryWeightingLocal () {
140159
saveCategoryWeighting(this.getCategoryMap());
@@ -159,7 +178,7 @@ export default {
159178
},
160179
changeCategory (c, nc) {
161180
this.gradetable.changeCategory(this.categories[c], nc);
162-
this.categories[c] = nc;
181+
this.$set(this.categories, c, nc);
163182
},
164183
},
165184
};

src/js/components/GradeRow.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
-->
2222

2323
<template>
24-
<tr :bgcolor="(assignment.id % 2 == 0) ? '#edf3fe' : '#fff'">
24+
<tr :bgcolor="assignment.id % 2 == 0 ? '#edf3fe' : '#fff'">
2525
<td v-html="assignment.date" />
2626
<td
2727
v-if="!assignment.hypo"
@@ -60,14 +60,14 @@
6060
alt="Missing"
6161
>
6262
</td>
63-
<td width="14">
63+
<td width="35">
6464
<img
6565
v-if="assignment.exempt"
6666
src="/images/icon_exempt.gif"
6767
alt="Exempt"
6868
>
6969
</td>
70-
<td width="19">
70+
<td width="35">
7171
<img
7272
v-if="assignment.excluded"
7373
src="/images/icon_excluded.gif"
@@ -124,10 +124,10 @@
124124
</tr>
125125
</template>
126126
<script>
127-
import { avaliableGrades } from '../helpers';
128-
import ClassAssignment from '../models/ClassAssignment';
127+
import { avaliableGrades } from "../helpers";
128+
import ClassAssignment from "../models/ClassAssignment";
129129
export default {
130-
name: 'GradeRow',
130+
name: "GradeRow",
131131
props: {
132132
assignment: {
133133
type: ClassAssignment,

src/js/components/GradeTable.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@
4949
<th class="center">
5050
Grd
5151
</th>
52-
<th v-if="categoryWeighting">Exmp</th>
52+
<th v-if="categoryWeighting">
53+
Exmp
54+
</th>
5355
</tr>
5456
<grade-row
5557
v-for="assignment in assignments"
5658
:key="assignment.id"
5759
:assignment="assignment"
5860
:categories="categories"
59-
:categoryWeighting="categoryWeighting"
61+
:category-weighting="categoryWeighting"
6062
/>
6163
<tr>
6264
<td
@@ -87,7 +89,10 @@
8789
</tr>
8890
</tbody>
8991
</table>
90-
<button v-if="categoryWeighting" @click="addAssignment();">
92+
<button
93+
v-if="categoryWeighting"
94+
@click="addAssignment();"
95+
>
9196
Add Assignment
9297
</button>
9398
</div>
@@ -133,7 +138,7 @@ export default {
133138
}
134139
let missing = 0;
135140
for (var cat in catmap) {
136-
if (grade[cat] == null) {
141+
if (grade[cat] === undefined || grade[cat] === null || grade[cat].every((element) => element === -1)) {
137142
if (catmap[cat].weighting !== "") {
138143
missing += catmap[cat].weighting;
139144
}
@@ -142,11 +147,15 @@ export default {
142147
let percent = 0;
143148
for (cat in grade) {
144149
let sum = 0;
150+
let grade_count = 0;
145151
for (i = 0; i < grade[cat].length; i++) {
146-
sum += grade[cat][i];
152+
if (grade[cat][i] !== -1) {
153+
sum += grade[cat][i];
154+
grade_count++;
155+
}
147156
}
148-
if (catmap[cat].weighting !== "") {
149-
percent += sum / grade[cat].length * catmap[cat].weighting;
157+
if (catmap[cat].weighting !== "" && grade_count !== 0) {
158+
percent += (sum / grade_count) * catmap[cat].weighting;
150159
}
151160
}
152161
if (missing === 100) {
@@ -166,6 +175,9 @@ export default {
166175
}
167176
}
168177
},
178+
updateCategories (categories) {
179+
this.categories = categories;
180+
},
169181
changeCategory (oc, nc) {
170182
for (var i = 0; i < this.assignments.length; i++) {
171183
if (this.assignments[i].category === oc) {

0 commit comments

Comments
 (0)