förbättreing tränings

This commit is contained in:
larssand
2026-08-28 21:44:23 +02:00
parent c6262aceab
commit 375bfb2416
14 changed files with 420 additions and 54 deletions

View File

@@ -55,8 +55,6 @@ 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 : [])
.filter((goal) => profileReferences.has(String(goal?.driverId || "")) && (!goal?.classId || String(goal.classId) === classId))
.map((goal) => buildPublicTrainingGoal(goal, stats.totalLaps));
@@ -65,8 +63,6 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
classId,
className: String(classes.find((item) => String(item?.id || "") === classId)?.name || "").trim(),
brand: brands.join(" / "),
clubRank: rankIndex >= 0 ? rankIndex + 1 : 0,
rankedDrivers: rankedTotals.length,
stats,
channelStats,
nextMilestone: getPublicTrainingMilestone(stats.totalLaps),
@@ -78,7 +74,7 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
};
});
const activeClass = classProfiles[0] || {
classId: "", className: "", brand: "", clubRank: 0, rankedDrivers: 0,
classId: "", className: "", brand: "",
stats: buildPublicTrainingStats([]), nextMilestone: getPublicTrainingMilestone(0),
channelStats: buildPublicTimingChannelStats({}, new Set()),
recommendation: getPublicTrainingRecommendation({ totalLaps: 0 }), goals: [], currentSession: null,
@@ -91,8 +87,6 @@ function buildPublicTrainingProfile(state, shareToken, updatedAt, sinceTimestamp
name: String(driver.name || "Driver").trim(),
brand: activeClass.brand,
className: activeClass.className,
clubRank: activeClass.clubRank,
rankedDrivers: activeClass.rankedDrivers,
},
branding: {
clubName: String(settings.clubName || "JMK RB").trim(),
@@ -176,20 +170,6 @@ function buildPublicTrainingGoal(goal, currentLaps) {
};
}
function getRankedTrainingTotals(ledger, drivers, classId = "") {
const profileByDriverId = new Map(drivers
.filter((driver) => !classId || String(driver?.classId || "") === String(classId))
.map((driver) => [String(driver?.id || ""), getPublicDriverProfileId(driver)]));
const totals = new Map();
ledger.forEach((entry) => {
const driverId = String(entry?.driverId || "");
const profileId = profileByDriverId.get(driverId);
if (!profileId || Number(entry?.lapMs || 0) <= 500) return;
totals.set(profileId, (totals.get(profileId) || 0) + 1);
});
return [...totals.entries()].sort((left, right) => right[1] - left[1]);
}
function buildPublicTrainingStats(laps) {
const lapTimes = laps.map((lap) => lap.lapMs);
const recent = lapTimes.slice(-30);