From 45a6300c76d98eba57ea4ef9e3355f5637d5444c Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 4 Jul 2018 13:30:30 +0200 Subject: [PATCH] under armour & trainingpeaks done --- rowers/imports.py | 12 +- rowers/testdata/tpuploadresponse.txt | 1 + rowers/testdata/uapostworkoutresponse.txt | 1 + rowers/testdata/uastrokes.txt | 1 + rowers/testdata/uauser.txt | 1 + rowers/testdata/uaworkoutlist.txt | 1 + rowers/tests.py | 260 +++++++++++++++++++++- rowers/tpstuff.py | 16 +- rowers/underarmourstuff.py | 3 +- 9 files changed, 271 insertions(+), 25 deletions(-) create mode 100644 rowers/testdata/tpuploadresponse.txt create mode 100644 rowers/testdata/uapostworkoutresponse.txt create mode 100644 rowers/testdata/uastrokes.txt create mode 100644 rowers/testdata/uauser.txt create mode 100644 rowers/testdata/uaworkoutlist.txt diff --git a/rowers/imports.py b/rowers/imports.py index 06b7149f..9a2c2087 100644 --- a/rowers/imports.py +++ b/rowers/imports.py @@ -81,7 +81,7 @@ def imports_open(user,oauth_data): refreshtoken = None try: - tokenexpirydate = getattr(r,oauthdata['expirydatename']) + tokenexpirydate = getattr(r,oauth_data['expirydatename']) except AttributeError: tokenexpirydate = None @@ -97,7 +97,7 @@ def imports_open(user,oauth_data): return token -# Refresh ST token using refresh token +# Refresh token using refresh token def imports_do_refresh_token(refreshtoken,oauth_data,access_token=''): client_auth = requests.auth.HTTPBasicAuth( oauth_data['client_id'], @@ -105,16 +105,15 @@ def imports_do_refresh_token(refreshtoken,oauth_data,access_token=''): ) post_data = {"grant_type": "refresh_token", - "client_secret": client_secret, - "client_id": client_id, + "client_secret": oauth_data['client_secret'], + "client_id": oauth_data['client_id'], "refresh_token": refreshtoken, } headers = {'user-agent': 'sanderroosendaal', 'Accept': 'application/json', 'Content-Type': oauth_data['content_type']} - if oauth_data['bearer_auth']: - + if oauth_data['bearer_auth']: headers['authorization'] = 'Bearer %s' % access_token baseurl = oauth_data['base_url'] @@ -129,6 +128,7 @@ def imports_do_refresh_token(refreshtoken,oauth_data,access_token=''): headers=headers) token_json = response.json() + thetoken = token_json['access_token'] expires_in = token_json['expires_in'] try: diff --git a/rowers/testdata/tpuploadresponse.txt b/rowers/testdata/tpuploadresponse.txt new file mode 100644 index 00000000..9e8bc7d1 --- /dev/null +++ b/rowers/testdata/tpuploadresponse.txt @@ -0,0 +1 @@ +[{"EnergyPlanned": null, "ElevationMaximum": null, "HeartRateMinimum": null, "Title": "2ks with focus (6)", "HeartRateMaximum": null, "CaloriesPlanned": null, "WorkoutDay": "2018-07-02T00:00:00-06:00", "VelocityMaximum": null, "StartTimePlanned": null, "PowerAverage": null, "ElevationMinimum": null, "TssCalculationMethod": null, "VelocityAverage": null, "AthleteId": 1696848, "Completed": true, "CadenceAverage": null, "TssActual": null, "IFPlanned": null, "ElevationLoss": null, "HeartRateAverage": null, "Energy": null, "WorkoutType": "Rowing", "TorqueMaximum": null, "Distance": 1328.0, "VelocityPlanned": null, "TssPlanned": null, "TempAvg": null, "TorqueAverage": null, "Calories": null, "ElevationAverage": null, "PowerMaximum": null, "TotalTimePlanned": null, "ElevationGainPlanned": null, "Feeling": null, "DistanceCustomized": null, "IF": null, "TotalTime": 0.10333333333333333, "NormalizedPower": null, "NormalizedSpeed": null, "DistancePlanned": null, "CadenceMaximum": null, "ElevationGain": null, "TempMin": null, "Rpe": null, "StartTime": "2018-07-02T11:24:05-06:00", "Id": 615737179, "TempMax": null}] \ No newline at end of file diff --git a/rowers/testdata/uapostworkoutresponse.txt b/rowers/testdata/uapostworkoutresponse.txt new file mode 100644 index 00000000..b4430880 --- /dev/null +++ b/rowers/testdata/uapostworkoutresponse.txt @@ -0,0 +1 @@ +{"start_datetime": "2018-07-02T17:24:05+00:00", "name": "2ks with focus (6)", "is_default_name": false, "created_datetime": "2018-07-04T09:17:58+00:00", "notes": " \n from strava via rowsandall.com", "updated_datetime": "2018-07-04T09:17:58+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2136037651/", "id": "2136037651"}], "documentation": [{"href": "https://developer.underarmour.com/docs/v71_Workout"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2994311008/", "id": "2994311008"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 372.0, "distance_total": 1328.000091264, "cadence_max": 11.0, "speed_max": 4.3000016, "speed_min": 1.6666679, "cadence_min": 9.0, "speed_avg": 3.6897879, "cadence_avg": 9.0, "elapsed_time_total": 372.0, "heartrate_avg": 148.0}} \ No newline at end of file diff --git a/rowers/testdata/uastrokes.txt b/rowers/testdata/uastrokes.txt new file mode 100644 index 00000000..d1940978 --- /dev/null +++ b/rowers/testdata/uastrokes.txt @@ -0,0 +1 @@ +{"start_datetime": "2018-07-02T17:24:05+00:00", "name": "2ks with focus (6)", "is_default_name": false, "created_datetime": "2018-07-04T09:17:58+00:00", "notes": " \n from strava via rowsandall.com", "updated_datetime": "2018-07-04T09:17:58+00:00", "time_series": {"distance": [[0.0, 72], [26.0, 72], [30.0, 81], [33.0, 91], [36.0, 102], [39.0, 114], [42.0, 126], [45.0, 138], [48.0, 151], [51.0, 162], [54.0, 175], [57.0, 187], [60.0, 200], [63.0, 212], [66.0, 224], [69.0, 236], [72.0, 248], [75.0, 259], [78.0, 271], [81.0, 283], [84.0, 294], [87.0, 307], [90.0, 320], [93.0, 332], [96.0, 343], [99.0, 356], [102.0, 368], [105.0, 380], [108.0, 392], [111.0, 404], [114.0, 416], [117.0, 428], [120.0, 441], [123.0, 452], [126.0, 465], [129.0, 477], [132.0, 489], [135.0, 501], [138.0, 514], [141.0, 527], [144.0, 539], [147.0, 551], [150.0, 563], [153.0, 575], [156.0, 588], [159.0, 600], [162.0, 612], [165.0, 625], [168.0, 637], [172.0, 650], [174.0, 661], [178.0, 674], [181.0, 686], [184.0, 698], [187.0, 710], [190.0, 722], [193.0, 734], [196.0, 746], [199.0, 759], [202.0, 771], [205.0, 783], [208.0, 795], [211.0, 808], [214.0, 820], [217.0, 832], [220.0, 845], [223.0, 857], [226.0, 869], [246.0, 910], [249.0, 916], [252.0, 923], [256.0, 933], [259.0, 944], [262.0, 955], [265.0, 966], [268.0, 978], [271.0, 990], [275.0, 1002], [278.0, 1014], [281.0, 1025], [284.0, 1037], [287.0, 1050], [290.0, 1061], [293.0, 1073], [296.0, 1084], [299.0, 1095], [302.0, 1106], [305.0, 1116], [307.0, 1127], [310.0, 1137], [313.0, 1147], [316.0, 1158], [319.0, 1168], [321.0, 1177], [324.0, 1187], [327.0, 1196], [330.0, 1207], [333.0, 1216], [336.0, 1226], [338.0, 1236], [341.0, 1246], [344.0, 1255], [347.0, 1263], [351.0, 1272], [354.0, 1280], [357.0, 1288], [360.0, 1297], [363.0, 1306], [366.0, 1313], [369.0, 1321], [372.0, 1328]], "heartrate": [[0.0, 109], [26.0, 121], [30.0, 119], [33.0, 118], [36.0, 117], [39.0, 118], [42.0, 119], [45.0, 122], [48.0, 123], [51.0, 126], [54.0, 127], [57.0, 129], [60.0, 130], [63.0, 130], [66.0, 131], [69.0, 131], [72.0, 132], [75.0, 133], [78.0, 134], [81.0, 134], [84.0, 135], [87.0, 136], [90.0, 139], [93.0, 141], [96.0, 142], [99.0, 143], [102.0, 144], [105.0, 145], [108.0, 146], [111.0, 146], [114.0, 146], [117.0, 146], [120.0, 147], [123.0, 147], [126.0, 148], [129.0, 149], [132.0, 150], [135.0, 150], [138.0, 151], [141.0, 152], [144.0, 153], [147.0, 153], [150.0, 154], [153.0, 154], [156.0, 155], [159.0, 155], [162.0, 154], [165.0, 155], [168.0, 156], [172.0, 156], [174.0, 156], [178.0, 156], [181.0, 156], [184.0, 156], [187.0, 156], [190.0, 155], [193.0, 155], [196.0, 156], [199.0, 157], [202.0, 160], [205.0, 161], [208.0, 162], [211.0, 163], [214.0, 163], [217.0, 164], [220.0, 164], [223.0, 165], [226.0, 165], [246.0, 161], [249.0, 160], [252.0, 158], [256.0, 161], [259.0, 162], [262.0, 162], [265.0, 158], [268.0, 154], [271.0, 152], [275.0, 152], [278.0, 151], [281.0, 151], [284.0, 151], [287.0, 151], [290.0, 151], [293.0, 151], [296.0, 151], [299.0, 152], [302.0, 152], [305.0, 152], [307.0, 152], [310.0, 152], [313.0, 153], [316.0, 153], [319.0, 154], [321.0, 155], [324.0, 155], [327.0, 156], [330.0, 156], [333.0, 155], [336.0, 155], [338.0, 155], [341.0, 155], [344.0, 155], [347.0, 155], [351.0, 155], [354.0, 154], [357.0, 152], [360.0, 151], [363.0, 150], [366.0, 149], [369.0, 148], [372.0, 147]], "cadence": [[0.0, 19], [26.0, 19], [30.0, 20], [33.0, 19], [36.0, 19], [39.0, 20], [42.0, 19], [45.0, 20], [48.0, 20], [51.0, 20], [54.0, 20], [57.0, 19], [60.0, 20], [63.0, 20], [66.0, 20], [69.0, 19], [72.0, 20], [75.0, 20], [78.0, 20], [81.0, 20], [84.0, 20], [87.0, 19], [90.0, 20], [93.0, 20], [96.0, 20], [99.0, 20], [102.0, 20], [105.0, 20], [108.0, 20], [111.0, 20], [114.0, 20], [117.0, 20], [120.0, 20], [123.0, 19], [126.0, 20], [129.0, 20], [132.0, 20], [135.0, 19], [138.0, 20], [141.0, 20], [144.0, 19], [147.0, 20], [150.0, 19], [153.0, 20], [156.0, 19], [159.0, 19], [162.0, 19], [165.0, 19], [168.0, 20], [172.0, 19], [174.0, 20], [178.0, 20], [181.0, 20], [184.0, 20], [187.0, 20], [190.0, 20], [193.0, 20], [196.0, 19], [199.0, 19], [202.0, 20], [205.0, 20], [208.0, 20], [211.0, 20], [214.0, 20], [217.0, 20], [220.0, 20], [223.0, 20], [226.0, 20], [246.0, 22], [249.0, 18], [252.0, 18], [256.0, 19], [259.0, 19], [262.0, 19], [265.0, 19], [268.0, 19], [271.0, 19], [275.0, 19], [278.0, 19], [281.0, 19], [284.0, 19], [287.0, 19], [290.0, 19], [293.0, 20], [296.0, 21], [299.0, 20], [302.0, 21], [305.0, 20], [307.0, 21], [310.0, 21], [313.0, 21], [316.0, 22], [319.0, 21], [321.0, 21], [324.0, 21], [327.0, 21], [330.0, 21], [333.0, 21], [336.0, 22], [338.0, 21], [341.0, 20], [344.0, 20], [347.0, 19], [351.0, 19], [354.0, 18], [357.0, 18], [360.0, 19], [363.0, 19], [366.0, 19], [369.0, 19], [372.0, 21]], "position": [[0.0, {"lat": 49.245117, "lng": 16.504335, "elevation": 227.0}], [26.0, {"lat": 49.244682, "lng": 16.504757, "elevation": 227.0}], [30.0, {"lat": 49.24461, "lng": 16.504818, "elevation": 227.0}], [33.0, {"lat": 49.244526, "lng": 16.504883, "elevation": 227.0}], [36.0, {"lat": 49.244434, "lng": 16.50495, "elevation": 227.0}], [39.0, {"lat": 49.244343, "lng": 16.505022, "elevation": 227.0}], [42.0, {"lat": 49.244244, "lng": 16.505089, "elevation": 227.0}], [45.0, {"lat": 49.244141, "lng": 16.505159, "elevation": 227.0}], [48.0, {"lat": 49.244041, "lng": 16.505224, "elevation": 227.0}], [51.0, {"lat": 49.243942, "lng": 16.505276, "elevation": 227.0}], [54.0, {"lat": 49.243832, "lng": 16.505325, "elevation": 227.0}], [57.0, {"lat": 49.243729, "lng": 16.505367, "elevation": 227.0}], [60.0, {"lat": 49.243618, "lng": 16.505405, "elevation": 227.0}], [63.0, {"lat": 49.243511, "lng": 16.50544, "elevation": 227.0}], [66.0, {"lat": 49.243401, "lng": 16.50547, "elevation": 227.0}], [69.0, {"lat": 49.243294, "lng": 16.505499, "elevation": 227.0}], [72.0, {"lat": 49.243191, "lng": 16.505527, "elevation": 227.0}], [75.0, {"lat": 49.243092, "lng": 16.505547, "elevation": 227.0}], [78.0, {"lat": 49.242989, "lng": 16.505571, "elevation": 227.0}], [81.0, {"lat": 49.242882, "lng": 16.505596, "elevation": 227.0}], [84.0, {"lat": 49.242779, "lng": 16.505621, "elevation": 227.0}], [87.0, {"lat": 49.242664, "lng": 16.50565, "elevation": 227.0}], [90.0, {"lat": 49.242554, "lng": 16.505676, "elevation": 227.0}], [93.0, {"lat": 49.242447, "lng": 16.505703, "elevation": 227.0}], [96.0, {"lat": 49.242344, "lng": 16.505726, "elevation": 227.0}], [99.0, {"lat": 49.242229, "lng": 16.50576, "elevation": 227.0}], [102.0, {"lat": 49.242123, "lng": 16.505798, "elevation": 227.0}], [105.0, {"lat": 49.242023, "lng": 16.505838, "elevation": 227.0}], [108.0, {"lat": 49.24192, "lng": 16.505886, "elevation": 227.0}], [111.0, {"lat": 49.241818, "lng": 16.505941, "elevation": 227.0}], [114.0, {"lat": 49.241714, "lng": 16.505997, "elevation": 227.0}], [117.0, {"lat": 49.241615, "lng": 16.50606, "elevation": 227.0}], [120.0, {"lat": 49.241512, "lng": 16.506125, "elevation": 227.0}], [123.0, {"lat": 49.241413, "lng": 16.506189, "elevation": 227.0}], [126.0, {"lat": 49.241306, "lng": 16.50626, "elevation": 227.0}], [129.0, {"lat": 49.241215, "lng": 16.506323, "elevation": 227.0}], [132.0, {"lat": 49.241112, "lng": 16.506395, "elevation": 227.0}], [135.0, {"lat": 49.241016, "lng": 16.506472, "elevation": 227.0}], [138.0, {"lat": 49.240913, "lng": 16.506557, "elevation": 227.0}], [141.0, {"lat": 49.240818, "lng": 16.506636, "elevation": 227.0}], [144.0, {"lat": 49.240715, "lng": 16.506721, "elevation": 227.0}], [147.0, {"lat": 49.240623, "lng": 16.506802, "elevation": 227.0}], [150.0, {"lat": 49.240532, "lng": 16.506887, "elevation": 227.0}], [153.0, {"lat": 49.240437, "lng": 16.506968, "elevation": 227.0}], [156.0, {"lat": 49.240337, "lng": 16.507055, "elevation": 227.0}], [159.0, {"lat": 49.240242, "lng": 16.507133, "elevation": 227.0}], [162.0, {"lat": 49.240147, "lng": 16.507212, "elevation": 227.0}], [165.0, {"lat": 49.240044, "lng": 16.507296, "elevation": 227.0}], [168.0, {"lat": 49.239952, "lng": 16.507376, "elevation": 227.0}], [172.0, {"lat": 49.239853, "lng": 16.50746, "elevation": 227.0}], [174.0, {"lat": 49.239761, "lng": 16.507534, "elevation": 227.0}], [178.0, {"lat": 49.239662, "lng": 16.507614, "elevation": 227.0}], [181.0, {"lat": 49.239563, "lng": 16.507688, "elevation": 227.0}], [184.0, {"lat": 49.239464, "lng": 16.507763, "elevation": 227.0}], [187.0, {"lat": 49.239365, "lng": 16.507835, "elevation": 227.0}], [190.0, {"lat": 49.239269, "lng": 16.507906, "elevation": 227.0}], [193.0, {"lat": 49.23917, "lng": 16.507978, "elevation": 227.0}], [196.0, {"lat": 49.239075, "lng": 16.508049, "elevation": 227.0}], [199.0, {"lat": 49.238968, "lng": 16.508125, "elevation": 227.0}], [202.0, {"lat": 49.238873, "lng": 16.508202, "elevation": 227.0}], [205.0, {"lat": 49.238777, "lng": 16.50828, "elevation": 227.0}], [208.0, {"lat": 49.238678, "lng": 16.508356, "elevation": 227.0}], [211.0, {"lat": 49.238579, "lng": 16.508434, "elevation": 227.0}], [214.0, {"lat": 49.238483, "lng": 16.508514, "elevation": 227.0}], [217.0, {"lat": 49.23838, "lng": 16.508587, "elevation": 227.0}], [220.0, {"lat": 49.238285, "lng": 16.508659, "elevation": 227.0}], [223.0, {"lat": 49.238186, "lng": 16.508732, "elevation": 227.0}], [226.0, {"lat": 49.238087, "lng": 16.508804, "elevation": 227.0}], [246.0, {"lat": 49.237766, "lng": 16.509081, "elevation": 227.0}], [249.0, {"lat": 49.237755, "lng": 16.50915, "elevation": 227.0}], [252.0, {"lat": 49.23774, "lng": 16.509256, "elevation": 227.0}], [256.0, {"lat": 49.237728, "lng": 16.509386, "elevation": 227.0}], [259.0, {"lat": 49.237713, "lng": 16.509533, "elevation": 227.0}], [262.0, {"lat": 49.237698, "lng": 16.50968, "elevation": 227.0}], [265.0, {"lat": 49.237679, "lng": 16.509838, "elevation": 227.0}], [268.0, {"lat": 49.237659, "lng": 16.509998, "elevation": 227.0}], [271.0, {"lat": 49.237637, "lng": 16.510162, "elevation": 227.0}], [275.0, {"lat": 49.237614, "lng": 16.510325, "elevation": 227.0}], [278.0, {"lat": 49.237595, "lng": 16.510479, "elevation": 227.0}], [281.0, {"lat": 49.237572, "lng": 16.510632, "elevation": 227.0}], [284.0, {"lat": 49.237553, "lng": 16.510798, "elevation": 227.0}], [287.0, {"lat": 49.23753, "lng": 16.510962, "elevation": 227.0}], [290.0, {"lat": 49.237507, "lng": 16.51112, "elevation": 227.0}], [293.0, {"lat": 49.23748, "lng": 16.511272, "elevation": 227.0}], [296.0, {"lat": 49.237461, "lng": 16.511421, "elevation": 227.0}], [299.0, {"lat": 49.237442, "lng": 16.511572, "elevation": 227.0}], [302.0, {"lat": 49.237431, "lng": 16.511717, "elevation": 227.0}], [305.0, {"lat": 49.237423, "lng": 16.511864, "elevation": 227.0}], [307.0, {"lat": 49.237423, "lng": 16.512009, "elevation": 227.0}], [310.0, {"lat": 49.237431, "lng": 16.51215, "elevation": 227.0}], [313.0, {"lat": 49.237446, "lng": 16.512289, "elevation": 227.0}], [316.0, {"lat": 49.237472, "lng": 16.512424, "elevation": 227.0}], [319.0, {"lat": 49.237503, "lng": 16.512552, "elevation": 227.0}], [321.0, {"lat": 49.237541, "lng": 16.512667, "elevation": 227.0}], [324.0, {"lat": 49.237591, "lng": 16.512783, "elevation": 227.0}], [327.0, {"lat": 49.237648, "lng": 16.512882, "elevation": 227.0}], [330.0, {"lat": 49.237713, "lng": 16.512979, "elevation": 227.0}], [333.0, {"lat": 49.237782, "lng": 16.513058, "elevation": 227.0}], [336.0, {"lat": 49.237862, "lng": 16.51313, "elevation": 227.0}], [338.0, {"lat": 49.237942, "lng": 16.513184, "elevation": 227.0}], [341.0, {"lat": 49.238022, "lng": 16.513227, "elevation": 227.0}], [344.0, {"lat": 49.238098, "lng": 16.513269, "elevation": 227.0}], [347.0, {"lat": 49.238167, "lng": 16.513304, "elevation": 227.0}], [351.0, {"lat": 49.238243, "lng": 16.513334, "elevation": 227.0}], [354.0, {"lat": 49.238316, "lng": 16.513361, "elevation": 227.0}], [357.0, {"lat": 49.238388, "lng": 16.513384, "elevation": 227.02}], [360.0, {"lat": 49.238468, "lng": 16.513409, "elevation": 227.06}], [363.0, {"lat": 49.238544, "lng": 16.513428, "elevation": 227.11}], [366.0, {"lat": 49.238613, "lng": 16.513451, "elevation": 227.19}], [369.0, {"lat": 49.238682, "lng": 16.513474, "elevation": 227.28}], [372.0, {"lat": 49.238739, "lng": 16.513494, "elevation": 227.38}]]}, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2136037651/", "id": "2136037651"}], "documentation": [{"href": "https://developer.underarmour.com/docs/v71_Workout"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2994311008/?field_set=time_series", "id": "2994311008"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "reference_key": null, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 372.0, "distance_total": 1328.000091264, "cadence_max": 11.0, "speed_max": 4.3000016, "speed_min": 1.6666679, "cadence_min": 9.0, "speed_avg": 3.6897879, "cadence_avg": 9.0, "elapsed_time_total": 372.0, "heartrate_avg": 148.0}} \ No newline at end of file diff --git a/rowers/testdata/uauser.txt b/rowers/testdata/uauser.txt new file mode 100644 index 00000000..d7c9eb56 --- /dev/null +++ b/rowers/testdata/uauser.txt @@ -0,0 +1 @@ +{"last_name": "Roosendaal", "weight": null, "communication": {"promotions": false, "newsletter": false, "system_messages": false}, "height": null, "hobbies": "", "id": 109227799, "date_joined": "2017-03-28T11:32:53+00:00", "first_name": "Sander", "display_name": "Sander Roosendaal", "introduction": "", "display_measurement_system": "metric", "last_login": "2017-03-28T11:32:53+00:00", "location": {"country": "US", "region": "VA", "address": "", "locality": "Ashburn"}, "_links": {"stats": [{"href": "/v7.1/user_stats/109227799/?aggregate_by_period=month", "id": "109227799", "name": "month"}, {"href": "/v7.1/user_stats/109227799/?aggregate_by_period=day", "id": "109227799", "name": "day"}, {"href": "/v7.1/user_stats/109227799/?aggregate_by_period=week", "id": "109227799", "name": "week"}, {"href": "/v7.1/user_stats/109227799/?aggregate_by_period=year", "id": "109227799", "name": "year"}, {"href": "/v7.1/user_stats/109227799/?aggregate_by_period=lifetime", "id": "109227799", "name": "lifetime"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1", "name": "status_post"}, {"href": "/v7.1/privacy_option/1/", "id": "1", "name": "workout"}, {"href": "/v7.1/privacy_option/0/", "id": "0", "name": "workout_music"}, {"href": "/v7.1/privacy_option/3/", "id": "3", "name": "activity_feed"}, {"href": "/v7.1/privacy_option/0/", "id": "0", "name": "bodymass"}, {"href": "/v7.1/privacy_option/1/", "id": "1", "name": "food_log"}, {"href": "/v7.1/privacy_option/3/", "id": "3", "name": "email_search"}, {"href": "/v7.1/privacy_option/1/", "id": "1", "name": "profile"}, {"href": "/v7.1/privacy_option/1/", "id": "1", "name": "route"}, {"href": "/v7.1/privacy_option/0/", "id": "0", "name": "sleep"}], "image": [{"href": "/v7.1/user_profile_photo/109227799/", "id": "109227799", "name": "user_profile_photo"}], "documentation": [{"href": "https://developer.underarmour.com/docs/v71_User"}], "deactivation": [{"href": "/v7.1/user_deactivation/"}], "user_achievements": [{"href": "/v7.1/user_achievement/?user=109227799"}], "friendships": [{"href": "/v7.1/friendship/?from_user=109227799"}], "workouts": [{"href": "/v7.1/workout/?user=109227799&order_by=-start_datetime"}], "self": [{"href": "/v7.1/user/109227799/", "id": "109227799"}]}, "email": "roosendaalsander@gmail.com", "goal_statement": null, "username": "Sander109227799", "sharing": {"twitter": false, "facebook": false}, "last_initial": "R.", "preferred_language": "en-US", "gender": "M", "time_zone": "Europe/Bratislava", "birthdate": "1972-04-19", "profile_statement": ""} \ No newline at end of file diff --git a/rowers/testdata/uaworkoutlist.txt b/rowers/testdata/uaworkoutlist.txt new file mode 100644 index 00000000..0edff012 --- /dev/null +++ b/rowers/testdata/uaworkoutlist.txt @@ -0,0 +1 @@ +{"_embedded": {"workouts": [{"start_datetime": "2018-07-02T17:24:05+00:00", "name": "2ks with focus (6)", "is_default_name": false, "created_datetime": "2018-07-04T09:17:58+00:00", "notes": " \n from strava via rowsandall.com", "updated_datetime": "2018-07-04T09:17:58+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2994311008/", "id": "2994311008"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2136037651/", "id": "2136037651"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 372.0, "distance_total": 1328.000091264, "cadence_max": 11.0, "speed_max": 4.3000016, "speed_min": 1.6666679, "cadence_min": 9.0, "speed_avg": 3.6897879, "cadence_avg": 9.0, "elapsed_time_total": 372.0, "heartrate_avg": 148.0}}, {"start_datetime": "2018-05-15T10:35:00+00:00", "name": "Turin", "is_default_name": false, "created_datetime": "2018-05-18T08:16:04+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T08:16:04+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"self": [{"href": "/v7.1/workout/2893713871/", "id": "2893713871"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 0.0, "elapsed_time_total": 0.0, "distance_total": 0.0}}, {"start_datetime": "2018-05-14T13:53:04+00:00", "name": "Hradiste", "is_default_name": false, "created_datetime": "2018-05-18T09:37:59+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T09:37:59+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893767499/", "id": "2893767499"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064193549/", "id": "2064193549"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 1500.0, "distance_total": 6090.99689088, "cadence_max": 45.0, "speed_max": 50.78598, "speed_min": 0.024136182, "cadence_min": 8.0, "speed_avg": 4.6101894, "cadence_avg": 28.0, "elapsed_time_total": 1500.0, "heartrate_avg": 177.0}}, {"start_datetime": "2018-05-13T09:22:49+00:00", "name": "Completed a workout (generic) 0.6 mi on 05/13/18", "is_default_name": true, "created_datetime": "2018-05-17T08:58:45+00:00", "notes": "", "updated_datetime": "2018-05-17T08:59:03+00:00", "reference_key": "2018-05-13T09:22:49.000Z", "start_locale_timezone": "Europe/Bratislava", "source": "Unknown File", "source_manufacturer": "unknown", "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2891557930/", "id": "2891557930"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2062649698/", "id": "2062649698"}], "activity_type": [{"href": "/v7.1/activity_type/21/", "id": "21"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 233.0, "cadence_min": 27.0, "distance_total": 972.999726336, "cadence_max": 41.0, "speed_max": 5.7333326, "speed_min": 0.30000004, "heartrate_min": 117.0, "power_min": 27.0, "speed_avg": 4.201863, "cadence_avg": 31.0, "power_avg": 282.436, "heartrate_max": 136.0, "power_max": 511.0, "elapsed_time_total": 233.0, "heartrate_avg": 125.0, "metabolic_energy_total": 4184.0}}, {"start_datetime": "2018-05-13T09:22:49+00:00", "name": "Piestany Race (1) (2)", "is_default_name": false, "created_datetime": "2018-05-18T11:42:30+00:00", "notes": "imported through email\r\n from speedcoach2v2.15 via rowsandall.com\n from unknown via rowsandall.com", "updated_datetime": "2018-05-18T11:42:31+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893934296/", "id": "2893934296"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064309187/", "id": "2064309187"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 233.0, "distance_total": 972.999726336, "cadence_max": 20.0, "speed_max": 5.100011, "speed_min": 1.069047, "cadence_min": 13.0, "speed_avg": 4.1767173, "cadence_avg": 15.0, "elapsed_time_total": 233.0, "heartrate_avg": 125.0}}, {"start_datetime": "2018-05-13T08:02:00+00:00", "name": "Mixed 4x", "is_default_name": false, "created_datetime": "2018-05-17T09:48:01+00:00", "notes": "from unknown via rowsandall.com\r\nFailed to download METAR data\r\nSummary for your location at 2018-05-13T18:06:11+00:00: Partly Cloudy. Temperature 70.76F/21.5C. Wind: 1.3 m/s. Wind Bearing: 117 degrees\n from unknown via rowsandall.com", "updated_datetime": "2018-05-17T09:48:01+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"self": [{"href": "/v7.1/workout/2891593603/", "id": "2891593603"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 0.0, "elapsed_time_total": 0.0, "distance_total": 0.0}}, {"start_datetime": "2018-05-13T07:57:02+00:00", "name": "Piestany (2)", "is_default_name": false, "created_datetime": "2018-05-18T11:44:24+00:00", "notes": "imported through email\n from speedcoach2v2.15 via rowsandall.com\n from speedcoach2v2.15 via rowsandall.com", "updated_datetime": "2018-05-18T11:44:24+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893937560/", "id": "2893937560"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064311308/", "id": "2064311308"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 2111.0, "distance_total": 4604.99301504, "cadence_max": 37.0, "speed_max": 5.3203125, "speed_min": 0.0709524, "cadence_min": 4.0, "speed_avg": 2.644988, "cadence_avg": 11.0, "elapsed_time_total": 2111.0, "heartrate_avg": 126.0}}, {"start_datetime": "2018-05-12T15:47:00+00:00", "name": "MM 4x", "is_default_name": false, "created_datetime": "2018-05-18T12:48:24+00:00", "notes": "from unknown via rowsandall.com\nFailed to download METAR data\nSummary for your location at 2018-05-12T16:08:53+00:00: Drizzle. Temperature 70.74F/21.5C. Wind: 1.37 m/s. Wind Bearing: 7 degrees\n from unknown via rowsandall.com", "updated_datetime": "2018-05-18T12:48:24+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2894050207/", "id": "2894050207"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064393991/", "id": "2064393991"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 2624.0, "distance_total": 5929.00032384, "cadence_max": 29.0, "speed_max": 6.097581, "speed_avg": 2.7866058, "cadence_avg": 10.0, "elapsed_time_total": 2624.0}}, {"start_datetime": "2018-05-12T11:32:33+00:00", "name": "DC", "is_default_name": false, "created_datetime": "2018-05-18T09:55:44+00:00", "notes": "\n from tcx via rowsandall.com", "updated_datetime": "2018-05-18T09:55:44+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893782598/", "id": "2893782598"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064203758/", "id": "2064203758"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 6173.0, "distance_total": 16813.9433088, "speed_max": 4.1599975, "speed_avg": 2.7349057, "elapsed_time_total": 6173.0, "heartrate_avg": 137.0}}, {"start_datetime": "2018-05-12T11:32:33+00:00", "name": "DC", "is_default_name": false, "created_datetime": "2018-05-18T08:42:27+00:00", "notes": "\n from tcx via rowsandall.com", "updated_datetime": "2018-05-18T08:42:27+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"self": [{"href": "/v7.1/workout/2893729495/", "id": "2893729495"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 0.0, "elapsed_time_total": 0.0, "distance_total": 0.0}}, {"start_datetime": "2018-05-11T07:02:52+00:00", "name": "Naarden 1", "is_default_name": false, "created_datetime": "2018-05-18T08:59:22+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T08:59:22+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"self": [{"href": "/v7.1/workout/2893741039/", "id": "2893741039"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": false, "is_verified": true, "aggregates": {"active_time_total": 0.0, "elapsed_time_total": 0.0, "distance_total": 0.0}}, {"start_datetime": "2018-05-10T16:55:01+00:00", "name": "Racice 2", "is_default_name": false, "created_datetime": "2018-05-18T09:01:02+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T09:01:02+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"self": [{"href": "/v7.1/workout/2893742116/", "id": "2893742116"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": false, "is_verified": true, "aggregates": {"heartrate_avg": 173.0, "distance_total": 8000.00074368}}, {"start_datetime": "2018-05-10T09:11:24+00:00", "name": "Naarden goed", "is_default_name": false, "created_datetime": "2018-05-18T09:12:28+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T09:12:29+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893750054/", "id": "2893750054"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064181300/", "id": "2064181300"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"heartrate_avg": 136.0, "distance_total": 15263.00240256}}, {"start_datetime": "2018-05-05T08:11:04+00:00", "name": "Steady (2)", "is_default_name": false, "created_datetime": "2018-05-18T09:24:01+00:00", "notes": "\n from sporttracks via rowsandall.com", "updated_datetime": "2018-05-18T09:24:02+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893757776/", "id": "2893757776"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064186616/", "id": "2064186616"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"heartrate_avg": 133.0, "cadence_min": 11.0, "distance_total": 1152.00062208, "cadence_max": 35.0, "cadence_avg": 17.0}}, {"start_datetime": "2018-05-04T06:07:04+00:00", "name": "Zip test", "is_default_name": false, "created_datetime": "2018-05-18T09:25:30+00:00", "notes": "imported through email\n from speedcoach2v2.15 via rowsandall.com", "updated_datetime": "2018-05-18T09:25:31+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893758691/", "id": "2893758691"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064187276/", "id": "2064187276"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"heartrate_avg": 173.0, "cadence_min": 14.0, "distance_total": 5996.99510784, "cadence_max": 39.0, "cadence_avg": 26.0}}, {"start_datetime": "2018-05-04T06:07:04+00:00", "name": "Zip test 2", "is_default_name": false, "created_datetime": "2018-05-18T09:26:17+00:00", "notes": "imported through email\n from speedcoach2v2.15 via rowsandall.com", "updated_datetime": "2018-05-18T09:26:17+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893759225/", "id": "2893759225"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064187669/", "id": "2064187669"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"heartrate_avg": 173.0, "cadence_min": 14.0, "distance_total": 5996.99510784, "cadence_max": 39.0, "cadence_avg": 26.0}}, {"start_datetime": "2018-04-25T22:59:01+00:00", "name": "SpeedCoach 7x150m", "is_default_name": false, "created_datetime": "2018-05-18T09:28:00+00:00", "notes": "\n from speedcoach2corrected via rowsandall.com", "updated_datetime": "2018-05-18T09:28:00+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893760308/", "id": "2893760308"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064188509/", "id": "2064188509"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"heartrate_avg": 142.0, "cadence_min": 15.0, "distance_total": 4158.99551232, "cadence_max": 29.0, "cadence_avg": 24.0}}, {"start_datetime": "2018-04-24T13:35:30+00:00", "name": "Rowed 5.0 mi on 04/24/18", "is_default_name": false, "created_datetime": "2018-05-18T09:30:49+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T09:30:50+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"self": [{"href": "/v7.1/workout/2893762366/", "id": "2893762366"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 2880.0, "distance_total": 9420.00542208, "cadence_max": 44.0, "speed_max": 4.5985217, "speed_min": 1.3475842, "speed_avg": 3.401818, "cadence_avg": 16.0, "elapsed_time_total": 2880.0, "heartrate_avg": 145.0}}, {"start_datetime": "2018-04-23T20:42:00+00:00", "name": "Racice", "is_default_name": false, "created_datetime": "2018-05-18T09:27:18+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T09:27:18+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893759843/", "id": "2893759843"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064188131/", "id": "2064188131"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"heartrate_avg": 173.0, "cadence_min": 8.0, "distance_total": 8000.00074368, "cadence_max": 30.0, "cadence_avg": 25.0}}, {"start_datetime": "2018-04-07T07:41:02+00:00", "name": "2x3km fail", "is_default_name": false, "created_datetime": "2018-05-18T09:34:01+00:00", "notes": "\n from csv via rowsandall.com", "updated_datetime": "2018-05-18T09:34:01+00:00", "reference_key": null, "start_locale_timezone": "Europe/Bratislava", "source": "", "source_manufacturer": null, "_links": {"user": [{"href": "/v7.1/user/109227799/", "id": "109227799"}], "self": [{"href": "/v7.1/workout/2893764754/", "id": "2893764754"}], "privacy": [{"href": "/v7.1/privacy_option/1/", "id": "1"}], "route": [{"href": "/v7.1/route/2064191680/", "id": "2064191680"}], "activity_type": [{"href": "/v7.1/activity_type/128/", "id": "128"}]}, "has_time_series": true, "is_verified": true, "aggregates": {"active_time_total": 3968.0, "distance_total": 10567.9987776, "cadence_max": 63.0, "speed_max": 4.0374823, "speed_min": 0.22480257, "cadence_min": 8.0, "speed_avg": 3.053185, "cadence_avg": 20.0, "elapsed_time_total": 3968.0, "heartrate_avg": 155.0}}]}, "_links": {"self": [{"href": "/v7.1/workout/?limit=20&order_by=-start_datetime&user=109227799&offset=0"}], "documentation": [{"href": "https://developer.underarmour.com/docs/v71_Workout"}], "next": [{"href": "/v7.1/workout/?limit=20&order_by=-start_datetime&user=109227799&offset=20"}]}, "total_count": 45} \ No newline at end of file diff --git a/rowers/tests.py b/rowers/tests.py index 4920d7fa..a1f35397 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -84,6 +84,7 @@ def mocked_requests(*args, **kwargs): sporttracksworkoutlist = json.load(open('rowers/testdata/sporttracksworkouts.txt')) rkworkoutlistjson = json.load(open('rowers/testdata/rkworkoutslist.txt','r')) + uaworkoutlistjson = json.load(open('rowers/testdata/uaworkoutlist.txt','r')) stravasummaryjson = json.load(open('rowers/testdata/stravaworkoutsummary.txt','r')) @@ -94,6 +95,10 @@ def mocked_requests(*args, **kwargs): stravahrjson = json.load(open('rowers/testdata/stravahrtestdata.txt','r')) stravaspmjson = json.load(open('rowers/testdata/stravaspmtestdata.txt','r')) + uapostworkoutjson = json.load(open('rowers/testdata/uapostworkoutresponse.txt','r')) + + tpuploadresponse = json.load(open('rowers/testdata/tpuploadresponse.txt','r')) + stravastreamjson = { 'time':stravatimejson, 'velocity_smooth':stravavelojson, @@ -107,6 +112,9 @@ def mocked_requests(*args, **kwargs): rkstrokesjson = json.load(open('rowers/testdata/rkstrokes.txt','r')) + uastrokesjson = json.load(open('rowers/testdata/uastrokes.txt','r')) + uauserjson = json.load(open('rowers/testdata/uauser.txt','r')) + class MockResponse: def __init__(self, json_data, status_code): self.json_data = json_data @@ -143,6 +151,8 @@ def mocked_requests(*args, **kwargs): stravatester = re.compile('.*?strava\.com') sttester = re.compile('.*?sporttracks\.mobi') rktester = re.compile('.*?runkeeper\.com') + uatester = re.compile('.*?mapmyfitness\.com') + tptester = re.compile('.*?trainingpeaks\.com') c2importregex = '.*?concept2.com\/api\/users\/me\/results\/\d+' c2importtester = re.compile(c2importregex) @@ -180,6 +190,64 @@ def mocked_requests(*args, **kwargs): rkusertester = re.compile(rkuserregex) rkstrokesregex = '.*?api\.runkeeper\.com\/fitnessActivities/\d+$' rkstrokestester = re.compile(rkstrokesregex) + + uaapiregex = '.*?api\.ua\.com' + uaapitester = re.compile(uaapiregex) + + uauploadregex = '.*?api\.ua\.com\/v7.1\/workout\/$' + uauploadtester = re.compile(uauploadregex) + + uastrokesregex = '.*?api\.ua\.com\/v7.1\/workout\/\d+' + uastrokestester = re.compile(uastrokesregex) + + ualistregex = '.*?api\.ua\.com\/v7.1\/workout\/\?user' + ualisttester = re.compile(ualistregex) + + uauserregex = '.*?api\.ua\.com\/v7.1\/user\/self\/' + uausertester = re.compile(uauserregex) + + tpuploadregex = '.*?trainingpeaks\.com\/v1\/file' + tpuploadtester = re.compile(tpuploadregex) + + if tptester.match(args[0]): + if 'token' in args[0]: + json_data = { + 'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq', + 'expires_in': 604800, + 'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR' + } + return MockResponse(json_data,200) + elif tpuploadtester.match(args[0]): + return MockResponse(tpuploadresponse,200) + + if uaapitester.match(args[0]): + if 'access_token' in args[0]: + json_data = { + 'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq', + 'expires_in': 604800, + 'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR' + } + return MockResponse(json_data,200) + elif uauploadtester.match(args[0]): + if 'data' in kwargs: + return MockResponse(uapostworkoutjson,200) + elif uastrokestester.match(args[0]): + return MockResponse(uastrokesjson,200) + elif ualisttester.match(args[0]): + return MockResponse(uaworkoutlistjson,200) + elif uausertester.match(args[0]): + return MockResponse(uauserjson,200) + + + if uatester.match(args[0]): + if 'access_token' in args[0]: + json_data = { + 'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq', + 'expires_in': 604800, + 'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR' + } + return MockResponse(json_data,200) + if rktester.match(args[0]): if 'token' in args[0]: @@ -189,7 +257,7 @@ def mocked_requests(*args, **kwargs): 'refresh_token': 'jHJhFzCfOOKB8oyiayubhLAlxaMkG3ruC1E8YxaR' } return MockResponse(json_data,200) - if rkuploadtester.match(args[0]): + elif rkuploadtester.match(args[0]): if 'data' in kwargs: # post header_data = { @@ -199,7 +267,7 @@ def mocked_requests(*args, **kwargs): else: json_data = rkworkoutlistjson return MockResponse(json_data,200) - if rkusertester.match(args[0]): + elif rkusertester.match(args[0]): json_data = { "userID": 1234567890, "profile": "/profile", @@ -216,7 +284,7 @@ def mocked_requests(*args, **kwargs): "team": "/team" } return MockResponse(json_data, 200) - if rkstrokestester.match(args[0]): + elif rkstrokestester.match(args[0]): return MockResponse(rkstrokesjson,200) if sttester.match(args[0]): @@ -661,6 +729,192 @@ class RunKeeperObjects(DjangoTestCase): self.assertEqual(response.status_code, 200) + + +class UAObjects(DjangoTestCase): + def setUp(self): + self.c = Client() + self.u = User.objects.create_user('john', + 'sander@ds.ds', + 'koeinsloot') + + self.u.first_name = 'John' + self.u.last_name = 'Sander' + self.u.save() + self.r = Rower.objects.create(user=self.u,gdproptin=True, + gdproptindate=timezone.now() + ) + + + self.r.underarmourtoken = '12' + self.r.underarmourrefreshtoken = '12' + self.r.underarmourtokenexpirydate = datetime.datetime.now()+datetime.timedelta(days=1) + self.r.save() + + self.c.login(username='john',password='koeinsloot') + + self.nu = datetime.datetime.now() + + filename = 'rowers/testdata/testdata.csv' + + rr = rrower(hrmax=self.r.max,hrut2=self.r.ut2, + hrut1=self.r.ut1,hrat=self.r.at, + hrtr=self.r.tr,hran=self.r.an,ftp=self.r.ftp) + row = rdata(filename,rower=rr) + totaldist = row.df['cum_dist'].max() + totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min() + totaltime = totaltime+row.df.ix[0,' ElapsedTime (sec)'] + + + hours = int(totaltime/3600.) + minutes = int((totaltime - 3600.*hours)/60.) + seconds = int(totaltime - 3600.*hours - 60.*minutes) + tenths = int(10*(totaltime - 3600.*hours - 60.*minutes - seconds)) + + duration = "%s:%s:%s.%s" % (hours,minutes,seconds,tenths) + + + workoutdate = row.rowdatetime.strftime('%Y-%m-%d') + workoutstarttime = row.rowdatetime.strftime('%H:%M:%S') + + self.w = Workout.objects.create( + name='testworkout',workouttype='On-water', + user=self.r,date=self.nu.strftime('%Y-%m-%d'), + starttime=workoutstarttime, + startdatetime=row.rowdatetime, + duration=duration,distance=totaldist, + csvfilename=filename + ) + + @patch('rowers.imports.requests.post', side_effect=mocked_requests) + def test_underarmour_callback(self, mock_post): + response = self.c.get('/underarmour_callback?code=dsdoij232s',follow=True) + + + self.assertEqual(response.status_code, 200) + + + @patch('rowers.underarmourstuff.requests.post', side_effect=mocked_requests) + def test_underarmour_token_refresh(self, mock_post): + response = self.c.get('/rowers/me/underarmourrefresh/',follow=True) + + self.assertEqual(response.status_code, 200) + + + @patch('rowers.underarmourstuff.requests.post', side_effect=mocked_requests) + @patch('rowers.underarmourstuff.requests.get', side_effect=mocked_requests) + def test_underarmour_upload(self, mock_get, mock_post): + response = self.c.get('/rowers/workout/1/underarmouruploadw/') + + self.assertRedirects(response, + expected_url = '/rowers/workout/1/export', + status_code=302,target_status_code=200) + + self.assertEqual(response.url, '/rowers/workout/1/export') + self.assertEqual(response.status_code, 302) + + @patch('rowers.underarmourstuff.requests.get', side_effect=mocked_requests) + def test_underarmour_list(self, mock_get): + response = self.c.get('/rowers/workout/underarmourimport',follow=True) + + self.assertEqual(response.status_code,200) + + @patch('rowers.imports.requests.get', side_effect=mocked_requests) + def test_underarmour_import(self, mock_get): + + response = self.c.get('/rowers/workout/underarmourimport/12/',follow=True) + + self.assertRedirects(response, + expected_url='/rowers/workout/2/edit', + status_code=302,target_status_code=200) + + self.assertEqual(response.status_code, 200) + + +class TPObjects(DjangoTestCase): + def setUp(self): + self.c = Client() + self.u = User.objects.create_user('john', + 'sander@ds.ds', + 'koeinsloot') + + self.u.first_name = 'John' + self.u.last_name = 'Sander' + self.u.save() + self.r = Rower.objects.create(user=self.u,gdproptin=True, + gdproptindate=timezone.now() + ) + + + self.r.tptoken = '12' + self.r.tprefreshtoken = '12' + self.r.tptokenexpirydate = datetime.datetime.now()+datetime.timedelta(days=1) + self.r.save() + + self.c.login(username='john',password='koeinsloot') + + self.nu = datetime.datetime.now() + + filename = 'rowers/testdata/testdata.csv' + + rr = rrower(hrmax=self.r.max,hrut2=self.r.ut2, + hrut1=self.r.ut1,hrat=self.r.at, + hrtr=self.r.tr,hran=self.r.an,ftp=self.r.ftp) + row = rdata(filename,rower=rr) + totaldist = row.df['cum_dist'].max() + totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min() + totaltime = totaltime+row.df.ix[0,' ElapsedTime (sec)'] + + + hours = int(totaltime/3600.) + minutes = int((totaltime - 3600.*hours)/60.) + seconds = int(totaltime - 3600.*hours - 60.*minutes) + tenths = int(10*(totaltime - 3600.*hours - 60.*minutes - seconds)) + + duration = "%s:%s:%s.%s" % (hours,minutes,seconds,tenths) + + + workoutdate = row.rowdatetime.strftime('%Y-%m-%d') + workoutstarttime = row.rowdatetime.strftime('%H:%M:%S') + + self.w = Workout.objects.create( + name='testworkout',workouttype='On-water', + user=self.r,date=self.nu.strftime('%Y-%m-%d'), + starttime=workoutstarttime, + startdatetime=row.rowdatetime, + duration=duration,distance=totaldist, + csvfilename=filename + ) + + @patch('rowers.imports.requests.post', side_effect=mocked_requests) + def test_tp_callback(self, mock_post): + response = self.c.get('/tp_callback?code=dsdoij232s',follow=True) + + + self.assertEqual(response.status_code, 200) + + + @patch('rowers.tpstuff.requests.post', side_effect=mocked_requests) + def test_tp_token_refresh(self, mock_post): + response = self.c.get('/rowers/me/tprefresh/',follow=True) + + self.assertEqual(response.status_code, 200) + + + @patch('rowers.tpstuff.requests.post', side_effect=mocked_requests) + @patch('rowers.tpstuff.requests.get', side_effect=mocked_requests) + def test_tp_upload(self, mock_get, mock_post): + response = self.c.get('/rowers/workout/1/tpuploadw/') + + self.assertRedirects(response, + expected_url = '/rowers/workout/1/export', + status_code=302,target_status_code=200) + + self.assertEqual(response.url, '/rowers/workout/1/export') + self.assertEqual(response.status_code, 302) + + + class TestErrorPages(TestCase): def test_error_handlers(self): diff --git a/rowers/tpstuff.py b/rowers/tpstuff.py index 9a783d9a..d19e5c64 100644 --- a/rowers/tpstuff.py +++ b/rowers/tpstuff.py @@ -229,7 +229,6 @@ def uploadactivity(access_token,filename,description='', data = json.dumps(data), headers=headers) - print resp.status_code if resp.status_code != 200: if settings.DEBUG: print resp.status_code @@ -237,24 +236,11 @@ def uploadactivity(access_token,filename,description='', print "" print headers print "" - with open("media/tperrors.log","a") as errorlog: - errorlog.write(str(resp.status_code)) - errorlog.write("\r\n") - timestr = strftime("%Y%m%d-%H%M%S") - errorlog.write(timestr+"\r\n") - errorlog.write("\r\n") - errorlog.write(str(resp.reason)) - errorlog.write("\r\n") - try: - errorlog.write(str(resp.json())) - except: - pass - errorlog.write("\r\n") return 0,resp.reason,resp.status_code,headers else: return resp.json()[0]["Id"],"ok",200,"" - return 0 + return 0,0,0,0 def workout_tp_upload(user,w): diff --git a/rowers/underarmourstuff.py b/rowers/underarmourstuff.py index bd4bd4b8..20a8365b 100644 --- a/rowers/underarmourstuff.py +++ b/rowers/underarmourstuff.py @@ -52,6 +52,7 @@ def get_underarmour_workout_list(user): 'Content-Type': 'application/json'} url = "https://api.ua.com/v7.1/workout/?user="+str(get_userid(r.underarmourtoken))+"&order_by=-start_datetime" + print url s = requests.get(url,headers=headers) @@ -221,7 +222,7 @@ def get_idfromuri(user,links): return id,typename def getidfromresponse(response): - t = json.loads(response.text) + t = response.json() links = t["_links"]