Split- och depåstatistik är implementerad
This commit is contained in:
@@ -314,6 +314,58 @@ export function buildDriverTrainingStats(state, driverId, classId = "") {
|
||||
};
|
||||
}
|
||||
|
||||
export function buildDriverTimingChannelStats(state, driverId, classId = "") {
|
||||
const profileReferences = getTrainingDriverIds(state, driverId, classId);
|
||||
const sessions = new Map((Array.isArray(state?.sessions) ? state.sessions : []).map((session) => [String(session.id || ""), session]));
|
||||
const events = new Map((Array.isArray(state?.events) ? state.events : []).map((event) => [String(event.id || ""), event]));
|
||||
const splits = [];
|
||||
const pitStops = [];
|
||||
|
||||
Object.entries(state?.resultsBySession || {}).forEach(([sessionId, result]) => {
|
||||
const session = sessions.get(String(sessionId));
|
||||
const event = session ? events.get(String(session.eventId || "")) : null;
|
||||
(Array.isArray(result?.splits) ? result.splits : []).forEach((split) => {
|
||||
if (!profileReferences.has(String(split?.driverId || "")) || Number(split?.splitMs || 0) <= 0) return;
|
||||
splits.push({
|
||||
...split,
|
||||
sessionId: String(sessionId),
|
||||
sessionName: String(session?.name || ""),
|
||||
eventName: String(event?.name || ""),
|
||||
splitMs: Math.round(Number(split.splitMs)),
|
||||
});
|
||||
});
|
||||
(Array.isArray(result?.pitStops) ? result.pitStops : []).forEach((stop) => {
|
||||
if (!profileReferences.has(String(stop?.driverId || "")) || Number(stop?.pitStopMs || 0) <= 0) return;
|
||||
pitStops.push({
|
||||
...stop,
|
||||
sessionId: String(sessionId),
|
||||
sessionName: String(session?.name || ""),
|
||||
eventName: String(event?.name || ""),
|
||||
pitStopMs: Math.round(Number(stop.pitStopMs)),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
splits.sort((left, right) => Number(left.timestamp || 0) - Number(right.timestamp || 0));
|
||||
pitStops.sort((left, right) => Number(left.enteredAt || 0) - Number(right.enteredAt || 0));
|
||||
const splitTimes = splits.map((split) => split.splitMs);
|
||||
const pitTimes = pitStops.map((stop) => stop.pitStopMs);
|
||||
return {
|
||||
splitCount: splits.length,
|
||||
splitSessions: new Set(splits.map((split) => split.sessionId)).size,
|
||||
bestSplitMs: splitTimes.length ? Math.min(...splitTimes) : 0,
|
||||
averageSplitMs: splitTimes.length ? Math.round(splitTimes.reduce((sum, value) => sum + value, 0) / splitTimes.length) : 0,
|
||||
lastSplitMs: splitTimes.at(-1) || 0,
|
||||
pitStopCount: pitStops.length,
|
||||
pitSessions: new Set(pitStops.map((stop) => stop.sessionId)).size,
|
||||
totalPitMs: pitTimes.reduce((sum, value) => sum + value, 0),
|
||||
averagePitStopMs: pitTimes.length ? Math.round(pitTimes.reduce((sum, value) => sum + value, 0) / pitTimes.length) : 0,
|
||||
bestPitStopMs: pitTimes.length ? Math.min(...pitTimes) : 0,
|
||||
longestPitStopMs: pitTimes.length ? Math.max(...pitTimes) : 0,
|
||||
recentPitStops: pitStops.slice(-10).reverse(),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildDriverActivePracticeStats(state, driverId, nowTs = Date.now(), classId = "") {
|
||||
const session = (Array.isArray(state?.sessions) ? state.sessions : [])
|
||||
.find((item) => String(item?.id || "") === String(state?.activeSessionId || ""));
|
||||
|
||||
Reference in New Issue
Block a user