Add class-specific driver training profiles and metadata
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
splitTrainingStints,
|
||||
syncTrainingLedger,
|
||||
} from "../src/training_logic.js";
|
||||
import { getDriverProfileGroups } from "../src/driver_profile_logic.js";
|
||||
|
||||
function createUid() {
|
||||
let index = 0;
|
||||
@@ -109,6 +110,72 @@ test("driver statistics remain isolated and aggregate days and sessions", () =>
|
||||
assert.equal(stats.dailySummaries[1].laps, 2);
|
||||
});
|
||||
|
||||
test("one driver profile combines transponders within a class but keeps 2WD and 4WD separate", () => {
|
||||
const state = {
|
||||
drivers: [
|
||||
{ id: "driver_2wd_a", name: "Same Driver", profileId: "profile_same", classId: "class_2wd" },
|
||||
{ id: "driver_2wd_b", name: "Same Driver", profileId: "profile_same", classId: "class_2wd" },
|
||||
{ id: "driver_4wd", name: "Same Driver", profileId: "profile_same", classId: "class_4wd" },
|
||||
],
|
||||
training: {
|
||||
ledger: [
|
||||
{ driverId: "driver_2wd_a", sessionId: "practice", timestamp: 10_000, lapMs: 18_000 },
|
||||
{ driverId: "driver_2wd_b", sessionId: "practice", timestamp: 30_000, lapMs: 17_500 },
|
||||
{ driverId: "driver_4wd", sessionId: "practice", timestamp: 50_000, lapMs: 15_000 },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const twoWheelDrive = buildDriverTrainingStats(state, "profile_same", "class_2wd");
|
||||
const fourWheelDrive = buildDriverTrainingStats(state, "profile_same", "class_4wd");
|
||||
|
||||
assert.equal(twoWheelDrive.totalLaps, 2);
|
||||
assert.equal(twoWheelDrive.bestLapMs, 17_500);
|
||||
assert.equal(fourWheelDrive.totalLaps, 1);
|
||||
assert.equal(fourWheelDrive.bestLapMs, 15_000);
|
||||
});
|
||||
|
||||
test("legacy same-name entries share a profile while an explicit profile can remain separate", () => {
|
||||
const groups = getDriverProfileGroups({
|
||||
drivers: [
|
||||
{ id: "legacy_2wd", name: "Test Driver", classId: "2wd", club: "JMK RB", country: "Sverige" },
|
||||
{ id: "legacy_4wd", name: " test driver ", classId: "4wd" },
|
||||
{ id: "separate", name: "Test Driver", profileId: "profile_other", classId: "2wd" },
|
||||
],
|
||||
});
|
||||
|
||||
assert.equal(groups.length, 2);
|
||||
assert.equal(groups.find((group) => group.id.startsWith("legacy:"))?.drivers.length, 2);
|
||||
assert.equal(groups.find((group) => group.id.startsWith("legacy:"))?.club, "JMK RB");
|
||||
assert.equal(groups.find((group) => group.id.startsWith("legacy:"))?.country, "Sverige");
|
||||
assert.equal(groups.find((group) => group.id === "profile_other")?.drivers.length, 1);
|
||||
});
|
||||
|
||||
test("active practice profile statistics include only linked entries in the selected class", () => {
|
||||
const state = {
|
||||
activeSessionId: "practice",
|
||||
drivers: [
|
||||
{ id: "two_a", name: "Driver", profileId: "profile", classId: "2wd" },
|
||||
{ id: "two_b", name: "Driver", profileId: "profile", classId: "2wd" },
|
||||
{ id: "four", name: "Driver", profileId: "profile", classId: "4wd" },
|
||||
],
|
||||
sessions: [{ id: "practice", name: "Open", type: "open_practice", status: "running", startedAt: 1_000 }],
|
||||
resultsBySession: {
|
||||
practice: {
|
||||
passings: [
|
||||
{ driverId: "two_a", timestamp: 20_000, lapMs: 18_000, validLap: true },
|
||||
{ driverId: "two_b", timestamp: 39_000, lapMs: 17_500, validLap: true },
|
||||
{ driverId: "four", timestamp: 55_000, lapMs: 15_000, validLap: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const stats = buildDriverActivePracticeStats(state, "profile", 60_000, "2wd");
|
||||
assert.equal(stats.laps, 2);
|
||||
assert.equal(stats.bestLapMs, 17_500);
|
||||
});
|
||||
|
||||
test("active practice stats include only the selected driver's current valid laps", () => {
|
||||
const startedAt = 10_000;
|
||||
const state = {
|
||||
|
||||
Reference in New Issue
Block a user