Try to make events breakdown actually work
This commit is contained in:
parent
9cfc521256
commit
e92526efe8
@ -34,20 +34,24 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
status: 500,
|
status: 500,
|
||||||
});
|
});
|
||||||
|
|
||||||
const pointData: {
|
const data: {
|
||||||
[k: string]: {
|
|
||||||
[p: string]: number;
|
|
||||||
};
|
|
||||||
} = {};
|
|
||||||
|
|
||||||
const nameData: {
|
|
||||||
[k: string]: {
|
[k: string]: {
|
||||||
|
fotd: number;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
} & {
|
||||||
|
[k: string]: {
|
||||||
|
[k: string]: number;
|
||||||
|
};
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
for (const row of memberResults.results)
|
for (const row of memberResults.results as Record<string, string>[]) {
|
||||||
nameData[row.id as string] = { name: row.name as 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(
|
const eventsResult = await context.env.D1.prepare(
|
||||||
"SELECT answered_at, created_by, day, month, performed_at, reached_minimum_player_count, type, year FROM events;",
|
"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 creator = row.created_by as string;
|
||||||
const type = row.type 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 {
|
else {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const currentYear = now.getUTCFullYear();
|
const currentYear = now.getUTCFullYear();
|
||||||
@ -78,13 +82,12 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
currentYear === row.year &&
|
currentYear === row.year &&
|
||||||
(row.day as number) < currentDay)
|
(row.day as number) < currentDay)
|
||||||
)
|
)
|
||||||
pointData[creator][type] -= 5;
|
data[creator][type] -= 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (row.type) {
|
switch (row.type) {
|
||||||
case "gamenight":
|
case "gamenight":
|
||||||
if (row.reached_minimum_player_count)
|
if (row.reached_minimum_player_count) data[creator].gamenight += 10;
|
||||||
pointData[creator].gamenight += 10;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -93,7 +96,7 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
(row.answered_at as number) - (row.performed_at as number) >=
|
(row.answered_at as number) - (row.performed_at as number) >=
|
||||||
86400000
|
86400000
|
||||||
)
|
)
|
||||||
pointData[creator].rotw += 10;
|
data[creator].rotw += 10;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -102,7 +105,7 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.assign(pointData, nameData);
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user