From e5bcc0f1dd5e94ee126a4a05dc2f101a4401c53b Mon Sep 17 00:00:00 2001 From: Samuel Gunter Date: Fri, 22 Mar 2024 02:33:02 -0500 Subject: [PATCH] feat: actually sum for duplicate semesters (different uniques) --- src/views/lib/database/queryDistribution.ts | 27 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/views/lib/database/queryDistribution.ts b/src/views/lib/database/queryDistribution.ts index 6406e1ba6..2ce8f14a8 100644 --- a/src/views/lib/database/queryDistribution.ts +++ b/src/views/lib/database/queryDistribution.ts @@ -118,10 +118,29 @@ export async function querySemesterDistribution(course: Course, semester: Semest throw new NoDataError(course); } - let row: Required = {} as Required; - res.columns.forEach((col, i) => { - row[col as keyof CourseSQLRow] = res.values[0]![i]! as never; - }); + const row: Required = {} as Required; + 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,