Skip to content

Commit

Permalink
Swap Mean GPA for Median GPA
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiramTadepalli committed Jan 14, 2025
1 parent c9328bf commit e60afee
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ function calculateGrades(grades: GradesData, academicSessions?: string[]) {
const GPALookup = [
4, 4, 3.67, 3.33, 3, 2.67, 2.33, 2, 1.67, 1.33, 1, 0.67, 0,
];
let gpa = -1;
let mean_gpa = -1;
if (total !== 0) {
gpa =
mean_gpa =
GPALookup.reduce(
(accumulator, currentValue, index) =>
accumulator + currentValue * grade_distribution[index],
Expand All @@ -160,8 +160,20 @@ function calculateGrades(grades: GradesData, academicSessions?: string[]) {
(total - grade_distribution[grade_distribution.length - 1]);
}

let median_gpa = -1;
let medianIndex = -1;
if (total != 0) {
let i = Math.floor(total / 2);
while (i > 0) {
medianIndex++;
i -= grade_distribution[medianIndex];
}
median_gpa = GPALookup[medianIndex];
}

return {
gpa: gpa,
// mean_gpa: mean_gpa,
gpa: median_gpa,
total: total,
grade_distribution: grade_distribution,
};
Expand Down

0 comments on commit e60afee

Please sign in to comment.