feat: Phase 0b - add avg_per_week_30d aggregation method
- 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:
parent
9fa6c5dea7
commit
14c4ea13d9
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user