From e4f038936a835be64abfc7460073acaba1efd93d Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Fri, 19 Jun 2026 17:11:39 +0200 Subject: [PATCH] fix --- api/src/analytics/analytics.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/api/src/analytics/analytics.service.ts b/api/src/analytics/analytics.service.ts index 020844e..9b50ceb 100644 --- a/api/src/analytics/analytics.service.ts +++ b/api/src/analytics/analytics.service.ts @@ -1358,11 +1358,18 @@ export class AnalyticsService { const daysSinceLastRun = lastRun?.startDate ? this.daysBetween(lastRun.startDate, now) : null; // Faktor 1: Load Ratio (0-100) - const loadFactor = acuteChronicRatio !== null ? Math.min(acuteChronicRatio * 10, 100) : 50; + const loadFactor = acuteChronicRatio === null ? 50 : Math.min(acuteChronicRatio * 10, 100); // Faktor 2: Intensität - Anteil harter Läufe in den letzten 14 Tagen - 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 !== null && al.activity.startDate !== undefined && this.daysBetween(al.activity.startDate, now) <= 14); + const recentRuns = runs.filter((run) => { + const days = this.daysBetween(run.startDate, now); + return days !== null && days <= 14; + }); + const hardRuns = activityLoads.filter((al) => { + if (al.zone !== 'hard') return false; + const days = this.daysBetween(al.activity.startDate, now); + return days !== null && days <= 14; + }); const intensityFactor = recentRuns.length > 0 ? Math.round((hardRuns.length / recentRuns.length) * 100) : 0; // Faktor 3: Erholung (je mehr Tage seit letztem Lauf, desto besser) @@ -1406,7 +1413,7 @@ export class AnalyticsService { const formScore = this.calculateFormScore(activityLoads, now); // Fatigue: Basierend auf akuter Belastung - const fatigueScore = acuteChronicRatio !== null ? Math.max(0, 100 - (acuteChronicRatio - 1) * 50) : 75; + const fatigueScore = acuteChronicRatio === null ? 75 : Math.max(0, 100 - (acuteChronicRatio - 1) * 50); // Recovery const recoveryScore = daysSinceLastRun === null ? 50 : @@ -1504,6 +1511,7 @@ export class AnalyticsService { for (let i = sortedRuns.length - 2; i >= 0; i--) { const currentRunDate = sortedRuns[i].startDate!; const daysDiff = this.daysBetween(currentRunDate, lastRunDate); + if (daysDiff === null) break; if (daysDiff === 1) { streak++; } else if (daysDiff > 1) {