Compare commits

...

5 Commits

Author SHA1 Message Date
c732ff2014 Leaderboard: Implement first primitive leaderboard page (only total points)
All checks were successful
Build Formula11 Docker Image / pocketbase-docker (push) Successful in 29s
2025-03-23 17:17:07 +01:00
7fb38874d9 Leaderboard: Fetch points data 2025-03-23 17:16:51 +01:00
ce2c7af35c Env: Add sqlite/sqlitebrowser to flake 2025-03-23 17:16:30 +01:00
9ec0bf0bd5 Lib: Add fetchers for RacePickPoints and RacePickPointsAcc 2025-03-23 17:16:10 +01:00
f249205cd8 Lib: Add RacePickPoints and RacePickPointsAcc to schema 2025-03-23 17:15:59 +01:00
5 changed files with 87 additions and 1 deletions

View File

@ -81,6 +81,9 @@
packages = with pkgs; [ packages = with pkgs; [
nodejs_23 nodejs_23
pocketbase pocketbase
sqlite # For sqlite console
sqlitebrowser # To check low-level pocketbase data
]; ];
# Use $1 for positional args # Use $1 for positional args
@ -88,7 +91,7 @@
{ {
name = "pb"; name = "pb";
help = "Serve PocketBase"; help = "Serve PocketBase";
command = "pocketbase serve --http 192.168.86.50:8090"; command = "pocketbase serve --http 192.168.86.50:8090 --dev";
} }
{ {
name = "dev"; name = "dev";

View File

@ -7,6 +7,8 @@ import type {
Hottake, Hottake,
Race, Race,
RacePick, RacePick,
RacePickPoints,
RacePickPointsAcc,
RaceResult, RaceResult,
SeasonPick, SeasonPick,
SeasonPickedUser, SeasonPickedUser,
@ -261,3 +263,29 @@ export const fetch_seasonpickedusers = async (
return seasonpickedusers; return seasonpickedusers;
}; };
/**
* Fetch all [RacePickPoints] from the database
*/
export const fetch_racepickpoints = async (
fetch: (_: any) => Promise<Response>,
): Promise<RacePickPoints[]> => {
const racepickpoints: RacePickPoints[] = await pb
.collection("racepickpoints")
.getFullList({ fetch: fetch });
return racepickpoints;
};
/**
* Fetch all [RacePickPointsAcc] from the database, ordered descendingly by total points.
*/
export const fetch_racepickpointsacc = async (
fetch: (_: any) => Promise<Response>,
): Promise<RacePickPointsAcc[]> => {
const racepickpointsacc: RacePickPointsAcc[] = await pb
.collection("racepickpointsacc")
.getFullList({ fetch: fetch });
return racepickpointsacc;
};

View File

@ -127,3 +127,21 @@ export interface SeasonPickedUser {
admin: boolean; admin: boolean;
picked: string | null; picked: string | null;
} }
// Points Data
export interface RacePickPoints {
id: string;
user: string;
step: number;
pxx_points: number;
dnf_points: number;
}
export interface RacePickPointsAcc {
id: string;
user: string;
total_pxx_points: number;
total_dnf_points: number;
total_points: number;
}

View File

@ -1,3 +1,28 @@
<script lang="ts">
import { Table, type TableColumn } from "$lib/components";
import { get_by_value } from "$lib/database";
import type { PageData } from "./$types";
let { data }: { data: PageData } = $props();
const leaderboard_columns: TableColumn[] = $derived([
{
data_value_name: "user",
label: "User",
valuefun: async (value: string): Promise<string> =>
get_by_value(await data.users, "id", value)?.firstname ?? "Invalid",
},
{
data_value_name: "total_points",
label: "Points",
},
]);
</script>
<svelte:head> <svelte:head>
<title>Formula 11 - Leaderboard</title> <title>Formula 11 - Leaderboard</title>
</svelte:head> </svelte:head>
{#await Promise.all( [data.users, data.racepickpoints, data.racepickpointsacc], ) then [users, racepickpoints, racepickpointsacc]}
<Table data={racepickpointsacc} columns={leaderboard_columns} />
{/await}

View File

@ -0,0 +1,12 @@
import { fetch_users, fetch_racepickpoints, fetch_racepickpointsacc } from "$lib/fetch";
import type { PageLoad } from "../$types";
export const load: PageLoad = async ({ fetch, depends }) => {
depends("data:users", "data:raceresults");
return {
users: fetch_users(fetch),
racepickpoints: fetch_racepickpoints(fetch),
racepickpointsacc: fetch_racepickpointsacc(fetch),
};
};