From d33934863de7beabf37144decd7c6e0dbf981333 Mon Sep 17 00:00:00 2001 From: Shinsina Date: Fri, 19 Apr 2024 14:07:19 -0500 Subject: [PATCH 1/3] Correct Race Results to return "main event" result --- .../car-class/[carClassId]/index.astro | 3 ++- .../car-class/[carClassId]/season-summary.astro | 3 ++- .../subsessions/by-car-class/[carClassId].astro | 3 ++- .../[id]/subsessions/by-track/[trackSlug].astro | 2 +- .../user/[id]/subsessions/by-year/[year].astro | 12 ++++++++++-- src/pages/user/[id]/subsessions/index.astro | 17 +++++++++++++++-- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro index 208cfde..8695072 100644 --- a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro +++ b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro @@ -39,7 +39,8 @@ const allSeasonRaceResultsForUser = await db .where( and( eq(SubsessionRaceResults.cust_id, Number(id)), - eq(SubsessionRaceResults.car_class_id, Number(carClassId)) + eq(SubsessionRaceResults.car_class_id, Number(carClassId)), + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` ) ); const results = allSeasonSubsessions diff --git a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro index 2575913..c11fe83 100644 --- a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro +++ b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro @@ -40,7 +40,8 @@ const allSeasonRaceResultsForUser = await db .where( and( eq(SubsessionRaceResults.cust_id, Number(id)), - eq(SubsessionRaceResults.car_class_id, Number(carClassId)) + eq(SubsessionRaceResults.car_class_id, Number(carClassId)), + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` ) ); const subsessions = allSeasonSubsessions.filter((v) => diff --git a/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro b/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro index 81919c9..83f2630 100644 --- a/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro +++ b/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro @@ -41,7 +41,8 @@ const subsessionRaceResults = await db .where( and( eq(SubsessionRaceResults.cust_id, Number(id)), - eq(SubsessionRaceResults.car_class_id, Number(carClassId)) + eq(SubsessionRaceResults.car_class_id, Number(carClassId)), + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` ) ); const subsessionsWithoutResult = await db diff --git a/src/pages/user/[id]/subsessions/by-track/[trackSlug].astro b/src/pages/user/[id]/subsessions/by-track/[trackSlug].astro index eef54c6..3076151 100644 --- a/src/pages/user/[id]/subsessions/by-track/[trackSlug].astro +++ b/src/pages/user/[id]/subsessions/by-track/[trackSlug].astro @@ -80,7 +80,7 @@ const subsessionRaceResults = await db .from(SubsessionRaceResults) .where( // @ts-ignore - sql`${SubsessionRaceResults.cust_id} IS ${id} AND ${SubsessionRaceResults.subsession_id} IN ${subsessionsWithoutResult.filter((subsession) => subsession.track?.track_name === trackName && subsession.track?.config_name === configName).map((subsessionWithoutResult) => subsessionWithoutResult.subsession_id)}` + sql`${SubsessionRaceResults.cust_id} IS ${id} AND ${SubsessionRaceResults.subsession_id} IN ${subsessionsWithoutResult.filter((subsession) => subsession.track?.track_name === trackName && subsession.track?.config_name === configName).map((subsessionWithoutResult) => subsessionWithoutResult.subsession_id)} AND ${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` ); const subsessions = subsessionsWithoutResult diff --git a/src/pages/user/[id]/subsessions/by-year/[year].astro b/src/pages/user/[id]/subsessions/by-year/[year].astro index c6e9bf6..2784474 100644 --- a/src/pages/user/[id]/subsessions/by-year/[year].astro +++ b/src/pages/user/[id]/subsessions/by-year/[year].astro @@ -1,5 +1,13 @@ --- -import { db, eq, desc, sql, SubsessionRaceResults, Subsession } from "astro:db"; +import { + db, + desc, + eq, + and, + sql, + Subsession, + SubsessionRaceResults, +} from "astro:db"; import SubsessionsLayout from "$lib/layouts/subsessions.astro"; import userIds from "$lib/utils/user-ids"; export async function getStaticPaths() { @@ -39,7 +47,7 @@ const subsessionRaceResults = await db .select() .from(SubsessionRaceResults) .where( - sql`${SubsessionRaceResults.cust_id} IS ${id} AND ${SubsessionRaceResults.subsession_id} IN ${subsessionsWithoutResult.map((subsessionWithoutResult) => subsessionWithoutResult.subsession_id)}` + sql`${SubsessionRaceResults.cust_id} IS ${id} AND ${SubsessionRaceResults.subsession_id} IN ${subsessionsWithoutResult.map((subsessionWithoutResult) => subsessionWithoutResult.subsession_id)} AND ${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` ); const subsessions = subsessionsWithoutResult diff --git a/src/pages/user/[id]/subsessions/index.astro b/src/pages/user/[id]/subsessions/index.astro index 3c28749..5693144 100644 --- a/src/pages/user/[id]/subsessions/index.astro +++ b/src/pages/user/[id]/subsessions/index.astro @@ -1,5 +1,13 @@ --- -import { db, desc, eq, sql, Subsession, SubsessionRaceResults } from "astro:db"; +import { + db, + desc, + eq, + and, + sql, + Subsession, + SubsessionRaceResults, +} from "astro:db"; import SubsessionsLayout from "$lib/layouts/subsessions.astro"; import userIds from "$lib/utils/user-ids"; export function getStaticPaths() { @@ -11,7 +19,12 @@ const seoDescription = `Subsessions page for user ID: ${id}`; const subsessionRaceResults = await db .select() .from(SubsessionRaceResults) - .where(eq(SubsessionRaceResults.cust_id, Number(id))); + .where( + and( + eq(SubsessionRaceResults.cust_id, Number(id)), + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` + ) + ); const subsessionsWithoutResult = await db .select() .from(Subsession) From 4c1b9c41ddaafd93f332c046057cc7a4edf7ced9 Mon Sep 17 00:00:00 2001 From: Shinsina Date: Fri, 19 Apr 2024 14:48:07 -0500 Subject: [PATCH 2/3] Simplify and correct parse-lap-time utility, corrects calc --- src/lib/utils/parse-lap-time.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/lib/utils/parse-lap-time.ts b/src/lib/utils/parse-lap-time.ts index 1b23ba5..13a1de6 100644 --- a/src/lib/utils/parse-lap-time.ts +++ b/src/lib/utils/parse-lap-time.ts @@ -1,21 +1,6 @@ export default (lap: number): string => { const ingestedLap = String(lap); - const placeDecimal = () => { - switch (ingestedLap.length) { - case 1: - return `0.000${ingestedLap}`; - case 2: - return `0.00${ingestedLap}`; - case 3: - return `0.0${ingestedLap}`; - case 4: - return `0.${ingestedLap}`; - default: - const decimal = ingestedLap.match(/[0-9]{4}$/); - return ingestedLap.replace(String(decimal), `.${decimal}`); - } - }; - const withDecimal = lap > 0 ? placeDecimal() : ingestedLap; + const withDecimal = lap > 0 ? String((lap / 10000).toFixed(4)) : ingestedLap; const [priorToDecimal, _] = withDecimal.split("."); if (priorToDecimal.length > 2) { const seconds = String(priorToDecimal.match(/[0-9]{2}$/)); From b2dad1c8ea2acecfd6bf167164bc52905e7306b7 Mon Sep 17 00:00:00 2001 From: Shinsina Date: Fri, 19 Apr 2024 15:06:16 -0500 Subject: [PATCH 3/3] Include N/A in simsession_name --- .../[id]/season/[seasonId]/car-class/[carClassId]/index.astro | 2 +- .../[seasonId]/car-class/[carClassId]/season-summary.astro | 2 +- src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro | 2 +- src/pages/user/[id]/subsessions/index.astro | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro index 8695072..b9d0ae3 100644 --- a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro +++ b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/index.astro @@ -40,7 +40,7 @@ const allSeasonRaceResultsForUser = await db and( eq(SubsessionRaceResults.cust_id, Number(id)), eq(SubsessionRaceResults.car_class_id, Number(carClassId)), - sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE", "N/A"]}` ) ); const results = allSeasonSubsessions diff --git a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro index c11fe83..7f215b2 100644 --- a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro +++ b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro @@ -41,7 +41,7 @@ const allSeasonRaceResultsForUser = await db and( eq(SubsessionRaceResults.cust_id, Number(id)), eq(SubsessionRaceResults.car_class_id, Number(carClassId)), - sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE", "N/A"]}` ) ); const subsessions = allSeasonSubsessions.filter((v) => diff --git a/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro b/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro index 83f2630..2bfe840 100644 --- a/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro +++ b/src/pages/user/[id]/subsessions/by-car-class/[carClassId].astro @@ -42,7 +42,7 @@ const subsessionRaceResults = await db and( eq(SubsessionRaceResults.cust_id, Number(id)), eq(SubsessionRaceResults.car_class_id, Number(carClassId)), - sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE", "N/A"]}` ) ); const subsessionsWithoutResult = await db diff --git a/src/pages/user/[id]/subsessions/index.astro b/src/pages/user/[id]/subsessions/index.astro index 5693144..28fb7fe 100644 --- a/src/pages/user/[id]/subsessions/index.astro +++ b/src/pages/user/[id]/subsessions/index.astro @@ -22,7 +22,7 @@ const subsessionRaceResults = await db .where( and( eq(SubsessionRaceResults.cust_id, Number(id)), - sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE"]}` + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE", "N/A"]}` ) ); const subsessionsWithoutResult = await db