Skip to content

Commit eb7abe4

Browse files
committed
fix seeAssignment if there is only one category
1 parent 38b97fd commit eb7abe4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/content_script/scores/scoreTools/SingleAssignment.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
curCatId: number = curCategoryId,
8585
gradeManager: GradeManager,
8686
) {
87-
console.log("curCalc", hGrade, hWeight, percent, curCatId, gradeManager);
8887
let grade = 0;
8988
let curCategory: Category | null = gradeManager.getCategoryById(curCatId);
9089
let curCategoryId = curCatId;
@@ -122,7 +121,7 @@
122121
otherWeightSum += category.weight;
123122
otherGrade += curGrade * category.weight;
124123
}
125-
otherGrade /= otherWeightSum;
124+
if (otherWeightSum != 0) otherGrade /= otherWeightSum;
126125
curCategoryGrade *= curCategoryWeightSum;
127126
128127
grade =
@@ -499,8 +498,10 @@
499498
Your grade is {convertPercentCutoffToGrade(
500499
newFinalPercent,
501500
)}{newFinalPercent !== SpecialGrade.INC
502-
? ` with a percentage of ${newFinalPercent.toFixed(2)}%.`
503-
: "."}
501+
? ` with a percentage of ${newFinalPercent.toFixed(2)}%`
502+
: ""}{seeAssignment
503+
? " without the 'See all possibilities' assignment"
504+
: ""}.
504505
{/if}
505506
</div>
506507
{/if}

src/models/grades.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,27 @@ export class GradeManager {
195195
public calculateGradePercentage(): number | SpecialGrade.INC | SpecialGrade.INVALID {
196196
if (!this.validWeights()) return SpecialGrade.INVALID;
197197
let totalGrade = 0;
198+
198199
for (let category of this.categories) {
199-
if (this.getSeeAssignment()?.category.id == category.id) continue;
200-
let categoryGrade = 0;
201200
let categoryAssignments = this.getAssignmentsByCategory(category);
201+
if (this.getSeeAssignment()?.category.id == category.id && categoryAssignments.length == 1) continue;
202+
let categoryGrade = 0;
202203
let categorySumOfWeights = this.sumOfWeightsInCategory(category);
203204
for (let assignment of categoryAssignments) {
204205
if (assignment.see) continue;
205206
if (assignment.grade == "INC") return SpecialGrade.INC;
206-
categoryGrade += gradeToPercent[assignment.grade] * (assignment.weight / 100);
207+
categoryGrade += gradeToPercent[assignment.grade] * (assignment.weight);
207208
}
208-
if (categoryGrade != 0 && this.calcedTotalWeight != 0) totalGrade += (categoryGrade / categorySumOfWeights) * 100 * (category.weight / this.calcedTotalWeight);
209+
if (categoryGrade != 0 && this.calcedTotalWeight != 0) {
210+
totalGrade += (categoryGrade / categorySumOfWeights) * (category.weight / this.calcedTotalWeight)
211+
};
209212
}
210213
return totalGrade;
211214
}
212215

213216
get calcedTotalWeight(): number {
214217
let seeAssignment = this.getSeeAssignment();
215-
if (seeAssignment) return this.totalWeight - seeAssignment.category.weight;
218+
if (seeAssignment && this.getAssignmentsByCategory(seeAssignment.category).length <= 1) return this.totalWeight - seeAssignment.category.weight;
216219
return this.totalWeight;
217220
}
218221

0 commit comments

Comments
 (0)