glutamatt HF Staff commited on
Commit
58c055f
·
verified ·
1 Parent(s): 6814b6b

simpler to be accurate

Browse files
Files changed (2) hide show
  1. src/main.ts +3 -7
  2. src/utils/metricAcwr.ts +3 -8
src/main.ts CHANGED
@@ -355,14 +355,10 @@ function renderCharts(activities: Activity[], targetAcwr: number, predictToday:
355
  }
356
  endDate.setHours(23, 59, 59, 999);
357
 
358
- // Calculate start date: use longer history for activities with less frequency
359
- // Base: 2x chronic period (56 days), extended up to 3x (84 days) for sparse activities
360
- const activityFrequency = activities.length / Math.max(1,
361
- (endDate.getTime() - activities[0].date.getTime()) / (1000 * 60 * 60 * 24));
362
- const multiplier = activityFrequency < 0.2 ? 3 : activityFrequency < 0.5 ? 2.5 : 2;
363
-
364
  const startDate = new Date(endDate);
365
- startDate.setDate(startDate.getDate() - Math.floor(28 * multiplier));
366
  startDate.setHours(0, 0, 0, 0);
367
 
368
  dateRange = {
 
355
  }
356
  endDate.setHours(23, 59, 59, 999);
357
 
358
+ // Calculate start date: always go back 56 days (2 x 28 days chronic period)
359
+ // This ensures we have enough historical data for accurate ACWR calculation
 
 
 
 
360
  const startDate = new Date(endDate);
361
+ startDate.setDate(startDate.getDate() - 56);
362
  startDate.setHours(0, 0, 0, 0);
363
 
364
  dateRange = {
src/utils/metricAcwr.ts CHANGED
@@ -334,14 +334,9 @@ export function calculateMetricACWR(
334
  const chronicAvg = chronicCount > 0 ? chronicSum / 28 : null;
335
  average28d.push(chronicAvg);
336
 
337
- // Calculate ACWR with smart requirements:
338
- // - At the beginning (first 28 days): need at least 8 data points to avoid unrealistic spikes
339
- // - After that: calculate whenever both averages are available (minimum 4 data points)
340
- // This avoids spikes at the start while ensuring the end is always visible
341
- const needsMinimumData = index < 28;
342
- const hasEnoughData = needsMinimumData ? chronicCount >= 8 : chronicCount >= 4;
343
-
344
- if (hasEnoughData && acuteAvg !== null && chronicAvg !== null && chronicAvg > 0) {
345
  acwr.push(acuteAvg / chronicAvg);
346
  } else {
347
  acwr.push(null);
 
334
  const chronicAvg = chronicCount > 0 ? chronicSum / 28 : null;
335
  average28d.push(chronicAvg);
336
 
337
+ // Calculate ACWR only after we have at least 28 days of data range
338
+ // This ensures accuracy by having a full chronic period (28 days)
339
+ if (index >= 27 && acuteAvg !== null && chronicAvg !== null && chronicAvg > 0) {
 
 
 
 
 
340
  acwr.push(acuteAvg / chronicAvg);
341
  } else {
342
  acwr.push(null);