Skip to content

Commit

Permalink
fix : handle sub-subjects when thay have 0 coef
Browse files Browse the repository at this point in the history
  • Loading branch information
saumon-brule committed Oct 7, 2024
1 parent 615d6c0 commit d5f9a99
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/utils/gradesTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export function safeParseFloat(value) {
export function calcAverage(list) {
let average = 0;
let coef = 0;
for (let i of list) {
list.forEach(i => {
if ((i.isSignificant ?? true) && !isNaN(i.value)) {
coef += i.coef;
}
}
})

const noCoef = !coef;

for (let i of list) {
list.forEach(i => {
if ((i.isSignificant ?? true) && !isNaN(i.value)) {
if (noCoef) {
average += (i.value * 20 / i.scale);
Expand All @@ -44,14 +44,15 @@ export function calcAverage(list) {
average += (i.value * 20 / i.scale) * i.coef;
}
}
}
})

if (coef > 0 && list.length > 0) {
return Math.ceil(average / coef * 100) / 100;
return Math.round(average / coef * 100) / 100;
} else {
return "N/A"
}
}

export function calcClassAverage(list) {
let average = 0;
let coef = 0;
Expand Down Expand Up @@ -132,7 +133,7 @@ export function calcGeneralAverage(period) {
for (let validKey of validKeys) {
sum += period.subjects[validKey].coef;
}
coefMultiplicator = period.subjects[subjectCode].coef / sum;
coefMultiplicator = sum ? (period.subjects[subjectCode].coef / sum) : 0; // Handle the case where the sum of subSubject coef is 0
}
list.push({
value: currentSubject.average ?? 0,
Expand Down

0 comments on commit d5f9a99

Please sign in to comment.