This commit is contained in:
xds
2026-03-16 14:46:20 +03:00
parent 00db55720c
commit de8c2472e2
45 changed files with 3714 additions and 140 deletions

View File

@@ -0,0 +1,30 @@
import numpy as np
from backend.app.models.activity import DataPoint
# Standard durations for the power duration curve
DURATIONS = [1, 5, 10, 15, 30, 60, 120, 300, 600, 1200, 1800, 3600]
def calculate_power_curve(data_points: list[DataPoint]) -> dict[int, int]:
"""
Calculate max average power for standard durations.
Returns {duration_seconds: max_avg_power}.
"""
powers = np.array([dp.power for dp in data_points if dp.power is not None], dtype=float)
if len(powers) == 0:
return {}
result = {}
for dur in DURATIONS:
if dur > len(powers):
break
if dur == 1:
result[dur] = int(np.max(powers))
else:
# Rolling mean via cumsum for efficiency
cumsum = np.cumsum(np.insert(powers, 0, 0))
rolling_avg = (cumsum[dur:] - cumsum[:-dur]) / dur
result[dur] = int(np.max(rolling_avg))
return result