API & Client: use of calculated bounds from API to display map

This commit is contained in:
Sam
2018-05-14 14:51:03 +02:00
parent e4a65f4c79
commit 12595040d5
10 changed files with 57 additions and 23 deletions

View File

@ -0,0 +1,28 @@
"""add 'bounds' column to 'Activity' table
Revision ID: 92adde6ac0d0
Revises: dd73d23a7a3d
Create Date: 2018-05-14 14:25:04.889189
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '92adde6ac0d0'
down_revision = 'dd73d23a7a3d'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('activities', sa.Column('bounds', postgresql.ARRAY(sa.Float()), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('activities', 'bounds')
# ### end Alembic commands ###

View File

@ -1,6 +1,7 @@
import datetime
from mpwo_api import db
from sqlalchemy.dialects import postgresql
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.types import Enum
@ -68,6 +69,7 @@ class Activity(db.Model):
ascent = db.Column(db.Numeric(5, 2), nullable=True) # meters
max_speed = db.Column(db.Numeric(5, 2), nullable=True) # km/h
ave_speed = db.Column(db.Numeric(5, 2), nullable=True) # km/h
bounds = db.Column(postgresql.ARRAY(db.Float), nullable=True)
segments = db.relationship('ActivitySegment',
lazy=True,
cascade='all, delete',
@ -110,6 +112,7 @@ class Activity(db.Model):
"max_speed": float(self.max_speed) if self.max_speed else None,
"ave_speed": float(self.ave_speed) if self.ave_speed else None,
"with_gpx": self.gpx is not None,
"bounds": [float(bound) for bound in self.bounds] if self.bounds else [], # noqa
"segments": [segment.serialize() for segment in self.segments]
}

View File

@ -52,6 +52,7 @@ def create_activity(
if gpx_data:
new_activity.gpx = gpx_data['filename']
new_activity.bounds = gpx_data['bounds']
update_activity_data(new_activity, gpx_data)
else:
new_activity.moving = duration

View File

@ -18,6 +18,21 @@ def assert_activity_data_with_gpx(data):
assert data['data']['activities'][0]['moving'] == '0:04:10'
assert data['data']['activities'][0]['pauses'] is None
assert data['data']['activities'][0]['with_gpx'] is True
assert len(data['data']['activities'][0]['segments']) == 1
segment = data['data']['activities'][0]['segments'][0]
assert segment['activity_id'] == 1
assert segment['segment_id'] == 0
assert segment['duration'] == '0:04:10'
assert segment['ascent'] == 0.4
assert segment['ave_speed'] == 4.6
assert segment['descent'] == 23.4
assert segment['distance'] == 0.32
assert segment['max_alt'] == 998.0
assert segment['max_speed'] == 5.09
assert segment['min_alt'] == 975.0
assert segment['moving'] == '0:04:10'
assert segment['pauses'] is None
def assert_activity_data_wo_gpx(data):