feat: Phase 0b - add avg_per_week_30d aggregation method
All checks were successful
Deploy Development / deploy (push) Successful in 44s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

- Calculates average count per week over 30 days
- Use case: Training frequency per week (smoothed)
- Formula: (count in 30 days) / 4.285 weeks
- Documentation: .claude/docs/technical/AGGREGATION_METHODS.md
This commit is contained in:
Lars 2026-03-28 10:45:36 +01:00
parent 9fa6c5dea7
commit 14c4ea13d9

View File

@ -407,6 +407,21 @@ def _fetch_by_aggregation_method(
row = cur.fetchone() row = cur.fetchone()
return float(row['max_value']) if row and row['max_value'] is not None else None return float(row['max_value']) if row and row['max_value'] is not None else None
elif method == 'avg_per_week_30d':
# Average count per week over 30 days
# Use case: Training frequency per week (smoothed over 4.3 weeks)
days_ago = date.today() - timedelta(days=30)
params = [profile_id, days_ago] + filter_params
cur.execute(f"""
SELECT COUNT(*) as count_value FROM {table}
WHERE profile_id = %s AND {date_col} >= %s{filter_sql}
""", params)
row = cur.fetchone()
if row and row['count_value'] is not None:
# 30 days = 4.285 weeks (30/7)
return round(float(row['count_value']) / 4.285, 2)
return None
else: else:
print(f"[WARNING] Unknown aggregation method: {method}") print(f"[WARNING] Unknown aggregation method: {method}")
return None return None