Strip pre-2000 leading points to prevent epoch-zero start time and absurd duration
This commit is contained in:
@@ -5,9 +5,27 @@ It gets fed into metrics computation and the BAS JSON writer.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
# Any timestamp before this is almost certainly an uninitialised sensor value
|
||||
# (epoch 0, FIT "no-data" sentinel, RTC not yet synced, etc.).
|
||||
_MIN_TIMESTAMP = datetime(2000, 1, 1, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def strip_bogus_leading_points(points: list["DataPoint"]) -> list["DataPoint"]:
|
||||
"""Drop leading points whose timestamp predates the year 2000.
|
||||
|
||||
FIT files occasionally emit a record with timestamp=0 (or another
|
||||
pre-2000 value) as an uninitialised sentinel before the real data
|
||||
begins. Keeping such a point as points[0] produces a 1970 start
|
||||
time and an absurdly large duration_s.
|
||||
"""
|
||||
i = 0
|
||||
while i < len(points) and points[i].timestamp < _MIN_TIMESTAMP:
|
||||
i += 1
|
||||
return points[i:]
|
||||
|
||||
|
||||
@dataclass
|
||||
class DataPoint:
|
||||
|
||||
Reference in New Issue
Block a user