Private
Public Access
1
0

api v3 latency related improvements

This commit is contained in:
Sander Roosendaal
2023-01-21 10:00:26 +01:00
parent 7ccebc7a98
commit b02a2075c6
5 changed files with 87 additions and 32 deletions

View File

@@ -1047,6 +1047,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
forceunit='lbs', forceunit='lbs',
consistencychecks=False, consistencychecks=False,
startdatetime='', startdatetime='',
workoutid='',
impeller=False): impeller=False):
message = None message = None
@@ -1089,7 +1090,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
return new_workout_from_df(r, newdf, return new_workout_from_df(r, newdf,
title=title, boattype=boattype, title=title, boattype=boattype,
workouttype=workouttype, workouttype=workouttype,
workoutsource=workoutsource, startdatetime=startdatetime) workoutsource=workoutsource, startdatetime=startdatetime,
workoutid=workoutid)
try: try:
checks = row.check_consistency() checks = row.check_consistency()
allchecks = 1 allchecks = 1
@@ -1233,26 +1235,59 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
timezone_str = str(workoutstartdatetime.tzinfo) timezone_str = str(workoutstartdatetime.tzinfo)
w = Workout(user=r, name=title, date=workoutdate, if workoutid:
workouttype=workouttype, try:
boattype=boattype, w = Workout.objects.get(id=workoutid)
dragfactor=dragfactor, w.name = title
duration=duration, distance=totaldist, w.date = workoutdate
weightcategory=weightcategory, w.workouttype = workouttype
adaptiveclass=adaptiveclass, w.boattype = boattype
starttime=workoutstarttime, w.dragfactor = dragfactor
duplicate=duplicate, w.duration = duration
workoutsource=workoutsource, w.distance = totaldist
rankingpiece=rankingpiece, w.weightcategory = weightcategory
forceunit=forceunit, w.adaptiveclass = adaptiveclass
rpe=rpe, w.starttime = workoutstarttime
csvfilename=f2, notes=notes, summary=summary, w.duplicate = duplicate
maxhr=maxhr, averagehr=averagehr, w.workoutsource = workoutsource
startdatetime=workoutstartdatetime, w.rankingpiece = rankingpiece
inboard=inboard, oarlength=oarlength, w.forceunit = forceunit
timezone=timezone_str, w.rpe = rpe
privacy=privacy, w.csvfilename = f2
impeller=impeller) w.notes = notes
w.summary = summary
w.maxhr = maxhr
w.averagehr = averagehr
w.startdatetime = workoutstartdatetime
w.inboard = inboard
w.oarlength = oarlength
w.timezone = timezone_str
w.privacy = privacy
w.impeller = impeller
except Workout.DoesNotExist:
workoutid = ''
if not workoutid:
w = Workout(user=r, name=title, date=workoutdate,
workouttype=workouttype,
boattype=boattype,
dragfactor=dragfactor,
duration=duration, distance=totaldist,
weightcategory=weightcategory,
adaptiveclass=adaptiveclass,
starttime=workoutstarttime,
duplicate=duplicate,
workoutsource=workoutsource,
rankingpiece=rankingpiece,
forceunit=forceunit,
rpe=rpe,
csvfilename=f2, notes=notes, summary=summary,
maxhr=maxhr, averagehr=averagehr,
startdatetime=workoutstartdatetime,
inboard=inboard, oarlength=oarlength,
timezone=timezone_str,
privacy=privacy,
impeller=impeller)
try: try:
w.save() w.save()
except ValidationError: # pragma: no cover except ValidationError: # pragma: no cover
@@ -1292,6 +1327,7 @@ def new_workout_from_file(r, f2,
makeprivate=False, makeprivate=False,
startdatetime='', startdatetime='',
notes='', notes='',
workoutid='',
oarlockfirmware='', oarlockfirmware='',
inboard=None, inboard=None,
oarlength=None, oarlength=None,
@@ -1463,6 +1499,7 @@ def new_workout_from_file(r, f2,
title=title, title=title,
forceunit='N', forceunit='N',
impeller=impeller, impeller=impeller,
workoutid=workoutid,
) )
return (id, message, f2) return (id, message, f2)
@@ -1474,6 +1511,7 @@ def new_workout_from_df(r, df,
boattype='1x', boattype='1x',
workouttype='rower', workouttype='rower',
parent=None, parent=None,
workoutid='',
startdatetime='', startdatetime='',
setprivate=False, setprivate=False,
forceunit='lbs', forceunit='lbs',
@@ -1541,6 +1579,7 @@ def new_workout_from_df(r, df,
inboard=inboard, inboard=inboard,
makeprivate=makeprivate, makeprivate=makeprivate,
dosmooth=False, dosmooth=False,
workoutid=workoutid,
rpe=rpe, rpe=rpe,
consistencychecks=False) consistencychecks=False)

View File

@@ -315,6 +315,20 @@ def summaryfromsplitdata(splitdata, data, filename, sep='|', workouttype='rower'
return sums, sa, results return sums, sa, results
@app.task
def handle_post_workout_api(uploadoptions, debug=False, **kwargs):
session = requests.session()
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
session.headers.update(newHeaders)
response = session.post(UPLOAD_SERVICE_URL, json=uploadoptions)
if response.status_code != 200:
return 0
return 1
@app.task @app.task
def handle_remove_workouts_team(ws, t, debug=False, **kwargs): def handle_remove_workouts_team(ws, t, debug=False, **kwargs):
for w in ws: for w in ws:

View File

@@ -297,6 +297,10 @@ def strokedatajson_v3(request):
csvfilename = 'media/{code}.csv.gz'.format(code=uuid4().hex[:16]) csvfilename = 'media/{code}.csv.gz'.format(code=uuid4().hex[:16])
_ = data.to_csv(csvfilename, index_label='index', compression='gzip') _ = data.to_csv(csvfilename, index_label='index', compression='gzip')
duration = datetime.time(0,0,1)
w = Workout(user=request.user.rower,date=timezone.now().date(),duration=duration)
w.save()
uploadoptions = { uploadoptions = {
'secret': UPLOAD_SERVICE_SECRET, 'secret': UPLOAD_SERVICE_SECRET,
'user': request.user.id, 'user': request.user.id,
@@ -309,20 +313,15 @@ def strokedatajson_v3(request):
'rpe': rpe, 'rpe': rpe,
'notes': notes, 'notes': notes,
'timezone': timeZone, 'timezone': timeZone,
'id': w.id,
} }
session = requests.session()
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
session.headers.update(newHeaders)
response = session.post(UPLOAD_SERVICE_URL, json=uploadoptions)
if response.status_code != 200: _ = myqueue(queuehigh,
return HttpResponse(response.text, response.status_code) handle_post_workout_api,
uploadoptions)
try: workoutid = w.id
workoutid = response.json()['id']
except KeyError:
workoutid = 1
return JsonResponse( return JsonResponse(
{"workout public id": encoder.encode_hex(workoutid), {"workout public id": encoder.encode_hex(workoutid),

View File

@@ -242,6 +242,7 @@ from rowers.rows import handle_uploaded_file, handle_uploaded_image
from rowers.plannedsessions import * from rowers.plannedsessions import *
from rowers.tasks import handle_makeplot, handle_otwsetpower, handle_sendemailtcx, handle_sendemailcsv from rowers.tasks import handle_makeplot, handle_otwsetpower, handle_sendemailtcx, handle_sendemailcsv
from rowers.tasks import ( from rowers.tasks import (
handle_post_workout_api,
handle_sendemail_newftp, handle_sendemail_newftp,
instroke_static, instroke_static,
fetch_rojabo_session, fetch_rojabo_session,

View File

@@ -5210,6 +5210,7 @@ def workout_upload_api(request):
# sync related IDs # sync related IDs
c2id = post_data.get('c2id', '') c2id = post_data.get('c2id', '')
workoutid = post_data.get('id','')
startdatetime = post_data.get('startdatetime', '') startdatetime = post_data.get('startdatetime', '')
oarlockfirmware = post_data.get('oarlockfirmware', None) oarlockfirmware = post_data.get('oarlockfirmware', None)
@@ -5300,6 +5301,7 @@ def workout_upload_api(request):
inboard=inboard, inboard=inboard,
oarlength=oarlength, oarlength=oarlength,
impeller=useImpeller, impeller=useImpeller,
workoutid=workoutid,
) )
if id == 0: # pragma: no cover if id == 0: # pragma: no cover