From 6cd112d83234159e979f86b3e1cc1667f5c88211 Mon Sep 17 00:00:00 2001 From: ben_29 Date: Thu, 30 May 2024 18:58:46 +0800 Subject: [PATCH] feat: elevation gain - db updator --- run_page/db_updater.py | 20 ++++++++++++++++++++ run_page/gpxtrackposter/track.py | 4 +--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 run_page/db_updater.py diff --git a/run_page/db_updater.py b/run_page/db_updater.py new file mode 100644 index 00000000000..570ed5aea7d --- /dev/null +++ b/run_page/db_updater.py @@ -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) diff --git a/run_page/gpxtrackposter/track.py b/run_page/gpxtrackposter/track.py index c4a01cf6631..bbbe21147b4 100644 --- a/run_page/gpxtrackposter/track.py +++ b/run_page/gpxtrackposter/track.py @@ -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, }