Skip to content

Commit

Permalink
feat: actually sum for duplicate semesters (different uniques) (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samathingamajig authored Mar 26, 2024
1 parent 8e79d6a commit d3f64ec
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/views/lib/database/queryDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,29 @@ export async function querySemesterDistribution(course: Course, semester: Semest
throw new NoDataError(course);
}

let row: Required<CourseSQLRow> = {} as Required<CourseSQLRow>;
res.columns.forEach((col, i) => {
row[col as keyof CourseSQLRow] = res.values[0]![i]! as never;
});
const row: Required<CourseSQLRow> = {} as Required<CourseSQLRow>;
for (let i = 0; i < res.columns.length; i++) {
const col = res.columns[i] as keyof CourseSQLRow;
switch (col) {
case 'A':
case 'A_Minus':
case 'B_Plus':
case 'B':
case 'B_Minus':
case 'C_Plus':
case 'C':
case 'C_Minus':
case 'D_Plus':
case 'D':
case 'D_Minus':
case 'F':
case 'Other':
row[col] = res.values.reduce((acc, cur) => acc + (cur[i] as number), 0) as never;
break;
default:
row[col] = res.columns[i]![0]! as never;
}
}

return {
A: row.A,
Expand Down

0 comments on commit d3f64ec

Please sign in to comment.