From 8bf9fcaa54f0315e6194f6317ddf586d54a5cba2 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 31 Jan 2019 08:43:03 +0100 Subject: [PATCH] bug fix --- rowers/c2stuff.py | 4 +- rowers/tests/c2jsonintervaldata.txt | 64 ++++++++++++++++++++++++++ rowers/tests/c2jsonsplitdata.txt | 47 +++++++++++++++++++ rowers/tests/testdata/testdata.csv.gz | Bin 11426 -> 11426 bytes rowers/tests/testdata/testdata.tcx | 2 +- rowers/views.py | 4 +- 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 rowers/tests/c2jsonintervaldata.txt create mode 100644 rowers/tests/c2jsonsplitdata.txt diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index dd345736..8a82b6a5 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -572,8 +572,10 @@ def get_workout(user,c2id): if 'workout' in data: if 'splits' in data['workout']: splitdata = data['workout']['splits'] - if 'intervals' in data['workout']: + elif 'intervals' in data['workout']: splitdata = data['workout']['intervals'] + else: + splitdata = None # Check if workout has stroke data, and get the stroke data diff --git a/rowers/tests/c2jsonintervaldata.txt b/rowers/tests/c2jsonintervaldata.txt new file mode 100644 index 00000000..3c37d306 --- /dev/null +++ b/rowers/tests/c2jsonintervaldata.txt @@ -0,0 +1,64 @@ +{ + "date": "2017-05-01 14:33:00", + "timezone": "Australia/Melbourne", + "workout_type": "VariableInterval", + "type": "rower", + "weight_class": "H", + "time": 16800, + "distance": 6721, + "rest_distance": 236, + "rest_time": 2700, + "calories_total": 427, + "drag_factor": 175, + "stroke_count": 996, + "stroke_rate": 33, + "workout": { + "intervals": [ + { + "type": "time", + "time": 2400, + "distance": 1011, + "rest_time": 600, + "rest_distance": 43, + "stroke_rate": 35, + "calories_total": 68 + }, + { + "type": "time", + "time": 3000, + "distance": 1229, + "rest_time": 600, + "rest_distance": 59, + "stroke_rate": 34, + "calories_total": 80 + }, + { + "type": "time", + "time": 3000, + "distance": 1190, + "rest_time": 600, + "rest_distance": 59, + "stroke_rate": 33, + "calories_total": 75 + }, + { + "type": "time", + "time": 2400, + "distance": 971, + "rest_time": 750, + "rest_distance": 44, + "stroke_rate": 34, + "calories_total": 62 + }, + { + "type": "time", + "time": 6000, + "distance": 2320, + "rest_time": 150, + "rest_distance": 31, + "stroke_rate": 32, + "calories_total": 142 + } + ] + } +} diff --git a/rowers/tests/c2jsonsplitdata.txt b/rowers/tests/c2jsonsplitdata.txt new file mode 100644 index 00000000..ff6f9815 --- /dev/null +++ b/rowers/tests/c2jsonsplitdata.txt @@ -0,0 +1,47 @@ +{ + "date": "2017-05-16 17:24:00", + "timezone": "US/Pacific", + "workout_type": "FixedTimeSplits", + "type": "rower", + "weight_class": "H", + "time": 6000, + "distance": 1789, + "stroke_count": 314, + "drag_factor": 134, + "stroke_rate": 31, + "calories_total": 90, + "workout": { + "splits": [ + { + "time": 1200, + "calories_total": 18, + "stroke_rate": 33, + "distance": 354 + }, + { + "time": 1200, + "calories_total": 18, + "stroke_rate": 31, + "distance": 355 + }, + { + "time": 1200, + "calories_total": 18, + "stroke_rate": 32, + "distance": 357 + }, + { + "time": 1200, + "calories_total": 18, + "stroke_rate": 31, + "distance": 363 + }, + { + "time": 1200, + "calories_total": 18, + "stroke_rate": 30, + "distance": 361 + } + ] + } +} diff --git a/rowers/tests/testdata/testdata.csv.gz b/rowers/tests/testdata/testdata.csv.gz index 806101ecd3bbee79024186e0a4e0a8ae8bcd9907..bec967baf833c83e63ccde42a6433b5b0a9fb66b 100644 GIT binary patch delta 15 WcmZ1!xhRrNzMF&N - <Element 'Notes' at 0x187d63c8> + <Element 'Notes' at 0x1d49a6d8> diff --git a/rowers/views.py b/rowers/views.py index 4ebd4374..8e374356 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -11369,8 +11369,10 @@ def workout_getimportview(request,externalid,source = 'c2'): if 'workout' in data: if 'splits' in data['workout']: splitdata = data['workout']['splits'] - if 'intervals' in data['workout']: + elif 'intervals' in data['workout']: splitdata = data['workout']['intervals'] + else: + splitdata = False else: splitdata = False