fix mid level issues. updated changelog
This commit is contained in:
@@ -86,8 +86,8 @@ def compute(activity: ParsedActivity) -> ComputedMetrics:
|
||||
moving_time_s=moving_time_s,
|
||||
elevation_gain_m=round(gain, 1) if gain is not None else None,
|
||||
elevation_loss_m=round(abs(loss), 1) if loss is not None else None,
|
||||
avg_speed_kmh=round(avg_speed_kmh, 2) if avg_speed_kmh else None,
|
||||
max_speed_kmh=round(max_speed_kmh, 2) if max_speed_kmh else None,
|
||||
avg_speed_kmh=round(avg_speed_kmh, 2) if avg_speed_kmh is not None else None,
|
||||
max_speed_kmh=round(max_speed_kmh, 2) if max_speed_kmh is not None else None,
|
||||
avg_hr_bpm=avg_hr,
|
||||
max_hr_bpm=max_hr,
|
||||
avg_cadence_rpm=avg_cad,
|
||||
|
||||
@@ -86,7 +86,7 @@ class FitParser:
|
||||
duration_s=int(elapsed) if elapsed else None,
|
||||
distance_m=_get(frame, "total_distance"),
|
||||
elevation_gain_m=_get(frame, "total_ascent"),
|
||||
avg_speed_kmh=speed_raw * 3.6 if speed_raw else None,
|
||||
avg_speed_kmh=speed_raw * 3.6 if speed_raw is not None else None,
|
||||
avg_hr_bpm=_get(frame, "avg_heart_rate"),
|
||||
avg_power_w=_get(frame, "avg_power"),
|
||||
)
|
||||
|
||||
@@ -87,11 +87,24 @@ class TcxParser:
|
||||
|
||||
|
||||
def _parse_ts(s: str) -> datetime:
|
||||
# ISO 8601 with or without fractional seconds
|
||||
s = s.rstrip("Z")
|
||||
for fmt in ("%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"):
|
||||
try:
|
||||
return datetime.strptime(s, fmt).replace(tzinfo=timezone.utc)
|
||||
except ValueError:
|
||||
continue
|
||||
# ISO 8601 with or without fractional seconds, with Z or numeric offset (+02:00)
|
||||
import re as _re
|
||||
# Strip trailing Z → assume UTC
|
||||
if s.endswith("Z"):
|
||||
s = s[:-1]
|
||||
for fmt in ("%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"):
|
||||
try:
|
||||
return datetime.strptime(s, fmt).replace(tzinfo=timezone.utc)
|
||||
except ValueError:
|
||||
continue
|
||||
# Numeric offset like +02:00 or -05:30 — parse with %z then convert to UTC
|
||||
m = _re.match(r"^(.+)([+-]\d{2}:\d{2})$", s)
|
||||
if m:
|
||||
body, off = m.group(1), m.group(2).replace(":", "")
|
||||
for fmt in ("%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"):
|
||||
try:
|
||||
dt = datetime.strptime(body + off, fmt + "%z")
|
||||
return dt.astimezone(timezone.utc).replace(tzinfo=timezone.utc)
|
||||
except ValueError:
|
||||
continue
|
||||
raise ValueError(f"Cannot parse timestamp: {s!r}")
|
||||
|
||||
Reference in New Issue
Block a user