Skip to content

Commit

Permalink
feat: elevation gain - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-29 committed Jun 3, 2024
1 parent 6cd112d commit 16b9613
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion run_page/db_updater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from generator.db import init_db, Activity
from config import SQL_FILE
import sqlalchemy
from sqlalchemy import text
from config import GPX_FOLDER, JSON_FILE, SQL_FILE
from utils import make_activities_file


def add_column_elevation_gain(session):
Expand All @@ -11,10 +14,12 @@ def add_column_elevation_gain(session):
print("column elevation_gain already added, skipping")
except sqlalchemy.exc.OperationalError:
sql_statement = 'alter TABLE "activities" add column elevation_gain Float after average_heartrate'
session.execute(statement=sql_statement)
session.execute(text(sql_statement))
print("column elevation_gain added successfully")


if __name__ == "__main__":
session = init_db(SQL_FILE)
add_column_elevation_gain(session)
# regenerate activities
make_activities_file(SQL_FILE, GPX_FOLDER, JSON_FILE)
2 changes: 2 additions & 0 deletions run_page/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def sync(self, force):
continue
if IGNORE_BEFORE_SAVING:
activity.summary_polyline = filter_out(activity.summary_polyline)
# strava use total_elevation_gain as elevation_gain
activity.elevation_gain = activity.total_elevation_gain
created = update_or_create_activity(self.session, activity)
if created:
sys.stdout.write("+")
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.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
4 changes: 3 additions & 1 deletion src/components/RunTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ 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.elevation_gain - b.elevation_gain : b.elevation_gain - a.elevation_gain;
sortFuncInfo === 'Elevation Gain'
? (a.elevation_gain ?? 0) - (b.elevation_gain ?? 0)
: (b.elevation_gain ?? 0) - (a.elevation_gain ?? 0);
const sortPaceFunc: SortFunc = (a, b) =>
sortFuncInfo === 'Pace'
? a.average_speed - b.average_speed
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;
elevation_gain: number;
elevation_gain: number | null;
average_speed: number;
streak: number;
}
Expand Down

0 comments on commit 16b9613

Please sign in to comment.