From 276a886a617e2eb9c9772d01df3667f76dffc429 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 29 May 2018 15:23:20 +0200 Subject: [PATCH] API: gpx import fix --- mpwo_api/migrations/versions/b7cfe0c17708_.py | 4 ++-- mpwo_api/migrations/versions/dd73d23a7a3d_.py | 4 ++-- mpwo_api/mpwo_api/activities/models.py | 8 ++++---- mpwo_api/mpwo_api/activities/utils.py | 8 +++++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mpwo_api/migrations/versions/b7cfe0c17708_.py b/mpwo_api/migrations/versions/b7cfe0c17708_.py index 65532bf1..0b630ed8 100644 --- a/mpwo_api/migrations/versions/b7cfe0c17708_.py +++ b/mpwo_api/migrations/versions/b7cfe0c17708_.py @@ -41,8 +41,8 @@ def upgrade(): sa.Column('distance', sa.Numeric(precision=6, scale=3), nullable=True), sa.Column('min_alt', sa.Numeric(precision=6, scale=2), nullable=True), sa.Column('max_alt', sa.Numeric(precision=6, scale=2), nullable=True), - sa.Column('descent', sa.Numeric(precision=6, scale=2), nullable=True), - sa.Column('ascent', sa.Numeric(precision=6, scale=2), nullable=True), + sa.Column('descent', sa.Numeric(precision=7, scale=2), nullable=True), + sa.Column('ascent', sa.Numeric(precision=7, scale=2), nullable=True), sa.Column('max_speed', sa.Numeric(precision=6, scale=2), nullable=True), sa.Column('ave_speed', sa.Numeric(precision=6, scale=2), nullable=True), sa.ForeignKeyConstraint(['sport_id'], ['sports.id'], ), diff --git a/mpwo_api/migrations/versions/dd73d23a7a3d_.py b/mpwo_api/migrations/versions/dd73d23a7a3d_.py index 11da94ac..7b17d386 100644 --- a/mpwo_api/migrations/versions/dd73d23a7a3d_.py +++ b/mpwo_api/migrations/versions/dd73d23a7a3d_.py @@ -27,8 +27,8 @@ def upgrade(): sa.Column('distance', sa.Numeric(precision=6, scale=3), nullable=True), sa.Column('min_alt', sa.Numeric(precision=6, scale=2), nullable=True), sa.Column('max_alt', sa.Numeric(precision=6, scale=2), nullable=True), - sa.Column('descent', sa.Numeric(precision=6, scale=2), nullable=True), - sa.Column('ascent', sa.Numeric(precision=6, scale=2), nullable=True), + sa.Column('descent', sa.Numeric(precision=7, scale=2), nullable=True), + sa.Column('ascent', sa.Numeric(precision=7, scale=2), nullable=True), sa.Column('max_speed', sa.Numeric(precision=6, scale=2), nullable=True), sa.Column('ave_speed', sa.Numeric(precision=6, scale=2), nullable=True), sa.ForeignKeyConstraint(['activity_id'], ['activities.id'], ), diff --git a/mpwo_api/mpwo_api/activities/models.py b/mpwo_api/mpwo_api/activities/models.py index a037981b..951c2b07 100644 --- a/mpwo_api/mpwo_api/activities/models.py +++ b/mpwo_api/mpwo_api/activities/models.py @@ -128,8 +128,8 @@ class Activity(db.Model): distance = db.Column(db.Numeric(6, 3), nullable=True) # kilometers min_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters max_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters - descent = db.Column(db.Numeric(6, 2), nullable=True) # meters - ascent = db.Column(db.Numeric(6, 2), nullable=True) # meters + descent = db.Column(db.Numeric(7, 2), nullable=True) # meters + ascent = db.Column(db.Numeric(7, 2), nullable=True) # meters max_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h ave_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h bounds = db.Column(postgresql.ARRAY(db.Float), nullable=True) @@ -263,8 +263,8 @@ class ActivitySegment(db.Model): distance = db.Column(db.Numeric(6, 3), nullable=True) # kilometers min_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters max_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters - descent = db.Column(db.Numeric(6, 2), nullable=True) # meters - ascent = db.Column(db.Numeric(6, 2), nullable=True) # meters + descent = db.Column(db.Numeric(7, 2), nullable=True) # meters + ascent = db.Column(db.Numeric(7, 2), nullable=True) # meters max_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h ave_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h diff --git a/mpwo_api/mpwo_api/activities/utils.py b/mpwo_api/mpwo_api/activities/utils.py index 91a453c4..c1687769 100644 --- a/mpwo_api/mpwo_api/activities/utils.py +++ b/mpwo_api/mpwo_api/activities/utils.py @@ -124,7 +124,7 @@ def get_gpx_data(parsed_gpx, max_speed, start): distance = mv.moving_distance + mv.stopped_distance gpx_data['distance'] = distance / 1000 - average_speed = distance / mv.moving_time + average_speed = distance / mv.moving_time if mv.moving_time > 0 else 0 gpx_data['average_speed'] = (average_speed / 1000) * 3600 return gpx_data @@ -207,9 +207,11 @@ def get_chart_data(gpx_file): if segment.get_speed(point_idx) is not None else 0) chart_data.append({ - 'distance': round(distance / 1000, 2), + 'distance': (round(distance / 1000, 2) + if distance is not None else 0), 'duration': point.time_difference(first_point), - 'elevation': round(point.elevation, 1), + 'elevation': (round(point.elevation, 1) + if point.elevation is not None else 0), 'speed': speed, 'time': point.time, })