setting marker on workout first save
This commit is contained in:
@@ -1102,6 +1102,56 @@ def workout_goldmedalstandard(workout):
|
|||||||
else:
|
else:
|
||||||
return 0,0
|
return 0,0
|
||||||
|
|
||||||
|
def check_marker(workout):
|
||||||
|
r = workout.user
|
||||||
|
ws = Workout.objects.filter(date__gte=workout.date-datetime.timedelta(days=r.kfit),
|
||||||
|
date__lte=workout.date,
|
||||||
|
user=r,duplicate=False,
|
||||||
|
).order_by("date")
|
||||||
|
ids = []
|
||||||
|
gms = []
|
||||||
|
for w in ws:
|
||||||
|
gmstandard,gmseconds = workout_goldmedalstandard(w)
|
||||||
|
if gmseconds>60:
|
||||||
|
ids.append(w.id)
|
||||||
|
gms.append(gmstandard)
|
||||||
|
|
||||||
|
df = pd.DataFrame({
|
||||||
|
'id':ids,
|
||||||
|
'gms':gms,
|
||||||
|
})
|
||||||
|
|
||||||
|
if df.empty:
|
||||||
|
workout.ranking = True
|
||||||
|
workout.save()
|
||||||
|
return workout
|
||||||
|
|
||||||
|
indexmax = df['gms'].idxmax()
|
||||||
|
theid = df.loc[indexmax,'id']
|
||||||
|
|
||||||
|
wmax = Workout.objects.get(id=theid)
|
||||||
|
gms_max = wmax.goldmedalstandard
|
||||||
|
|
||||||
|
# check if equal, bigger, or smaller than previous
|
||||||
|
if not wmax.rankingpiece:
|
||||||
|
rankingworkouts = ws.filter(rankingpiece=True)
|
||||||
|
if len(rankingworkouts) == 0:
|
||||||
|
wmax.rankingpiece = True
|
||||||
|
wmax.save()
|
||||||
|
return wmax
|
||||||
|
|
||||||
|
lastranking = rankingworkouts[len(rankingworkouts)-1]
|
||||||
|
if lastranking.goldmedalstandard+0.2 < wmax.goldmedalstandard:
|
||||||
|
wmax.rankingpiece = True
|
||||||
|
wmax.save()
|
||||||
|
return wmax
|
||||||
|
else:
|
||||||
|
return wmax
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_goldmedalstandard(rower,workout,recurrance=True):
|
def calculate_goldmedalstandard(rower,workout,recurrance=True):
|
||||||
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
|
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
|
||||||
try:
|
try:
|
||||||
@@ -1470,6 +1520,8 @@ def checkbreakthrough(w, r):
|
|||||||
|
|
||||||
# submit email task to send email about breakthrough workout
|
# submit email task to send email about breakthrough workout
|
||||||
if isbreakthrough:
|
if isbreakthrough:
|
||||||
|
w.rankingpiece = True
|
||||||
|
w.save()
|
||||||
if r.getemailnotifications and not r.emailbounced:
|
if r.getemailnotifications and not r.emailbounced:
|
||||||
job = myqueue(queuehigh,handle_sendemail_breakthrough,
|
job = myqueue(queuehigh,handle_sendemail_breakthrough,
|
||||||
w.id,
|
w.id,
|
||||||
@@ -1480,6 +1532,8 @@ def checkbreakthrough(w, r):
|
|||||||
|
|
||||||
# submit email task to send email about breakthrough workout
|
# submit email task to send email about breakthrough workout
|
||||||
if ishard:
|
if ishard:
|
||||||
|
w.rankingpiece = True
|
||||||
|
w.save()
|
||||||
if r.getemailnotifications and not r.emailbounced:
|
if r.getemailnotifications and not r.emailbounced:
|
||||||
job = myqueue(queuehigh,handle_sendemail_hard,
|
job = myqueue(queuehigh,handle_sendemail_hard,
|
||||||
w.id,
|
w.id,
|
||||||
@@ -1724,6 +1778,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
|||||||
|
|
||||||
# check for duplicate start times and duration
|
# check for duplicate start times and duration
|
||||||
duplicate = checkduplicates(r,workoutdate,workoutstartdatetime,workoutenddatetime)
|
duplicate = checkduplicates(r,workoutdate,workoutstartdatetime,workoutenddatetime)
|
||||||
|
if duplicate:
|
||||||
|
rankingpiece = False
|
||||||
|
|
||||||
# test title length
|
# test title length
|
||||||
if title is not None and len(title)>140:
|
if title is not None and len(title)>140:
|
||||||
@@ -1771,6 +1827,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)
|
job = myqueue(queuehigh,handle_calctrimp,w.id,f2,r.ftp,r.sex,r.hrftp,r.max,r.rest)
|
||||||
|
|
||||||
isbreakthrough, ishard = checkbreakthrough(w, r)
|
isbreakthrough, ishard = checkbreakthrough(w, r)
|
||||||
|
marker = check_marker(w)
|
||||||
|
|
||||||
return (w.id, message)
|
return (w.id, message)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user