fix c2 import
This commit is contained in:
@@ -2125,6 +2125,7 @@ def new_workout_from_file(r, f2,
|
|||||||
uploadoptions={'boattype': '1x', 'workouttype': 'rower'}):
|
uploadoptions={'boattype': '1x', 'workouttype': 'rower'}):
|
||||||
message = ""
|
message = ""
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fileformat = get_file_type(f2)
|
fileformat = get_file_type(f2)
|
||||||
except (IOError, UnicodeDecodeError): # pragma: no cover
|
except (IOError, UnicodeDecodeError): # pragma: no cover
|
||||||
|
|||||||
@@ -3158,7 +3158,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
title = ''
|
title = ''
|
||||||
|
|
||||||
# Create CSV file name and save data to CSV file
|
# Create CSV file name and save data to CSV file
|
||||||
csvfilename = 'media/{code}_{c2id}.csv'.format(
|
csvfilename = 'media/{code}_{c2id}.csv.gz'.format(
|
||||||
code=uuid4().hex[:16], c2id=c2id)
|
code=uuid4().hex[:16], c2id=c2id)
|
||||||
|
|
||||||
startdatetime, starttime, workoutdate, duration, starttimeunix, timezone = utils.get_startdatetime_from_c2data(
|
startdatetime, starttime, workoutdate, duration, starttimeunix, timezone = utils.get_startdatetime_from_c2data(
|
||||||
@@ -3167,7 +3167,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
s = 'Time zone {timezone}, startdatetime {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('c2_import.log', s)
|
||||||
|
|
||||||
authorizationstring = str('Bearer ' + c2token)
|
authorizationstring = str('Bearer ' + c2token)
|
||||||
headers = {'Authorization': authorizationstring,
|
headers = {'Authorization': authorizationstring,
|
||||||
@@ -3180,9 +3180,9 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
if s.status_code != 200: # pragma: no cover
|
if s.status_code != 200: # pragma: no cover
|
||||||
dologging('debuglog.log', 'No Stroke Data. Status Code {code}'.format(
|
dologging('c2_import.log', 'No Stroke Data. Status Code {code}'.format(
|
||||||
code=s.status_code))
|
code=s.status_code))
|
||||||
dologging('debuglog.log', s.text)
|
dologging('c2_import.log', s.text)
|
||||||
has_strokedata = False
|
has_strokedata = False
|
||||||
|
|
||||||
if not has_strokedata: # pragma: no cover
|
if not has_strokedata: # pragma: no cover
|
||||||
@@ -3192,7 +3192,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
try:
|
try:
|
||||||
strokedata = pd.DataFrame.from_dict(s.json()['data'])
|
strokedata = pd.DataFrame.from_dict(s.json()['data'])
|
||||||
except AttributeError: # pragma: no cover
|
except AttributeError: # pragma: no cover
|
||||||
dologging('debuglog.log', 'No stroke data in stroke data')
|
dologging('c2_import.log', 'No stroke data in stroke data')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -3200,7 +3200,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
cum_time = res[0]
|
cum_time = res[0]
|
||||||
lapidx = res[1]
|
lapidx = res[1]
|
||||||
except KeyError: # pragma: no cover
|
except KeyError: # pragma: no cover
|
||||||
dologging('debuglog.log', 'No time values in stroke data')
|
dologging('c2_import.log', 'No time values in stroke data')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
unixtime = cum_time+starttimeunix
|
unixtime = cum_time+starttimeunix
|
||||||
@@ -3242,7 +3242,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
if workouttype == 'bike': # pragma: no cover
|
if workouttype == 'bike': # pragma: no cover
|
||||||
velo = 1000./pace
|
velo = 1000./pace
|
||||||
|
|
||||||
dologging('debuglog.log', 'Unix Time Stamp {s}'.format(s=unixtime[0]))
|
dologging('c2_import.log', 'Unix Time Stamp {s}'.format(s=unixtime[0]))
|
||||||
# dologging('debuglog.log',json.dumps(s.json()))
|
# dologging('debuglog.log',json.dumps(s.json()))
|
||||||
|
|
||||||
df = pd.DataFrame({'TimeStamp (sec)': unixtime,
|
df = pd.DataFrame({'TimeStamp (sec)': unixtime,
|
||||||
@@ -3270,6 +3270,7 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
|
|
||||||
_ = df.to_csv(csvfilename, index_label='index', compression='gzip')
|
_ = df.to_csv(csvfilename, index_label='index', compression='gzip')
|
||||||
|
|
||||||
|
|
||||||
uploadoptions = {
|
uploadoptions = {
|
||||||
'secret': UPLOAD_SERVICE_SECRET,
|
'secret': UPLOAD_SERVICE_SECRET,
|
||||||
'user': userid,
|
'user': userid,
|
||||||
@@ -3289,6 +3290,9 @@ def handle_c2_async_workout(alldata, userid, c2token, c2id, delaysec, defaulttim
|
|||||||
response = session.post(UPLOAD_SERVICE_URL, json=uploadoptions)
|
response = session.post(UPLOAD_SERVICE_URL, json=uploadoptions)
|
||||||
|
|
||||||
if response.status_code != 200: # pragma: no cover
|
if response.status_code != 200: # pragma: no cover
|
||||||
|
dologging('c2_import.log',
|
||||||
|
'Upload API returned status code {code}'.format(
|
||||||
|
code=response.status_code))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
workoutid = response.json()['id']
|
workoutid = response.json()['id']
|
||||||
|
|||||||
@@ -4593,6 +4593,7 @@ def workout_upload_api(request):
|
|||||||
message = {'status': 'false', 'message': 'invalid credentials'}
|
message = {'status': 'false', 'message': 'invalid credentials'}
|
||||||
return JSONResponse(status=403, data=message)
|
return JSONResponse(status=403, data=message)
|
||||||
|
|
||||||
|
|
||||||
form = DocumentsForm(post_data)
|
form = DocumentsForm(post_data)
|
||||||
optionsform = TeamUploadOptionsForm(post_data)
|
optionsform = TeamUploadOptionsForm(post_data)
|
||||||
rowerform = TeamInviteForm(post_data)
|
rowerform = TeamInviteForm(post_data)
|
||||||
@@ -4613,6 +4614,7 @@ def workout_upload_api(request):
|
|||||||
message = {'status': 'false', 'message': 'could not find file'}
|
message = {'status': 'false', 'message': 'could not find file'}
|
||||||
return JSONResponse(status=400, data=message)
|
return JSONResponse(status=400, data=message)
|
||||||
|
|
||||||
|
|
||||||
# sync related IDs
|
# sync related IDs
|
||||||
c2id = post_data.get('c2id', '')
|
c2id = post_data.get('c2id', '')
|
||||||
|
|
||||||
@@ -4635,6 +4637,7 @@ def workout_upload_api(request):
|
|||||||
|
|
||||||
dologging('debuglog.log', s)
|
dologging('debuglog.log', s)
|
||||||
|
|
||||||
|
|
||||||
r = None
|
r = None
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
t = form.cleaned_data['title']
|
t = form.cleaned_data['title']
|
||||||
@@ -4768,6 +4771,7 @@ def workout_upload_api(request):
|
|||||||
message = form.errors
|
message = form.errors
|
||||||
return JSONResponse(status=400, data=message)
|
return JSONResponse(status=400, data=message)
|
||||||
|
|
||||||
|
|
||||||
message = {'status': 'true', 'id': w.id}
|
message = {'status': 'true', 'id': w.id}
|
||||||
statuscode = 200
|
statuscode = 200
|
||||||
if fstr:
|
if fstr:
|
||||||
|
|||||||
Reference in New Issue
Block a user