Dedup segment efforts by started_at to handle same activity stored under two IDs
This commit is contained in:
@@ -172,10 +172,15 @@ def save_efforts(data_dir: Path, handle: str, segment_id: str, efforts: list[Seg
|
||||
|
||||
|
||||
def add_effort(data_dir: Path, handle: str, segment_id: str, effort: SegmentEffort) -> None:
|
||||
"""Append an effort, replacing any existing effort with the same activity + start time."""
|
||||
"""Append an effort, replacing any existing effort at the same start time.
|
||||
|
||||
Deduplicating by started_at (not activity_id) handles the case where the
|
||||
same ride is stored under two activity IDs (e.g. re-imported with a different
|
||||
source hash), which would otherwise produce two identical-time efforts.
|
||||
"""
|
||||
efforts = load_efforts(data_dir, handle, segment_id)
|
||||
key = (effort.activity_id, _iso(effort.started_at))
|
||||
efforts = [e for e in efforts if (e.activity_id, _iso(e.started_at)) != key]
|
||||
key = _iso(effort.started_at)
|
||||
efforts = [e for e in efforts if _iso(e.started_at) != key]
|
||||
efforts.append(effort)
|
||||
efforts.sort(key=lambda e: e.started_at, reverse=True)
|
||||
save_efforts(data_dir, handle, segment_id, efforts)
|
||||
|
||||
Reference in New Issue
Block a user