Highscore: gleiche Stufe nach schnellerer Zeit sortieren
This commit is contained in:
parent
34bcef5da8
commit
3c00728c62
|
|
@ -35,6 +35,23 @@ describe('progress', () => {
|
|||
expect(stages).toEqual([4, 3, 2, 1]);
|
||||
});
|
||||
|
||||
it('orders same-stage runs by faster time first', () => {
|
||||
let p = emptyProgress();
|
||||
p = recordRun(p, 8, 4, '2026-01-01T00:00:00.000Z', 40000);
|
||||
p = recordRun(p, 8, 4, '2026-01-02T00:00:00.000Z', 20000);
|
||||
p = recordRun(p, 8, 4, '2026-01-03T00:00:00.000Z', 30000);
|
||||
const times = p.perTarget[8].top5.map((r) => r.timeMs);
|
||||
expect(times).toEqual([20000, 30000, 40000]);
|
||||
});
|
||||
|
||||
it('ranks timed runs ahead of untimed ones at the same stage', () => {
|
||||
let p = emptyProgress();
|
||||
p = recordRun(p, 9, 4, '2026-01-02T00:00:00.000Z'); // keine Zeit
|
||||
p = recordRun(p, 9, 4, '2026-01-01T00:00:00.000Z', 25000);
|
||||
expect(p.perTarget[9].top5[0].timeMs).toBe(25000);
|
||||
expect(p.perTarget[9].top5[1].timeMs).toBeUndefined();
|
||||
});
|
||||
|
||||
it('limits top5 to five entries', () => {
|
||||
let p = emptyProgress();
|
||||
for (let i = 0; i < 10; i++) p = recordRun(p, 6, ((i % 4) + 1) as 1 | 2 | 3 | 4);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export type RunRecord = { stage: Stage; date: string; timeMs?: number };
|
|||
|
||||
export type TargetProgress = {
|
||||
runs: number;
|
||||
top5: RunRecord[]; // sortiert: höchste Stufe zuerst, bei Gleichstand neueste zuerst
|
||||
top5: RunRecord[]; // sortiert: höchste Stufe zuerst, bei Gleichstand schnellere Zeit, dann neueste
|
||||
};
|
||||
|
||||
export type Progress = {
|
||||
|
|
@ -94,6 +94,10 @@ export function recordRun(
|
|||
const next: RunRecord = { stage, date, timeMs };
|
||||
const merged = [...prev.top5, next].sort((a, b) => {
|
||||
if (b.stage !== a.stage) return b.stage - a.stage;
|
||||
// Gleiche Stufe: schneller ist besser. Läufe ohne gemessene Zeit (Altdaten) hinten anstellen.
|
||||
const ta = a.timeMs ?? Infinity;
|
||||
const tb = b.timeMs ?? Infinity;
|
||||
if (ta !== tb) return ta - tb;
|
||||
return b.date.localeCompare(a.date);
|
||||
});
|
||||
const top5 = merged.slice(0, 5);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user