diff --git a/run_page/codoon_sync.py b/run_page/codoon_sync.py index e3719eaf376..584225f8879 100755 --- a/run_page/codoon_sync.py +++ b/run_page/codoon_sync.py @@ -528,10 +528,10 @@ def parse_raw_data_to_namedtuple( p["latitude"] = latlng_data[i][0] p["longitude"] = latlng_data[i][1] - total_elevation_gain = None + elevation_gain = None if run_points_data: gpx_data = self.parse_points_to_gpx(run_points_data) - total_elevation_gain = gpx_data.get_uphill_downhill().uphill + elevation_gain = gpx_data.get_uphill_downhill().uphill if with_gpx: # pass the track no points if str(log_id) not in old_gpx_ids: @@ -572,7 +572,7 @@ def parse_raw_data_to_namedtuple( seconds=int((end_date.timestamp() - start_date.timestamp())) ), "average_speed": run_data["total_length"] / run_data["total_time"], - "total_elevation_gain": total_elevation_gain, + "elevation_gain": elevation_gain, "location_country": location_country, "source": "Codoon", } diff --git a/run_page/endomondo_sync.py b/run_page/endomondo_sync.py index 00f4bed2358..c10f3ba02df 100644 --- a/run_page/endomondo_sync.py +++ b/run_page/endomondo_sync.py @@ -68,7 +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, + "elevation_gain": None, "location_country": "", } return namedtuple("x", d.keys())(*d.values()) diff --git a/run_page/generator/db.py b/run_page/generator/db.py index 7ee681d7491..3b7c87c0005 100644 --- a/run_page/generator/db.py +++ b/run_page/generator/db.py @@ -35,7 +35,7 @@ def randomword(): "summary_polyline", "average_heartrate", "average_speed", - "total_elevation_gain", + "elevation_gain", ] @@ -54,7 +54,7 @@ class Activity(Base): summary_polyline = Column(String) average_heartrate = Column(Float) average_speed = Column(Float) - total_elevation_gain = Column(Float) + elevation_gain = Column(Float) streak = None def to_dict(self): @@ -113,7 +113,7 @@ def update_or_create_activity(session, run_activity): location_country=location_country, average_heartrate=run_activity.average_heartrate, average_speed=float(run_activity.average_speed), - total_elevation_gain=float(run_activity.total_elevation_gain), + elevation_gain=float(run_activity.elevation_gain), summary_polyline=( run_activity.map and run_activity.map.summary_polyline or "" ), @@ -128,7 +128,7 @@ def update_or_create_activity(session, run_activity): activity.type = run_activity.type activity.average_heartrate = run_activity.average_heartrate activity.average_speed = float(run_activity.average_speed) - activity.total_elevation_gain = float(run_activity.total_elevation_gain) + activity.elevation_gain = float(run_activity.elevation_gain) activity.summary_polyline = ( run_activity.map and run_activity.map.summary_polyline or "" ) diff --git a/run_page/gpxtrackposter/track.py b/run_page/gpxtrackposter/track.py index 8a4ec4e8762..c4a01cf6631 100644 --- a/run_page/gpxtrackposter/track.py +++ b/run_page/gpxtrackposter/track.py @@ -47,7 +47,7 @@ def __init__(self): self.length = 0 self.special = False self.average_heartrate = None - self.total_elevation_gain = None + self.elevation_gain = None self.moving_dict = {} self.run_id = 0 self.start_latlng = [] @@ -165,7 +165,7 @@ def _load_tcx_data(self, tcx, file_name): except: pass self.polyline_str = polyline.encode(polyline_container) - self.total_elevation_gain = tcx.ascent + self.elevation_gain = tcx.ascent self.moving_dict = { "distance": self.length, "moving_time": datetime.timedelta(seconds=moving_time), @@ -229,7 +229,7 @@ def _load_gpx_data(self, gpx): sum(heart_rate_list) / len(heart_rate_list) if heart_rate_list else None ) self.moving_dict = self._get_moving_data(gpx) - self.total_elevation_gain = gpx.get_uphill_downhill().uphill + self.elevation_gain = gpx.get_uphill_downhill().uphill def _load_fit_data(self, fit: dict): _polylines = [] @@ -246,7 +246,7 @@ def _load_fit_data(self, fit: dict): self.average_heartrate = ( message["avg_heart_rate"] if "avg_heart_rate" in message else None ) - self.total_elevation_gain = ( + self.elevation_gain = ( message["total_ascent"] if "total_ascent" in message else None ) self.type = message["sport"].lower() @@ -304,9 +304,9 @@ def append(self, other): self.file_names.extend(other.file_names) self.special = self.special or other.special self.average_heartrate = self.average_heartrate or other.average_heartrate - self.total_elevation_gain = ( - self.total_elevation_gain if self.total_elevation_gain else 0 - ) + (other.total_elevation_gain if other.total_elevation_gain else 0) + self.elevation_gain = ( + self.elevation_gain if self.elevation_gain else 0 + ) + (other.elevation_gain if other.elevation_gain else 0) except: print( f"something wrong append this {self.end_time},in files {str(self.file_names)}" @@ -342,8 +342,8 @@ def to_namedtuple(self): "average_heartrate": ( int(self.average_heartrate) if self.average_heartrate else None ), - "total_elevation_gain": ( - int(self.total_elevation_gain) if self.total_elevation_gain else 0 + "elevation_gain": ( + int(self.elevation_gain) if self.elevation_gain else 0 ), "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 e6f1a98f3c0..4ee5c3cecf4 100755 --- a/run_page/joyrun_sync.py +++ b/run_page/joyrun_sync.py @@ -305,7 +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 + elevation_gain = None # pass the track no points if run_points_data: gpx_data = self.parse_points_to_gpx( @@ -316,7 +316,7 @@ 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 + elevation_gain = gpx_data.get_uphill_downhill().uphill if with_gpx: # pass the track no points if str(joyrun_id) not in old_gpx_ids: @@ -354,7 +354,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, + "elevation_gain": elevation_gain, "location_country": location_country, } return namedtuple("x", d.keys())(*d.values()) diff --git a/run_page/keep_sync.py b/run_page/keep_sync.py index 9b3c1d7d732..1edff5a050b 100755 --- a/run_page/keep_sync.py +++ b/run_page/keep_sync.py @@ -108,7 +108,7 @@ def parse_raw_data_to_nametuple( start_time = run_data["startTime"] avg_heart_rate = None - total_elevation_gain = None + elevation_gain = None decoded_hr_data = [] if run_data["heartRate"]: avg_heart_rate = run_data["heartRate"].get("averageHeartRate", None) @@ -139,7 +139,7 @@ def parse_raw_data_to_nametuple( gpx_data = parse_points_to_gpx( run_points_data_gpx, start_time, KEEP2STRAVA[run_data["dataType"]] ) - total_elevation_gain = gpx_data.get_uphill_downhill().uphill + elevation_gain = gpx_data.get_uphill_downhill().uphill if with_download_gpx and str(keep_id) not in old_gpx_ids: download_keep_gpx(gpx_data.to_xml(), str(keep_id)) else: @@ -165,7 +165,7 @@ def parse_raw_data_to_nametuple( "end_local": datetime.strftime(end_local, "%Y-%m-%d %H:%M:%S"), "length": run_data["distance"], "average_heartrate": int(avg_heart_rate) if avg_heart_rate else None, - "total_elevation_gain": run_data["accumulativeUpliftedHeight"], + "elevation_gain": run_data["accumulativeUpliftedHeight"], "map": run_map(polyline_str), "start_latlng": start_latlng, "distance": run_data["distance"], @@ -174,7 +174,7 @@ def parse_raw_data_to_nametuple( seconds=int((run_data["endTime"] - run_data["startTime"]) / 1000) ), "average_speed": run_data["distance"] / run_data["duration"], - "total_elevation_gain": total_elevation_gain, + "elevation_gain": elevation_gain, "location_country": str(run_data.get("region", "")), } return namedtuple("x", d.keys())(*d.values()) diff --git a/run_page/nike_sync.py b/run_page/nike_sync.py index 04c72f55e3d..11356a909a8 100644 --- a/run_page/nike_sync.py +++ b/run_page/nike_sync.py @@ -372,6 +372,7 @@ def parse_no_gpx_data(activity): "moving_time": moving_time, "elapsed_time": elapsed_time, "average_speed": distance / int(activity["active_duration_ms"] / 1000), + "elevation_gain": 0, "location_country": "", } return namedtuple("x", d.keys())(*d.values()) diff --git a/run_page/oppo_sync.py b/run_page/oppo_sync.py index e72a58d28cb..1af9169eabf 100644 --- a/run_page/oppo_sync.py +++ b/run_page/oppo_sync.py @@ -189,7 +189,7 @@ def parse_raw_data_to_name_tuple(sport_data, with_gpx, with_tcx): start_time = sport_data["startTime"] other_data = sport_data["otherSportData"] avg_heart_rate = None - total_elevation_gain = None + elevation_gain = None if other_data: avg_heart_rate = other_data.get("avgHeartRate", None) # fix #66 @@ -208,7 +208,7 @@ def parse_raw_data_to_name_tuple(sport_data, with_gpx, with_tcx): point_dict = prepare_track_points(sport_data, with_gpx) gpx_data = parse_points_to_gpx(sport_data, point_dict) - total_elevation_gain = gpx_data.get_uphill_downhill().uphill + elevation_gain = gpx_data.get_uphill_downhill().uphill if with_gpx is True: download_keep_gpx(gpx_data.to_xml(), str(oppo_id)) if with_tcx is True: @@ -249,7 +249,7 @@ def parse_raw_data_to_name_tuple(sport_data, with_gpx, with_tcx): seconds=int((sport_data["endTime"] - sport_data["startTime"]) / 1000) ), "average_speed": other_data["totalDistance"] / other_data["totalTime"] * 1000, - "total_elevation_gain": total_elevation_gain, + "elevation_gain": elevation_gain, "location_country": location_country, "source": sport_data["deviceName"], } diff --git a/run_page/tulipsport_sync.py b/run_page/tulipsport_sync.py index a2904eb58dc..6e1966765eb 100755 --- a/run_page/tulipsport_sync.py +++ b/run_page/tulipsport_sync.py @@ -98,7 +98,7 @@ def merge_summary_and_detail_to_nametuple(summary, detail): # end_date = datetime.strftime(summary["end_date"], "%Y-%m-%d %H:%M:%S") # end_date_local = datetime.strftime(summary["end_date_local"], "%Y-%m-%d %H:%M:%S") average_heartrate = int(detail["avg_hr"]) - total_elevation_gain = None + elevation_gain = None map = run_map("") start_latlng = None distance = summary["distance"] @@ -123,7 +123,7 @@ def merge_summary_and_detail_to_nametuple(summary, detail): map = run_map(polyline.encode(latlng_list)) altitude_list = [point[2] for point in detail["map_data_list"]] - total_elevation_gain = compute_elevation_gain(altitude_list) + elevation_gain = compute_elevation_gain(altitude_list) activity_db_instance = { "id": id, @@ -138,7 +138,7 @@ def merge_summary_and_detail_to_nametuple(summary, detail): "moving_time": moving_time, "elapsed_time": elapsed_time, "average_speed": average_speed, - "total_elevation_gain": total_elevation_gain, + "elevation_gain": elevation_gain, "location_country": location_country, } return namedtuple("activity_db_instance", activity_db_instance.keys())( diff --git a/src/components/RunTable/RunRow.tsx b/src/components/RunTable/RunRow.tsx index 6e5d93e8a67..77d69fef9ac 100644 --- a/src/components/RunTable/RunRow.tsx +++ b/src/components/RunTable/RunRow.tsx @@ -11,7 +11,7 @@ interface IRunRowProperties { const RunRow = ({ elementIndex, locateActivity, run, runIndex, setRunIndex }: IRunRowProperties) => { const distance = (run.distance / 1000.0).toFixed(2); - const elevation_gain = run.total_elevation_gain?.toFixed(0); + const elevation_gain = run.elevation_gain.toFixed(0); const paceParts = run.average_speed ? formatPace(run.average_speed) : null; const heartRate = run.average_heartrate; const runTime = formatRunTime(run.moving_time); diff --git a/src/components/RunTable/index.tsx b/src/components/RunTable/index.tsx index 6c337f2186f..1929c921a34 100644 --- a/src/components/RunTable/index.tsx +++ b/src/components/RunTable/index.tsx @@ -31,7 +31,7 @@ const RunTable = ({ const sortKMFunc: SortFunc = (a, b) => sortFuncInfo === 'KM' ? a.distance - b.distance : b.distance - a.distance; const sortElevationGainFunc: SortFunc = (a, b) => - sortFuncInfo === 'Elevation Gain' ? a.total_elevation_gain - b.total_elevation_gain : b.total_elevation_gain - a.total_elevation_gain; + sortFuncInfo === 'Elevation Gain' ? a.elevation_gain - b.elevation_gain : b.elevation_gain - a.elevation_gain; const sortPaceFunc: SortFunc = (a, b) => sortFuncInfo === 'Pace' ? a.average_speed - b.average_speed diff --git a/src/components/YearStat/index.tsx b/src/components/YearStat/index.tsx index 78998b81889..cc9fa638f79 100644 --- a/src/components/YearStat/index.tsx +++ b/src/components/YearStat/index.tsx @@ -27,7 +27,7 @@ const YearStat = ({ year, onClick }: { year: string, onClick: (_year: string) => let totalSecondsAvail = 0; runs.forEach((run) => { sumDistance += run.distance || 0; - sumElevationGain += run.total_elevation_gain || 0; + sumElevationGain += run.elevation_gain || 0; if (run.average_speed) { pace += run.average_speed; totalMetersAvail += run.distance || 0; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index d12e561e042..3237189643a 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -22,7 +22,7 @@ export interface Activity { location_country?: string | null; summary_polyline?: string | null; average_heartrate?: number | null; - total_elevation_gain?: number | null; + elevation_gain: number; average_speed: number; streak: number; }