Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoring corrections #44

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/lib/utils/parse-lap-time.ts
Original file line number Diff line number Diff line change
@@ -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}$/));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "N/A"]}`
)
);
const results = allSeasonSubsessions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "N/A"]}`
)
);
const subsessions = allSeasonSubsessions.filter((v) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "N/A"]}`
)
);
const subsessionsWithoutResult = await db
Expand Down
2 changes: 1 addition & 1 deletion src/pages/user/[id]/subsessions/by-track/[trackSlug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/pages/user/[id]/subsessions/by-year/[year].astro
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/pages/user/[id]/subsessions/index.astro
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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", "N/A"]}`
)
);
const subsessionsWithoutResult = await db
.select()
.from(Subsession)
Expand Down
Loading