Mobilprofilen visar nu per vald klassom det finns depå,mellantids

decoders
This commit is contained in:
larssand
2026-08-25 20:04:14 +02:00
parent abf887dccd
commit 84302a770d
7 changed files with 81 additions and 2 deletions

View File

@@ -54,6 +54,7 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
}))
.sort((left, right) => left.timestamp - right.timestamp);
const stats = buildPublicTrainingStats(classLaps);
const channelStats = buildPublicTimingChannelStats(state, classDriverIds);
const rankedTotals = getRankedTrainingTotals(ledger, drivers, classId);
const rankIndex = rankedTotals.findIndex(([profileId]) => profileId === driverProfile.id);
const classGoals = (Array.isArray(state?.training?.goals) ? state.training.goals : [])
@@ -67,6 +68,7 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
clubRank: rankIndex >= 0 ? rankIndex + 1 : 0,
rankedDrivers: rankedTotals.length,
stats,
channelStats,
nextMilestone: getPublicTrainingMilestone(stats.totalLaps),
recommendation: getPublicTrainingRecommendation(stats),
goals: classGoals,
@@ -78,6 +80,7 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
const activeClass = classProfiles[0] || {
classId: "", className: "", brand: "", clubRank: 0, rankedDrivers: 0,
stats: buildPublicTrainingStats([]), nextMilestone: getPublicTrainingMilestone(0),
channelStats: buildPublicTimingChannelStats({}, new Set()),
recommendation: getPublicTrainingRecommendation({ totalLaps: 0 }), goals: [], currentSession: null,
};
const settings = state?.settings && typeof state.settings === "object" ? state.settings : {};
@@ -98,6 +101,7 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
},
classProfiles,
stats: activeClass.stats,
channelStats: activeClass.channelStats,
nextMilestone: activeClass.nextMilestone,
recommendation: activeClass.recommendation,
goals: activeClass.goals,
@@ -105,6 +109,33 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
};
}
function buildPublicTimingChannelStats(state, classDriverIds) {
const splitTimes = [];
const pitTimes = [];
Object.values(state?.resultsBySession || {}).forEach((result) => {
(Array.isArray(result?.splits) ? result.splits : []).forEach((split) => {
const splitMs = Math.round(Number(split?.splitMs || 0) || 0);
if (classDriverIds.has(String(split?.driverId || "")) && splitMs > 0) splitTimes.push(splitMs);
});
(Array.isArray(result?.pitStops) ? result.pitStops : []).forEach((stop) => {
const pitStopMs = Math.round(Number(stop?.pitStopMs || 0) || 0);
if (classDriverIds.has(String(stop?.driverId || "")) && pitStopMs > 0) pitTimes.push(pitStopMs);
});
});
const average = (values) => values.length
? Math.round(values.reduce((sum, value) => sum + value, 0) / values.length)
: 0;
return {
splitCount: splitTimes.length,
bestSplitMs: splitTimes.length ? Math.min(...splitTimes) : 0,
averageSplitMs: average(splitTimes),
pitStopCount: pitTimes.length,
totalPitMs: pitTimes.reduce((sum, value) => sum + value, 0),
bestPitStopMs: pitTimes.length ? Math.min(...pitTimes) : 0,
averagePitStopMs: average(pitTimes),
};
}
function normalizePublicTrainingSince(value, startedAgoValue) {
const now = Date.now();
if (startedAgoValue !== undefined) {