From 1a161ea20f557de8fea3ffa2a6e034ee886ff6cf Mon Sep 17 00:00:00 2001 From: kevforget <74352754+kevforget@users.noreply.github.com> Date: Tue, 27 Sep 2022 11:47:30 +0200 Subject: [PATCH] fix: Added duration and total_duration retreival from STD (#205) * fix: Added duration and total_duration retreival from STD * Added fallback to MovingTime (always defined) for TimerTime and EndTime computation in STD activity download --- tapiriik/services/Decathlon/decathlon.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tapiriik/services/Decathlon/decathlon.py b/tapiriik/services/Decathlon/decathlon.py index 7e8a6f23..0d3f23ea 100644 --- a/tapiriik/services/Decathlon/decathlon.py +++ b/tapiriik/services/Decathlon/decathlon.py @@ -374,7 +374,14 @@ def DownloadActivityList(self, svcRecord, exhaustive=False): activity.Type = self._reverseActivityTypeMappings[sport] ride_data = ride["dataSummaries"] - activity.EndTime = activity.StartTime + timedelta(seconds=ride_data.get(self._unitMap["duration"])) + # "total_duration" might not be set, whereas "duration" is always set. + # We try to get the first one but we fallback to the second if it's None + timer_time = ride_data.get(self._unitMap["totalduration"], ride_data.get(self._unitMap["duration"])) + + activity.Stats.MovingTime = ActivityStatistic(ActivityStatisticUnit.Seconds, value=ride_data.get(self._unitMap["duration"])) + activity.Stats.TimerTime = ActivityStatistic(ActivityStatisticUnit.Seconds, value=timer_time) + activity.EndTime = activity.StartTime + timedelta(seconds=timer_time) + activity.Stats.Distance = ActivityStatistic(ActivityStatisticUnit.Meters, value=ride_data.get(self._unitMap["distance"])) activity.Stats.Energy = ActivityStatistic(ActivityStatisticUnit.Kilocalories, value=ride_data.get(self._unitMap["kcal"])) activity.Stats.HR = ActivityStatistic(ActivityStatisticUnit.BeatsPerMinute, avg=ride_data.get(self._unitMap["hravg"]))