Private
Public Access
1
0

Merge branch 'release/v18.9.13'

This commit is contained in:
Sander Roosendaal
2023-01-21 17:15:25 +01:00
7 changed files with 97 additions and 33 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

@@ -4193,6 +4193,13 @@ class WorkoutForm(ModelForm):
else: else:
del self.fields['plannedsession'] del self.fields['plannedsession']
def clean(self):
if any(self.errors):
return
cd = self.cleaned_data
if cd['duration'] is None or cd['duration'] == '':
raise forms.ValidationError('Duration cannot be empty')
# Used for the rowing physics calculations # Used for the rowing physics calculations

View File

@@ -51,7 +51,9 @@ graphql_url = "https://rp3rowing-app.com/graphql"
# Checks if user has UnderArmour token, renews them if they are expired # Checks if user has UnderArmour token, renews them if they are expired
def rp3_open(user): def rp3_open(user):
tokenexpirydate = user.rower.rp3tokenexpirydate tokenexpirydate = user.rower.rp3tokenexpirydate
if timezone.now()-timedelta(days=120)>tokenexpirydate: if tokenexpirydate is None:
raise NoTokenError
if tokenexpirydate is not None and timezone.now()-timedelta(days=120)>tokenexpirydate:
user.rower.rp3tokenexpirydate = timezone.now()-timedelta(days=1) user.rower.rp3tokenexpirydate = timezone.now()-timedelta(days=1)
user.rower.save() user.rower.save()
raise NoTokenError raise NoTokenError

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