diff --git a/mpwo_api/mpwo_api/activities/activities.py b/mpwo_api/mpwo_api/activities/activities.py index c5b9b68d..8b49226a 100644 --- a/mpwo_api/mpwo_api/activities/activities.py +++ b/mpwo_api/mpwo_api/activities/activities.py @@ -207,7 +207,7 @@ def post_activity_no_gpx(auth_user_id): user_id=auth_user_id, sport_id=activity_data.get('sport_id'), activity_date=datetime.strptime( - activity_data.get('activity_date'), '%d/%m/%Y'), + activity_data.get('activity_date'), '%Y-%m-%d'), duration=timedelta(seconds=activity_data.get('duration')) ) new_activity.moving = new_activity.duration diff --git a/mpwo_api/mpwo_api/activities/models.py b/mpwo_api/mpwo_api/activities/models.py index c30edb27..e9d0c678 100644 --- a/mpwo_api/mpwo_api/activities/models.py +++ b/mpwo_api/mpwo_api/activities/models.py @@ -76,5 +76,6 @@ class Activity(db.Model): "descent": float(self.descent) if self.descent else None, "ascent": float(self.ascent) if self.ascent else None, "max_speed": float(self.max_speed) if self.max_speed else None, - "ave_speed": float(self.ave_speed) if self.ave_speed else None + "ave_speed": float(self.ave_speed) if self.ave_speed else None, + "with_gpx": self.gpx is not None } diff --git a/mpwo_api/mpwo_api/tests/test_activities.py b/mpwo_api/mpwo_api/tests/test_activities.py index ccee96f0..ca11d688 100644 --- a/mpwo_api/mpwo_api/tests/test_activities.py +++ b/mpwo_api/mpwo_api/tests/test_activities.py @@ -55,12 +55,14 @@ def test_get_all_activities_for_authenticated_user(app): assert 1 == data['data']['activities'][0]['user_id'] assert 2 == data['data']['activities'][0]['sport_id'] assert '0:17:04' == data['data']['activities'][0]['duration'] + assert data['data']['activities'][0]['with_gpx'] is False assert 'creation_date' in data['data']['activities'][1] assert 'Sun, 01 Apr 2018 00:00:00 GMT' == data['data']['activities'][1]['activity_date'] # noqa assert 1 == data['data']['activities'][1]['user_id'] assert 1 == data['data']['activities'][1]['sport_id'] assert '1:40:00' == data['data']['activities'][1]['duration'] + assert data['data']['activities'][0]['with_gpx'] is False def test_get_activities_for_authenticated_user_no_activity(app): @@ -133,6 +135,22 @@ def test_add_an_activity_gpx(app): assert response.status_code == 201 assert 'created' in data['status'] + assert len(data['data']['activities']) == 1 + assert 'creation_date' in data['data']['activities'][0] + assert 'Tue, 13 Mar 2018 12:44:45 GMT' == data['data']['activities'][0]['activity_date'] # noqa + assert 1 == data['data']['activities'][0]['user_id'] + assert 1 == data['data']['activities'][0]['sport_id'] + assert '0:04:10' == data['data']['activities'][0]['duration'] + assert data['data']['activities'][0]['ascent'] == 0.4 + assert data['data']['activities'][0]['ave_speed'] == 4.6 + assert data['data']['activities'][0]['descent'] == 23.4 + assert data['data']['activities'][0]['distance'] == 0.32 + assert data['data']['activities'][0]['max_alt'] == 998.0 + assert data['data']['activities'][0]['max_speed'] == 5.09 + assert data['data']['activities'][0]['min_alt'] == 975.0 + 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 def test_add_an_activity_gpx_invalid_file(app): @@ -252,7 +270,7 @@ def test_add_an_activity_no_gpx(app): data=json.dumps(dict( sport_id=1, duration=3600, - activity_date='15/05/2018', + activity_date='2018-05-15', distance=10 )), headers=dict( @@ -280,6 +298,7 @@ def test_add_an_activity_no_gpx(app): assert data['data']['activities'][0]['min_alt'] is None assert data['data']['activities'][0]['moving'] == '1:00:00' assert data['data']['activities'][0]['pauses'] is None + assert data['data']['activities'][0]['with_gpx'] is False def test_add_an_activity_no_gpx_invalid_payload(app): @@ -396,6 +415,7 @@ def test_get_an_activity_without_gpx(app): assert data['data']['activities'][0]['min_alt'] is None assert data['data']['activities'][0]['moving'] is None assert data['data']['activities'][0]['pauses'] is None + assert data['data']['activities'][0]['with_gpx'] is False def test_get_an_activity_with_gpx(app): @@ -452,3 +472,4 @@ def test_get_an_activity_with_gpx(app): assert data['data']['activities'][0]['min_alt'] == 975.0 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 diff --git a/mpwo_client/src/actions/activities.js b/mpwo_client/src/actions/activities.js index e167b6d7..b05ebdbf 100644 --- a/mpwo_client/src/actions/activities.js +++ b/mpwo_client/src/actions/activities.js @@ -19,6 +19,18 @@ export const addActivity = form => dispatch => mpwoApi .catch(error => dispatch(setError(`activities: ${error}`))) +export const addActivityWithoutGpx = form => dispatch => mpwoApi + .addActivityWithoutGpx(form) + .then(ret => { + if (ret.status === 'created') { + history.push('/') + } else { + dispatch(setError(`activities: ${ret.message}`)) + } + }) + .catch(error => dispatch(setError(`activities: ${error}`))) + + export const getActivityGpx = activityId => dispatch => { if (activityId) { return mpwoApi diff --git a/mpwo_client/src/components/Activities/ActivityAdd.jsx b/mpwo_client/src/components/Activities/ActivityAdd.jsx index bb55399c..9608631d 100644 --- a/mpwo_client/src/components/Activities/ActivityAdd.jsx +++ b/mpwo_client/src/components/Activities/ActivityAdd.jsx @@ -3,16 +3,33 @@ import { Helmet } from 'react-helmet' import { connect } from 'react-redux' import FormWithGpx from './ActivityForms/FormWithGpx' +import FormWithoutGpx from './ActivityForms/FormWithoutGpx' import { getData } from '../../actions/index' class AddActivity extends React.Component { + constructor(props, context) { + super(props, context) + this.state = { + withGpx: true, + } + } + componentDidMount() { this.props.loadSports() } + handleRadioChange (changeEvent) { + this.setState({ + withGpx: + changeEvent.target.name === 'withGpx' + ? changeEvent.target.value : !changeEvent.target.value + }) + } + render() { const { message, sports } = this.props + const { withGpx } = this.state return (
{' '} Duration: {activity.duration} {' '} - {activity.pauses !== '0:00:00' && ( + {activity.pauses !== '0:00:00' && + activity.pauses !== null && ( `(pauses: ${activity.pauses})` )}
@@ -56,14 +57,18 @@ class ActivityDisplay extends React.Component { Average speed: {activity.ave_speed} km/h -{' '} Max speed : {activity.max_speed} km/h + {activity.min_alt && activity.max_alt && ({' '} Min altitude: {activity.min_alt}m -{' '} Max altitude: {activity.max_alt}m
+ )} + {activity.ascent && activity.descent && ({' '} Ascent: {activity.ascent}m -{' '} Descent: {activity.descent}m
+ )} @@ -73,7 +78,11 @@ class ActivityDisplay extends React.Component { Map