Private
Public Access
1
0

refactoring and adding email confirmation / trimp calc to api v2

This commit is contained in:
Sander Roosendaal
2020-12-31 06:56:50 +01:00
parent 11cec956b7
commit e55682edd0
3 changed files with 88 additions and 43 deletions

View File

@@ -1430,6 +1430,53 @@ def create_row_df(r,distance,duration,startdatetime,workouttype='rower',
from rowers.utils import totaltime_sec_to_string
def checkbreakthrough(w, r):
isbreakthrough = False
ishard = False
workouttype = w.workouttype
if workouttype in rowtypes:
cpdf,delta,cpvalues = setcp(w)
if not cpdf.empty:
if workouttype in otwtypes:
res, btvalues, res2 = utils.isbreakthrough(
delta, cpvalues, r.p0, r.p1, r.p2, r.p3, r.cpratio)
success = update_rolling_cp(r,otwtypes,'water')
elif workouttype in otetypes:
res, btvalues, res2 = utils.isbreakthrough(
delta, cpvalues, r.ep0, r.ep1, r.ep2, r.ep3, r.ecpratio)
success = update_rolling_cp(r,otetypes,'erg')
else:
res = 0
res2 = 0
if res:
isbreakthrough = True
if res2 and not isbreakthrough:
ishard = True
# submit email task to send email about breakthrough workout
if isbreakthrough:
if r.getemailnotifications and not r.emailbounced:
job = myqueue(queuehigh,handle_sendemail_breakthrough,
w.id,
r.user.email,
r.user.first_name,
r.user.last_name,
btvalues=btvalues.to_json())
# submit email task to send email about breakthrough workout
if ishard:
if r.getemailnotifications and not r.emailbounced:
job = myqueue(queuehigh,handle_sendemail_hard,
w.id,
r.user.email,
r.user.first_name,
r.user.last_name,
btvalues=btvalues.to_json())
return isbreakthrough, ishard
# Processes painsled CSV file to database
def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
boattype='1x',
@@ -1701,48 +1748,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
job = myqueue(queuehigh,handle_calctrimp,w.id,f2,r.ftp,r.sex,r.hrftp,r.max,r.rest)
isbreakthrough = False
ishard = False
if workouttype in rowtypes:
cpdf,delta,cpvalues = setcp(w)
if not cpdf.empty:
if workouttype in otwtypes:
res, btvalues, res2 = utils.isbreakthrough(
delta, cpvalues, r.p0, r.p1, r.p2, r.p3, r.cpratio)
success = update_rolling_cp(r,otwtypes,'water')
elif workouttype in otetypes:
res, btvalues, res2 = utils.isbreakthrough(
delta, cpvalues, r.ep0, r.ep1, r.ep2, r.ep3, r.ecpratio)
success = update_rolling_cp(r,otetypes,'erg')
else:
res = 0
res2 = 0
if res:
isbreakthrough = True
if res2 and not isbreakthrough:
ishard = True
# submit email task to send email about breakthrough workout
if isbreakthrough:
if r.getemailnotifications and not r.emailbounced:
job = myqueue(queuehigh,handle_sendemail_breakthrough,
w.id,
r.user.email,
r.user.first_name,
r.user.last_name,
btvalues=btvalues.to_json())
# submit email task to send email about breakthrough workout
if ishard:
if r.getemailnotifications and not r.emailbounced:
job = myqueue(queuehigh,handle_sendemail_hard,
w.id,
r.user.email,
r.user.first_name,
r.user.last_name,
btvalues=btvalues.to_json())
isbreakthrough, ishard = checkbreakthrough(w, r)
return (w.id, message)