Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Try to make events breakdown actually work
  • Loading branch information
regalijan committed Apr 11, 2024
1 parent 9cfc521 commit e92526e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions app/routes/events-team_.events-breakdown.tsx
Expand Up @@ -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<string, string>[]) {
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;",
Expand All @@ -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();
Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -102,7 +105,7 @@ export async function loader({ context }: { context: RequestContext }) {
}
}

return Object.assign(pointData, nameData);
return data;
}

export default function () {
Expand Down

0 comments on commit e92526e

Please sign in to comment.