Skip to content

Commit

Permalink
feat: elevation gain - db updator
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-29 committed May 30, 2024
1 parent 673861e commit 6cd112d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 20 additions & 0 deletions run_page/db_updater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from generator.db import init_db, Activity
from config import SQL_FILE
import sqlalchemy


def add_column_elevation_gain(session):
# check if column elevation_gain is already added
# if not add it to the db
try:
session.query(Activity).first()
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)
print("column elevation_gain added successfully")


if __name__ == "__main__":
session = init_db(SQL_FILE)
add_column_elevation_gain(session)
4 changes: 1 addition & 3 deletions run_page/gpxtrackposter/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,7 @@ def to_namedtuple(self):
"average_heartrate": (
int(self.average_heartrate) if self.average_heartrate else None
),
"elevation_gain": (
int(self.elevation_gain) if self.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

0 comments on commit 6cd112d

Please sign in to comment.