Spaces:
Running
Running
simpler to be accurate
Browse files- src/main.ts +3 -7
- 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:
|
| 359 |
-
//
|
| 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() -
|
| 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
|
| 338 |
-
//
|
| 339 |
-
|
| 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);
|