Compare commits

...

2 Commits

Author SHA1 Message Date
5cf7974a79 Seasonpicks: Mark correct and incorrect picks (ugly af/quite appalling)
All checks were successful
Build Formula11 Docker Image / pocketbase-docker (push) Successful in 37s
2025-12-26 21:16:21 +01:00
9d83673a90 Pocketbase: Update schema (add seasonpicks points calc) 2025-12-26 20:25:49 +01:00
3 changed files with 385 additions and 12 deletions

View File

@ -1570,6 +1570,157 @@
"indexes": [], "indexes": [],
"system": false "system": false
}, },
{
"id": "pbc_2622411661",
"listRule": "",
"viewRule": "",
"createRule": "@request.auth.id != \"\" &&\n@request.auth.admin = true",
"updateRule": "@request.auth.id != \"\" &&\n@request.auth.admin = true",
"deleteRule": null,
"name": "seasonpickresults",
"type": "base",
"fields": [
{
"autogeneratePattern": "[a-z0-9]{15}",
"hidden": false,
"id": "text3208210256",
"max": 15,
"min": 15,
"name": "id",
"pattern": "^[a-z0-9]+$",
"presentable": false,
"primaryKey": true,
"required": true,
"system": true,
"type": "text"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1736455494",
"hidden": false,
"id": "relation1202818397",
"maxSelect": 999,
"minSelect": 0,
"name": "correcthottake",
"presentable": false,
"required": false,
"system": false,
"type": "relation"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1967373549",
"hidden": false,
"id": "relation553681702",
"maxSelect": 1,
"minSelect": 0,
"name": "wdcwinner",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1568971955",
"hidden": false,
"id": "relation734366271",
"maxSelect": 1,
"minSelect": 0,
"name": "wccwinner",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1967373549",
"hidden": false,
"id": "relation3896658669",
"maxSelect": 999,
"minSelect": 0,
"name": "mostovertakes",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1967373549",
"hidden": false,
"id": "relation3731883446",
"maxSelect": 999,
"minSelect": 0,
"name": "mostdnfs",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"hidden": false,
"id": "number1147572598",
"max": 24,
"min": 0,
"name": "doohanstarts",
"onlyInt": false,
"presentable": false,
"required": true,
"system": false,
"type": "number"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1967373549",
"hidden": false,
"id": "relation1938994230",
"maxSelect": 10,
"minSelect": 10,
"name": "teamwinners",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1967373549",
"hidden": false,
"id": "relation3915334665",
"maxSelect": 999,
"minSelect": 3,
"name": "podiums",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"hidden": false,
"id": "autodate2990389176",
"name": "created",
"onCreate": true,
"onUpdate": false,
"presentable": false,
"system": false,
"type": "autodate"
},
{
"hidden": false,
"id": "autodate3332085495",
"name": "updated",
"onCreate": true,
"onUpdate": true,
"presentable": false,
"system": false,
"type": "autodate"
}
],
"indexes": [],
"system": false
},
{ {
"id": "pbc_1473742649", "id": "pbc_1473742649",
"listRule": "@request.auth.id != \"\" // If you know what you're doing you can easily request all picks here. But If I restrict this to the current user, the subscription events are blocked...", "listRule": "@request.auth.id != \"\" // If you know what you're doing you can easily request all picks here. But If I restrict this to the current user, the subscription events are blocked...",
@ -2677,6 +2828,128 @@
"system": false, "system": false,
"viewQuery": "-- This query returns users with an extra field \"picked\", depending on if they made their season picks yet\nSELECT\n user.id, user.username, user.firstname, user.avatar, user.admin,\n -- Generate the additional field \"picked\" that contains the season pick ID if the user occurs in the seasonpicks and false otherwise\n (CASE\n WHEN sp.user IS NOT NULL THEN sp.id\n ELSE NULL\n END) AS picked\nFROM\n users user\n-- Join users and seasonpicks (user ids that are missing from this join will receive picked=false)\nLEFT JOIN\n seasonpicks sp ON user.id = sp.user\nORDER BY user.id ASC;" "viewQuery": "-- This query returns users with an extra field \"picked\", depending on if they made their season picks yet\nSELECT\n user.id, user.username, user.firstname, user.avatar, user.admin,\n -- Generate the additional field \"picked\" that contains the season pick ID if the user occurs in the seasonpicks and false otherwise\n (CASE\n WHEN sp.user IS NOT NULL THEN sp.id\n ELSE NULL\n END) AS picked\nFROM\n users user\n-- Join users and seasonpicks (user ids that are missing from this join will receive picked=false)\nLEFT JOIN\n seasonpicks sp ON user.id = sp.user\nORDER BY user.id ASC;"
}, },
{
"id": "pbc_945270645",
"listRule": null,
"viewRule": null,
"createRule": null,
"updateRule": null,
"deleteRule": null,
"name": "seasonpickpoints",
"type": "view",
"fields": [
{
"autogeneratePattern": "",
"hidden": false,
"id": "text3208210256",
"max": 0,
"min": 0,
"name": "id",
"pattern": "^[a-z0-9]+$",
"presentable": false,
"primaryKey": true,
"required": true,
"system": true,
"type": "text"
},
{
"cascadeDelete": false,
"collectionId": "pbc_1736455494",
"hidden": false,
"id": "_clone_4tZb",
"maxSelect": 1,
"minSelect": 0,
"name": "user",
"presentable": false,
"required": true,
"system": false,
"type": "relation"
},
{
"hidden": false,
"id": "json368448629",
"maxSize": 1,
"name": "hottake_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json3943774131",
"maxSize": 1,
"name": "wdc_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json2406505082",
"maxSize": 1,
"name": "wcc_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json1467527923",
"maxSize": 1,
"name": "doohan_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json1170173829",
"maxSize": 1,
"name": "overtakes_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json182958108",
"maxSize": 1,
"name": "dnfs_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json1497196675",
"maxSize": 1,
"name": "teamwinner_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
},
{
"hidden": false,
"id": "json2424735323",
"maxSize": 1,
"name": "podium_points",
"presentable": false,
"required": false,
"system": false,
"type": "json"
}
],
"indexes": [],
"system": false,
"viewQuery": "SELECT\n sp.id,\n sp.user,\n \n (CASE\n -- Correct hottake\n WHEN sr.correcthottake LIKE '[%\"' || sp.user || '\"%]' THEN 10\n ELSE 0 \n END) AS hottake_points,\n\n (CASE\n -- Correct WDC\n WHEN sp.wdcwinner = sr.wdcwinner THEN 10\n ELSE 0\n END) AS wdc_points,\n\n (CASE\n -- Correct WCC\n WHEN sp.wccwinner = sr.wccwinner THEN 10\n ELSE 0\n END) AS wcc_points,\n\n (CASE\n WHEN ABS(sp.doohanstarts - sr.doohanstarts)\n = MIN(ABS(sp.doohanstarts - sr.doohanstarts)) OVER ()\n THEN 5\n ELSE 0\n END) AS doohan_points,\n\n (CASE\n -- Most Overtakes\n WHEN sr.mostovertakes LIKE '[%\"' || sp.mostovertakes || '\"%]' THEN 10\n ELSE 0\n END) AS overtakes_points,\n\n (CASE\n -- Most DNFs\n WHEN sr.mostdnfs LIKE '[%\"' || sp.mostdnfs || '\"%]' THEN 10\n ELSE 0\n END) AS dnfs_points,\n\n (SELECT SUM(CASE\n -- Teamwinners\n WHEN EXISTS (SELECT 1\n FROM json_each(sr.teamwinners) srtw\n WHERE srtw.value = sptw.value\n ) THEN 3\n ELSE -3\n END)\n FROM json_each(sp.teamwinners) sptw) AS teamwinner_points,\n\n (SELECT SUM(CASE\n -- Podiums\n WHEN EXISTS (SELECT 1\n FROM json_each(sr.podiums) srp\n WHERE srp.value = spp.value\n ) THEN 3\n ELSE -2\n END)\n FROM json_each(sp.podiums) spp) AS podium_points\n\nFROM seasonpicks sp\n-- CROSS JOIN: Cartesian Product\nCROSS JOIN seasonpickresults sr;"
},
{ {
"id": "pbc_575507001", "id": "pbc_575507001",
"listRule": "", "listRule": "",

View File

@ -7,7 +7,14 @@
type ModalStore, type ModalStore,
} from "@skeletonlabs/skeleton"; } from "@skeletonlabs/skeleton";
import type { PageData } from "./$types"; import type { PageData } from "./$types";
import type { Driver, Hottake, SeasonPick, SeasonPickedUser, User } from "$lib/schema"; import type {
Driver,
Hottake,
SeasonPick,
SeasonPickedUser,
SeasonPickResult,
User,
} from "$lib/schema";
import { ChequeredFlagIcon, LazyImage } from "$lib/components"; import { ChequeredFlagIcon, LazyImage } from "$lib/components";
import { import {
get_by_value, get_by_value,
@ -41,6 +48,29 @@
modalStore.trigger(modalSettings); modalStore.trigger(modalSettings);
}; };
// Await promises
let seasonpickresult: SeasonPickResult | undefined = $state(undefined);
data.seasonpickresults.then((r: SeasonPickResult[]) => {
if (r.length === 1) {
seasonpickresult = r[0];
}
});
let correct_doohanstarts: number | undefined = $state(undefined);
Promise.all([data.seasonpickresults, data.seasonpicks]).then(
([results, picks]: [SeasonPickResult[], SeasonPick[]]) => {
if (results.length === 1) {
let result = results[0];
correct_doohanstarts = Math.min(
...picks.map((pick: SeasonPick) => {
return Math.abs(pick.doohanstarts - result.doohanstarts);
}),
);
}
},
);
// Users that have already picked the season // Users that have already picked the season
let pickedusers: Promise<SeasonPickedUser[]> = $derived.by(async () => let pickedusers: Promise<SeasonPickedUser[]> = $derived.by(async () =>
(await data.seasonpickedusers).filter( (await data.seasonpickedusers).filter(
@ -63,7 +93,7 @@
<!-- Await this here so the accordion doesn't lag when opening --> <!-- Await this here so the accordion doesn't lag when opening -->
<!-- Only show the stuff if signed in --> <!-- Only show the stuff if signed in -->
{#if $pbUser} {#if $pbUser}
{#await Promise.all( [data.drivers, data.teams, data.seasonpickedusers, pickedusers, outstandingusers], ) then [drivers, teams, currentpicked, picked, outstanding]} {#await Promise.all( [data.drivers, data.teams, data.seasonpickedusers, data.seasonpickresults, pickedusers, outstandingusers], ) then [drivers, teams, currentpicked, results, picked, outstanding]}
{@const teamwinners = data.seasonpick {@const teamwinners = data.seasonpick
? data.seasonpick.teamwinners ? data.seasonpick.teamwinners
.map((id: string) => get_by_value(drivers, "id", id) as Driver) .map((id: string) => get_by_value(drivers, "id", id) as Driver)
@ -374,16 +404,29 @@
<div class="ml-1 w-full min-w-36"> <div class="ml-1 w-full min-w-36">
<!-- Hottake --> <!-- Hottake -->
<div <div
class="mt-1 h-32 w-full overflow-y-scroll border bg-surface-200 px-1 py-2 leading-3 lg:px-2" class="mt-1 h-32 w-full overflow-y-scroll border bg-surface-200 px-1 py-2 leading-3 lg:px-2 {seasonpickresult?.correcthottake.includes(
user.id,
)
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
> >
<div class="mx-auto w-fit text-xs font-bold lg:text-sm"> <div class="mx-auto w-fit rounded-md p-1 text-xs font-bold lg:text-sm">
{hottake?.hottake ?? "?"} {hottake?.hottake ?? "?"}
</div> </div>
</div> </div>
{#if seasonpicks.length > 0} {#if seasonpicks.length > 0}
<!-- Drivers Champion --> <!-- Drivers Champion -->
<div class="mt-1 h-20 w-full border bg-surface-200 px-1 py-2 leading-3 lg:px-2"> <div
class="mt-1 h-20 w-full border bg-surface-200 px-1 py-2 leading-3 lg:px-2 {seasonpickresult?.wdcwinner ===
wdcwinner?.id
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
>
<div class="mx-auto w-fit"> <div class="mx-auto w-fit">
<!-- NOTE: The containerstyle should be 64x64, don't know why that doesn't fit... (also below) --> <!-- NOTE: The containerstyle should be 64x64, don't know why that doesn't fit... (also below) -->
<LazyImage <LazyImage
@ -398,7 +441,14 @@
</div> </div>
<!-- Constructors Champion --> <!-- Constructors Champion -->
<div class="mt-1 h-20 w-full border bg-surface-200 p-1 px-1 py-2 leading-3 lg:px-2"> <div
class="mt-1 h-20 w-full border bg-surface-200 p-1 px-1 py-2 leading-3 lg:px-2 {seasonpickresult?.wccwinner ===
wccwinner?.id
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
>
<div class="mx-auto w-fit"> <div class="mx-auto w-fit">
<LazyImage <LazyImage
src={wccwinner?.banner_url ?? get_team_banner_template(data.graphics)} src={wccwinner?.banner_url ?? get_team_banner_template(data.graphics)}
@ -412,7 +462,15 @@
</div> </div>
<!-- Most Overtakes --> <!-- Most Overtakes -->
<div class="mt-1 h-20 w-full border bg-surface-200 px-1 py-2 leading-3 lg:px-2"> <div
class="mt-1 h-20 w-full border bg-surface-200 px-1 py-2 leading-3 lg:px-2 {seasonpickresult?.mostovertakes.includes(
mostovertakes?.id ?? 'INVALID',
)
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
>
<div class="mx-auto w-fit"> <div class="mx-auto w-fit">
<LazyImage <LazyImage
src={mostovertakes?.headshot_url ?? get_driver_headshot_template(data.graphics)} src={mostovertakes?.headshot_url ?? get_driver_headshot_template(data.graphics)}
@ -428,7 +486,15 @@
</div> </div>
<!-- Most DNFs --> <!-- Most DNFs -->
<div class="mt-1 h-20 w-full border bg-surface-200 px-1 py-2 leading-3 lg:px-2"> <div
class="mt-1 h-20 w-full border bg-surface-200 px-1 py-2 leading-3 lg:px-2 {seasonpickresult?.mostdnfs.includes(
mostdnfs?.id ?? 'INVALID',
)
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
>
<div class="mx-auto w-fit"> <div class="mx-auto w-fit">
<LazyImage <LazyImage
src={mostdnfs?.headshot_url ?? get_driver_headshot_template(data.graphics)} src={mostdnfs?.headshot_url ?? get_driver_headshot_template(data.graphics)}
@ -442,7 +508,15 @@
</div> </div>
<!-- Doohan Starts --> <!-- Doohan Starts -->
<div class="mt-1 h-20 w-full border bg-surface-200 p-1 px-1 py-2 leading-3 lg:px-2"> <div
class="mt-1 h-20 w-full border bg-surface-200 p-1 px-1 py-2 leading-3 lg:px-2 {Math.abs(
(seasonpickresult?.doohanstarts ?? 0) - pick?.doohanstarts,
) === correct_doohanstarts
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
>
<div class="mx-auto w-fit text-xs lg:text-sm"> <div class="mx-auto w-fit text-xs lg:text-sm">
Jack Doohan startet <span class="font-bold">{pick?.doohanstarts ?? "?"}</span> mal. Jack Doohan startet <span class="font-bold">{pick?.doohanstarts ?? "?"}</span> mal.
</div> </div>
@ -466,7 +540,16 @@
style="color: {color}; background-color: {color};" style="color: {color}; background-color: {color};"
> >
</span> </span>
<span class="w-7 align-middle" style="line-height: 20px;"> <span
class="w-7 rounded-md align-middle {pick.teamwinners.includes(
driver.id,
) && seasonpickresult?.teamwinners.includes(driver.id)
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
style="line-height: 20px;"
>
{driver?.code} {driver?.code}
</span> </span>
</div> </div>
@ -495,7 +578,15 @@
style="color: {color}; background-color: {color};" style="color: {color}; background-color: {color};"
> >
</span> </span>
<span class="w-7 align-middle" style="line-height: 20px;"> <span
class="w-7 rounded-md align-middle {pick.podiums.includes(driver.id) &&
seasonpickresult?.podiums.includes(driver.id)
? '!bg-tertiary-500'
: seasonpickresult
? '!bg-primary-500'
: ''}"
style="line-height: 20px;"
>
{driver?.code} {driver?.code}
</span> </span>
</div> </div>

View File

@ -6,11 +6,19 @@ import {
fetch_visibleseasonpicks, fetch_visibleseasonpicks,
fetch_teams, fetch_teams,
fetch_currentrace, fetch_currentrace,
fetch_seasonpickresults,
} from "$lib/fetch"; } from "$lib/fetch";
import type { PageLoad } from "../$types"; import type { PageLoad } from "../$types";
export const load: PageLoad = async ({ fetch, depends }) => { export const load: PageLoad = async ({ fetch, depends }) => {
depends("data:teams", "data:drivers", "data:seasonpicks", "data:user", "data:users"); depends(
"data:teams",
"data:drivers",
"data:seasonpicks",
"data:user",
"data:users",
"data:seasonpickresults",
);
return { return {
teams: fetch_teams(fetch), teams: fetch_teams(fetch),
@ -19,6 +27,7 @@ export const load: PageLoad = async ({ fetch, depends }) => {
hottakes: fetch_hottakes(fetch), hottakes: fetch_hottakes(fetch),
seasonpickedusers: fetch_seasonpickedusers(fetch), seasonpickedusers: fetch_seasonpickedusers(fetch),
currentrace: fetch_currentrace(fetch), // Used for countdown currentrace: fetch_currentrace(fetch), // Used for countdown
seasonpickresults: fetch_seasonpickresults(fetch),
seasonpick: await fetch_currentseasonpick(fetch), seasonpick: await fetch_currentseasonpick(fetch),
}; };