fix(training): keep practice laps in training stats after Reset data
Resetting a running Open Practice deleted its results, the Timing view recreated an empty result at once, and the next save rebuilt that session's training laps from nothing - wiping every earlier lap from the drivers' stats. Reset now syncs first and records resultsResetAt; laps from before it are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b63dd2372
commit
3cc4fa0845
10 files changed
+141
-7
No files matched your search
@@ -208,8 +208,15 @@ export function syncTrainingLedger(training, state, { uid }) {
|
||||
const normalized = normalizeTrainingState(training, { uid });
|
||||
const results = state?.resultsBySession && typeof state.resultsBySession === "object" ? state.resultsBySession : {};
|
||||
const currentSessionIds = new Set(Object.keys(results));
|
||||
const retained = normalized.ledger.filter((entry) => !currentSessionIds.has(entry.sessionId));
|
||||
const sessions = new Map((Array.isArray(state?.sessions) ? state.sessions : []).map((session) => [String(session.id), session]));
|
||||
// A session's laps are rebuilt from its results - except laps from before a "Reset data"
|
||||
// (session.resultsResetAt): they're gone from the results but stay training history, so an
|
||||
// Open Practice can be cleared for a new day without losing anyone's stats.
|
||||
const retained = normalized.ledger.filter((entry) => {
|
||||
if (!currentSessionIds.has(entry.sessionId)) return true;
|
||||
const resetAt = Number(sessions.get(entry.sessionId)?.resultsResetAt || 0);
|
||||
return resetAt > 0 && entry.timestamp < resetAt;
|
||||
});
|
||||
const events = new Map((Array.isArray(state?.events) ? state.events : []).map((event) => [String(event.id), event]));
|
||||
const current = [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user