Skip to content

Commit

Permalink
feat: elevation gain - field name
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-29 committed May 29, 2024
1 parent b809e61 commit 673861e
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 34 deletions.
6 changes: 3 additions & 3 deletions run_page/codoon_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
}
Expand Down
2 changes: 1 addition & 1 deletion run_page/endomondo_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions run_page/generator/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def randomword():
"summary_polyline",
"average_heartrate",
"average_speed",
"total_elevation_gain",
"elevation_gain",
]


Expand All @@ -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):
Expand Down Expand Up @@ -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 ""
),
Expand All @@ -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 ""
)
Expand Down
18 changes: 9 additions & 9 deletions run_page/gpxtrackposter/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 = []
Expand All @@ -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()
Expand Down Expand Up @@ -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)}"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions run_page/joyrun_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions run_page/keep_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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"],
Expand All @@ -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())
Expand Down
1 change: 1 addition & 0 deletions run_page/nike_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions run_page/oppo_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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"],
}
Expand Down
6 changes: 3 additions & 3 deletions run_page/tulipsport_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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,
Expand All @@ -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())(
Expand Down
2 changes: 1 addition & 1 deletion src/components/RunTable/RunRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/RunTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/YearStat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 673861e

Please sign in to comment.