This commit is contained in:
Bastian Wagner
2026-06-19 17:01:22 +02:00
parent d8b1a47a2a
commit 06bdf83657

View File

@@ -568,7 +568,7 @@ export class AnalyticsService {
acuteChronicRatio: number | null, acuteChronicRatio: number | null,
): RunningKpiDashboard['recovery'] { ): RunningKpiDashboard['recovery'] {
const sortedLoads = [...activityLoads] const sortedLoads = [...activityLoads]
.filter((load) => load.activity.startDate) .filter((load) => load.activity.startDate !== null && load.activity.startDate !== undefined)
.sort( .sort(
(left, right) => (left, right) =>
(right.activity.startDate?.getTime() ?? 0) - (right.activity.startDate?.getTime() ?? 0) -
@@ -1351,7 +1351,9 @@ export class AnalyticsService {
acuteChronicRatio: number | null, acuteChronicRatio: number | null,
now: Date, now: Date,
): RunningInjuryRisk | null { ): RunningInjuryRisk | null {
const sortedRuns = [...runs].sort((a, b) => (a.startDate?.getTime() ?? 0) - (b.startDate?.getTime() ?? 0)); const sortedRuns = [...runs]
.filter((run) => run.startDate !== null && run.startDate !== undefined)
.sort((a, b) => (a.startDate?.getTime() ?? 0) - (b.startDate?.getTime() ?? 0));
const lastRun = sortedRuns.length > 0 ? sortedRuns[sortedRuns.length - 1] : null; const lastRun = sortedRuns.length > 0 ? sortedRuns[sortedRuns.length - 1] : null;
const daysSinceLastRun = lastRun?.startDate ? this.daysBetween(lastRun.startDate, now) : null; const daysSinceLastRun = lastRun?.startDate ? this.daysBetween(lastRun.startDate, now) : null;
@@ -1359,8 +1361,8 @@ export class AnalyticsService {
const loadFactor = acuteChronicRatio !== null ? Math.min(acuteChronicRatio * 10, 100) : 50; const loadFactor = acuteChronicRatio !== null ? Math.min(acuteChronicRatio * 10, 100) : 50;
// Faktor 2: Intensität - Anteil harter Läufe in den letzten 14 Tagen // Faktor 2: Intensität - Anteil harter Läufe in den letzten 14 Tagen
const recentRuns = runs.filter((run) => run.startDate && this.daysBetween(run.startDate, now) <= 14); const recentRuns = runs.filter((run) => run.startDate !== null && run.startDate !== undefined && this.daysBetween(run.startDate, now) <= 14);
const hardRuns = activityLoads.filter((al) => al.zone === 'hard' && al.activity.startDate && this.daysBetween(al.activity.startDate, now) <= 14); const hardRuns = activityLoads.filter((al) => al.zone === 'hard' && al.activity.startDate !== null && al.activity.startDate !== undefined && this.daysBetween(al.activity.startDate, now) <= 14);
const intensityFactor = recentRuns.length > 0 ? Math.round((hardRuns.length / recentRuns.length) * 100) : 0; const intensityFactor = recentRuns.length > 0 ? Math.round((hardRuns.length / recentRuns.length) * 100) : 0;
// Faktor 3: Erholung (je mehr Tage seit letztem Lauf, desto besser) // Faktor 3: Erholung (je mehr Tage seit letztem Lauf, desto besser)
@@ -1394,7 +1396,9 @@ export class AnalyticsService {
acuteChronicRatio: number | null, acuteChronicRatio: number | null,
now: Date, now: Date,
): RunningReadinessScore | null { ): RunningReadinessScore | null {
const sortedRuns = [...runs].sort((a, b) => (a.startDate?.getTime() ?? 0) - (b.startDate?.getTime() ?? 0)); const sortedRuns = [...runs]
.filter((run) => run.startDate !== null && run.startDate !== undefined)
.sort((a, b) => (a.startDate?.getTime() ?? 0) - (b.startDate?.getTime() ?? 0));
const lastRun = sortedRuns.length > 0 ? sortedRuns[sortedRuns.length - 1] : null; const lastRun = sortedRuns.length > 0 ? sortedRuns[sortedRuns.length - 1] : null;
const daysSinceLastRun = lastRun?.startDate ? this.daysBetween(lastRun.startDate, now) : null; const daysSinceLastRun = lastRun?.startDate ? this.daysBetween(lastRun.startDate, now) : null;
@@ -1487,19 +1491,18 @@ export class AnalyticsService {
} }
const sortedRuns = [...runs] const sortedRuns = [...runs]
.filter((run) => run.startDate) .filter((run) => run.startDate !== null && run.startDate !== undefined)
.sort((a, b) => (a.startDate?.getTime() ?? 0) - (b.startDate?.getTime() ?? 0)); .sort((a, b) => (a.startDate!.getTime() ?? 0) - (b.startDate!.getTime() ?? 0));
const lastRunDate = sortedRuns[sortedRuns.length - 1].startDate; if (sortedRuns.length === 0) {
if (!lastRunDate) {
return 0; return 0;
} }
const lastRunDate = sortedRuns[sortedRuns.length - 1].startDate!;
let streak = 1; let streak = 1;
for (let i = sortedRuns.length - 2; i >= 0; i--) { for (let i = sortedRuns.length - 2; i >= 0; i--) {
const currentRunDate = sortedRuns[i].startDate; const currentRunDate = sortedRuns[i].startDate!;
if (!currentRunDate) continue;
const daysDiff = this.daysBetween(currentRunDate, lastRunDate); const daysDiff = this.daysBetween(currentRunDate, lastRunDate);
if (daysDiff === 1) { if (daysDiff === 1) {
streak++; streak++;
@@ -1522,8 +1525,8 @@ export class AnalyticsService {
const fourWeeksAgo = this.addDays(now, -28); const fourWeeksAgo = this.addDays(now, -28);
const eightWeeksAgo = this.addDays(now, -56); const eightWeeksAgo = this.addDays(now, -56);
const recentLoads = activityLoads.filter((al) => al.activity.startDate && al.activity.startDate >= fourWeeksAgo); const recentLoads = activityLoads.filter((al) => al.activity.startDate !== null && al.activity.startDate !== undefined && al.activity.startDate >= fourWeeksAgo);
const previousLoads = activityLoads.filter((al) => al.activity.startDate && al.activity.startDate >= eightWeeksAgo && al.activity.startDate < fourWeeksAgo); const previousLoads = activityLoads.filter((al) => al.activity.startDate !== null && al.activity.startDate !== undefined && al.activity.startDate >= eightWeeksAgo && al.activity.startDate < fourWeeksAgo);
const recentTSS = recentLoads.reduce((sum, load) => sum + load.load, 0); const recentTSS = recentLoads.reduce((sum, load) => sum + load.load, 0);
const previousTSS = previousLoads.reduce((sum, load) => sum + load.load, 0); const previousTSS = previousLoads.reduce((sum, load) => sum + load.load, 0);