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)

View File

@@ -4,7 +4,8 @@ from __future__ import print_function
from __future__ import unicode_literals
from rowers.views.statements import *
from rowers.tasks import handle_calctrimp
from rowers.mailprocessing import send_confirm
# Stroke data form to test API upload
@login_required()
@@ -310,6 +311,22 @@ def strokedatajson_v2(request,id):
datadf = dataprep.dataprep(rowdata,id=row.id,bands=True,barchart=True,otwpower=True,empower=True)
job = myqueue(queuehigh, handle_calctrimp, row.id, row.csvfilename, r.ftp,r.sex,r.hrftp, r.max, r.rest)
isbreakthrough, ishard = dataprep.checkbreakthrough(row, r)
if r.getemailnotifications and not r.emailbounced:
link = settings.SITE_URL+reverse(
r.defaultlandingpage,
kwargs = {
'id':encoder.encode_hex(row.id),
}
)
email_sent = send_confirm(r.user, row.name, link, '')
result = uploads.do_sync(row,{},quick=True)
with open('apilog.log','a') as logfile:
logfile.write(str(timezone.now())+": ")
logfile.write(request.user.username+" (strokedatajson_v2 POST completed successfully) \n")