From 67aab8306a940766e1579039756d31e51bfe2519 Mon Sep 17 00:00:00 2001 From: ben_29 Date: Sun, 26 May 2024 22:31:38 +0800 Subject: [PATCH] feat: elevation gain - joyrun --- run_page/endomondo_sync.py | 1 + run_page/gpxtrackposter/track.py | 2 +- run_page/joyrun_sync.py | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/run_page/endomondo_sync.py b/run_page/endomondo_sync.py index bdecf438d68..00f4bed2358 100644 --- a/run_page/endomondo_sync.py +++ b/run_page/endomondo_sync.py @@ -68,6 +68,7 @@ def parse_run_endomondo_to_nametuple(en_dict): "average_speed": en_dict.get("distance_km", 0) / en_dict.get("duration_s", 1) * 1000, + "total_elevation_gain": None, "location_country": "", } return namedtuple("x", d.keys())(*d.values()) diff --git a/run_page/gpxtrackposter/track.py b/run_page/gpxtrackposter/track.py index 88daacd1e8d..bdeebd6f66b 100644 --- a/run_page/gpxtrackposter/track.py +++ b/run_page/gpxtrackposter/track.py @@ -345,7 +345,7 @@ def to_namedtuple(self): int(self.average_heartrate) if self.average_heartrate else None ), "total_elevation_gain": ( - int(self.total_elevation_gain) if self.total_elevation_gain else None + int(self.total_elevation_gain) if self.total_elevation_gain else None ), "map": run_map(self.polyline_str), "start_latlng": self.start_latlng, diff --git a/run_page/joyrun_sync.py b/run_page/joyrun_sync.py index 49a6b01e6be..a2e4e894196 100755 --- a/run_page/joyrun_sync.py +++ b/run_page/joyrun_sync.py @@ -258,7 +258,8 @@ def parse_points_to_gpx( f""" {heart_rate_list[i]} - """) + """ + ) i += 1 point.extensions.append(gpx_extension_hr) gpx_segment.points.append(point) @@ -304,6 +305,7 @@ def parse_raw_data_to_nametuple(self, run_data, old_gpx_ids, with_gpx=False): # fix #66 if heart_rate < 0: heart_rate = None + total_elevation_gain = None # pass the track no points if run_points_data: gpx_data = self.parse_points_to_gpx( @@ -314,6 +316,11 @@ def parse_raw_data_to_nametuple(self, run_data, old_gpx_ids, with_gpx=False): altitude_list, pause_list, ) + total_elevation_gain = ( + gpx_data.get_uphill_downhill().uphill + if gpx_data.has_elevations() + else None + ) if with_gpx: # pass the track no points if str(joyrun_id) not in old_gpx_ids: @@ -351,6 +358,7 @@ def parse_raw_data_to_nametuple(self, run_data, old_gpx_ids, with_gpx=False): seconds=int((run_data["endtime"] - run_data["starttime"])) ), "average_speed": run_data["meter"] / run_data["second"], + "total_elevation_gain": total_elevation_gain, "location_country": location_country, } return namedtuple("x", d.keys())(*d.values())