Merge branch 'release/v16.3.2'
This commit is contained in:
@@ -2804,7 +2804,10 @@ def handle_update_wps(rid,types,ids,mode,debug=False,**kwargs):
|
|||||||
mask = df['driveenergy'] > 100
|
mask = df['driveenergy'] > 100
|
||||||
except (KeyError, TypeError): # pragma: no cover
|
except (KeyError, TypeError): # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
|
try:
|
||||||
wps_median = int(df.loc[mask,'driveenergy'].median())
|
wps_median = int(df.loc[mask,'driveenergy'].median())
|
||||||
|
except ValueError:
|
||||||
|
return 0
|
||||||
|
|
||||||
if mode == 'water':
|
if mode == 'water':
|
||||||
query = "UPDATE `rowers_rower` SET `median_wps` = '%s' WHERE `id` = '%s'" % (wps_median,rid)
|
query = "UPDATE `rowers_rower` SET `median_wps` = '%s' WHERE `id` = '%s'" % (wps_median,rid)
|
||||||
@@ -2854,7 +2857,7 @@ def handle_rp3_async_workout(userid,rp3token,rp3id,startdatetime,max_attempts,de
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
workout_download_details = pd.json_normalize(response.json()['data']['download'])
|
workout_download_details = pd.json_normalize(response.json()['data']['download'])
|
||||||
except JSONDecodeError: # pragma: no cover
|
except: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if workout_download_details.iat[0,1] == 'ready':
|
if workout_download_details.iat[0,1] == 'ready':
|
||||||
@@ -3018,6 +3021,57 @@ def handle_c2_getworkout(userid,c2token,c2id,defaulttimezone,debug=False,**kwarg
|
|||||||
|
|
||||||
return handle_c2_async_workout(alldata,userid,c2token,c2id,0,defaulttimezone)
|
return handle_c2_async_workout(alldata,userid,c2token,c2id,0,defaulttimezone)
|
||||||
|
|
||||||
|
def df_from_summary(data):
|
||||||
|
distance = data['distance']
|
||||||
|
c2id = data['id']
|
||||||
|
workouttype = data['type']
|
||||||
|
verified = data['verified']
|
||||||
|
weightclass = data['weight_class']
|
||||||
|
try:
|
||||||
|
title = data['name']
|
||||||
|
except KeyError:
|
||||||
|
title = ""
|
||||||
|
try:
|
||||||
|
t = data['comments'].split('\n', 1)[0]
|
||||||
|
title += t[:40]
|
||||||
|
except: # pragma: no cover
|
||||||
|
title = ''
|
||||||
|
|
||||||
|
weightcategory = 'hwt'
|
||||||
|
if weightclass == "L":
|
||||||
|
weightcategory = 'lwt'
|
||||||
|
|
||||||
|
startdatetime,starttime,workoutdate,duration,starttimeunix,timezone = utils.get_startdatetime_from_c2data(data)
|
||||||
|
|
||||||
|
splits = data['workout']['splits']
|
||||||
|
time = starttimeunix
|
||||||
|
elapsed_distance = 0
|
||||||
|
times = [0]
|
||||||
|
distances = [0]
|
||||||
|
spms = [splits[0]['stroke_rate']]
|
||||||
|
hrs = [splits[0]['heart_rate']['average']]
|
||||||
|
|
||||||
|
for split in splits:
|
||||||
|
time += split['time']/10.
|
||||||
|
elapsed_distance += split['distance']
|
||||||
|
times.append(time)
|
||||||
|
distances.append(elapsed_distance)
|
||||||
|
spms.append(split['stroke_rate'])
|
||||||
|
hrs.append(split['heart_rate']['average'])
|
||||||
|
|
||||||
|
df = pd.DataFrame({
|
||||||
|
'TimeStamp (sec)': times,
|
||||||
|
' Horizontal (meters)': distances,
|
||||||
|
' HRCur (bpm)': hrs,
|
||||||
|
' Cadence (stokes/min)': spms,
|
||||||
|
})
|
||||||
|
|
||||||
|
df[' ElapsedTime (sec)'] = df['TimeStamp (sec)']-starttimeunix
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone,debug=False,**kwargs):
|
def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone,debug=False,**kwargs):
|
||||||
time.sleep(delaysec)
|
time.sleep(delaysec)
|
||||||
@@ -3034,6 +3088,13 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
|
|
||||||
weightclass = data['weight_class']
|
weightclass = data['weight_class']
|
||||||
|
|
||||||
|
try:
|
||||||
|
has_strokedata = data['stroke_data']
|
||||||
|
except KeyError:
|
||||||
|
has_strokedata = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
s = 'User {userid}, C2 ID {c2id}'.format(userid=userid,c2id=c2id)
|
s = 'User {userid}, C2 ID {c2id}'.format(userid=userid,c2id=c2id)
|
||||||
dologging('debuglog.log',s)
|
dologging('debuglog.log',s)
|
||||||
dologging('debuglog.log',json.dumps(data))
|
dologging('debuglog.log',json.dumps(data))
|
||||||
@@ -3058,7 +3119,7 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
startdatetime,starttime,workoutdate,duration,starttimeunix,timezone = utils.get_startdatetime_from_c2data(data)
|
startdatetime,starttime,workoutdate,duration,starttimeunix,timezone = utils.get_startdatetime_from_c2data(data)
|
||||||
|
|
||||||
|
|
||||||
s = 'Time zone {timezone}, stardatetime {startdatetime}, duration {duration}'.format(
|
s = 'Time zone {timezone}, startdatetime {startdatetime}, duration {duration}'.format(
|
||||||
timezone=timezone,startdatetime=startdatetime,
|
timezone=timezone,startdatetime=startdatetime,
|
||||||
duration=duration)
|
duration=duration)
|
||||||
dologging('debuglog.log',s)
|
dologging('debuglog.log',s)
|
||||||
@@ -3081,7 +3142,14 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
if s.status_code != 200: # pragma: no cover
|
if s.status_code != 200: # pragma: no cover
|
||||||
return 0
|
dologging('debuglog.log','No Stroke Data. Status Code {code}'.format(code=s.status_code))
|
||||||
|
dologging('debuglog.log',s.text)
|
||||||
|
has_strokedata = False
|
||||||
|
|
||||||
|
if not has_strokedata:
|
||||||
|
df = df_from_summary(data)
|
||||||
|
else:
|
||||||
|
dologging('debuglog.log',json.dumps(s.json()))
|
||||||
|
|
||||||
strokedata = pd.DataFrame.from_dict(s.json()['data'])
|
strokedata = pd.DataFrame.from_dict(s.json()['data'])
|
||||||
|
|
||||||
@@ -3157,7 +3225,8 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
|
|||||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||||
|
|
||||||
res = df.to_csv(csvfilename,index_label='index',
|
res = df.to_csv(csvfilename,index_label='index',
|
||||||
compression='gzip')
|
compression='gzip'
|
||||||
|
)
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret':UPLOAD_SERVICE_SECRET,
|
'secret':UPLOAD_SERVICE_SECRET,
|
||||||
|
|||||||
@@ -348,6 +348,27 @@ class C2Objects(DjangoTestCase):
|
|||||||
self.assertEqual(got, want)
|
self.assertEqual(got, want)
|
||||||
self.assertEqual(workoutdate,'2021-05-23')
|
self.assertEqual(workoutdate,'2021-05-23')
|
||||||
|
|
||||||
|
def test_c2_import_54583351(self):
|
||||||
|
with open('rowers/tests/testdata/c2_54583351.json','r') as infile:
|
||||||
|
data = json.load(infile)
|
||||||
|
(
|
||||||
|
startdatetime,
|
||||||
|
starttime,
|
||||||
|
workoutdate,
|
||||||
|
duration,
|
||||||
|
starttimeunix,
|
||||||
|
timezone
|
||||||
|
) = utils.get_startdatetime_from_c2data(data)
|
||||||
|
|
||||||
|
|
||||||
|
self.assertEqual(str(timezone),'UTC')
|
||||||
|
|
||||||
|
got = arrow.get(startdatetime).isoformat()
|
||||||
|
want = arrow.get('2021-05-26 08:59:34.000000+00:00').isoformat()
|
||||||
|
|
||||||
|
self.assertEqual(got, want)
|
||||||
|
self.assertEqual(workoutdate,'2021-05-26')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
@patch('rowers.c2stuff.requests.get', side_effect=mocked_requests)
|
||||||
|
|||||||
Reference in New Issue
Block a user