API: gpx import fix
This commit is contained in:
parent
90c380f35a
commit
276a886a61
@ -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'], ),
|
||||
|
@ -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'], ),
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user