From e92526efe87df4429c72266effcac157f1d0ce79 Mon Sep 17 00:00:00 2001 From: Regalijan Date: Thu, 11 Apr 2024 13:01:37 -0400 Subject: [PATCH] Try to make events breakdown actually work --- app/routes/events-team_.events-breakdown.tsx | 33 +++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/routes/events-team_.events-breakdown.tsx b/app/routes/events-team_.events-breakdown.tsx index 766b913..d6c60df 100644 --- a/app/routes/events-team_.events-breakdown.tsx +++ b/app/routes/events-team_.events-breakdown.tsx @@ -34,20 +34,24 @@ export async function loader({ context }: { context: RequestContext }) { status: 500, }); - const pointData: { + const data: { [k: string]: { - [p: string]: number; + fotd: number; + name: string; }; - } = {}; - - const nameData: { + } & { [k: string]: { - name: string; + [k: string]: number; }; } = {}; - for (const row of memberResults.results) - nameData[row.id as string] = { name: row.name as string }; + for (const row of memberResults.results as Record[]) { + data[row.id].fotd = 0; + data[row.id].gamenight = 0; + data[row.id].name = row.name; + data[row.id].rotw = 0; + data[row.id].qotd = 0; + } const eventsResult = await context.env.D1.prepare( "SELECT answered_at, created_by, day, month, performed_at, reached_minimum_player_count, type, year FROM events;", @@ -62,9 +66,9 @@ export async function loader({ context }: { context: RequestContext }) { const creator = row.created_by as string; const type = row.type as string; - if (!pointData[creator]) continue; + if (!data[creator]) continue; - if (row.performed_at) pointData[creator][type as string] += 10; + if (row.performed_at) data[creator][type as string] += 10; else { const now = new Date(); const currentYear = now.getUTCFullYear(); @@ -78,13 +82,12 @@ export async function loader({ context }: { context: RequestContext }) { currentYear === row.year && (row.day as number) < currentDay) ) - pointData[creator][type] -= 5; + data[creator][type] -= 5; } switch (row.type) { case "gamenight": - if (row.reached_minimum_player_count) - pointData[creator].gamenight += 10; + if (row.reached_minimum_player_count) data[creator].gamenight += 10; break; @@ -93,7 +96,7 @@ export async function loader({ context }: { context: RequestContext }) { (row.answered_at as number) - (row.performed_at as number) >= 86400000 ) - pointData[creator].rotw += 10; + data[creator].rotw += 10; break; @@ -102,7 +105,7 @@ export async function loader({ context }: { context: RequestContext }) { } } - return Object.assign(pointData, nameData); + return data; } export default function () {