From 9e5b8a521b174e6837ca20466dd84cc3e58c31b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Granda?= Date: Sun, 25 May 2014 19:45:58 +0200 Subject: [PATCH] Update record.py Quick proposal to support scenarios where `avg_hr`, `max_hr` or both are zero. Feel free to improve it! --- pytrainer/record.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pytrainer/record.py b/pytrainer/record.py index 2809992b..2e7fbeeb 100644 --- a/pytrainer/record.py +++ b/pytrainer/record.py @@ -225,13 +225,16 @@ def hrFromLaps(self, laps): max_hr = max([int(lap.get('max_hr', 0) or 0) for lap in laps]) avg_hr_time_pairs = [(lap.get('avg_hr', None), float(lap.get('elapsed_time', 0) or 0)) for lap in laps] - + for lap_avg_hr, elapsed_time in avg_hr_time_pairs: if lap_avg_hr is not None: total_duration += elapsed_time ponderate_hr += elapsed_time * int(lap_avg_hr) + if lap_avg_hr > max_hr: + max_hr = lap_avg_hr - avg_hr = int(round(ponderate_hr / total_duration)) # ceil?, floor?, round? + if ponderate_hr > 0: + avg_hr = int(round(ponderate_hr / total_duration)) # ceil?, floor?, round? logging.debug('<<') return avg_hr, max_hr