Merge branch 'feature/newranking' into develop
This commit is contained in:
@@ -1102,6 +1102,62 @@ def workout_goldmedalstandard(workout):
|
|||||||
else:
|
else:
|
||||||
return 0,0
|
return 0,0
|
||||||
|
|
||||||
|
def check_marker(workout):
|
||||||
|
r = workout.user
|
||||||
|
gmstandard,gmseconds = workout_goldmedalstandard(workout)
|
||||||
|
if gmseconds<60:
|
||||||
|
return None
|
||||||
|
|
||||||
|
dd = arrow.get(workout.date).datetime-datetime.timedelta(days=r.kfit)
|
||||||
|
ws = Workout.objects.filter(date__gte=dd,
|
||||||
|
date__lte=workout.date,
|
||||||
|
user=r,duplicate=False,
|
||||||
|
workouttype__in=mytypes.rowtypes,
|
||||||
|
).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 +1526,9 @@ 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:
|
||||||
|
if not w.duplicate:
|
||||||
|
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 +1539,9 @@ 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:
|
||||||
|
if not w.duplicate:
|
||||||
|
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 +1786,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 +1835,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)
|
||||||
|
|
||||||
|
|||||||
+22
-40
@@ -1801,9 +1801,17 @@ def goldmedalscorechart(user,startdate=None,enddate=None):
|
|||||||
duplicate=False)
|
duplicate=False)
|
||||||
|
|
||||||
# marker workouts
|
# marker workouts
|
||||||
dates,testpower,testduration,fatigues,fitnesses,impulses, outids = build_goldmedalstandards(
|
workouts = Workout.objects.filter(user=user.rower,date__gte=startdate,
|
||||||
workouts,42
|
date__lte=enddate,
|
||||||
)
|
workouttype__in=mytypes.rowtypes,
|
||||||
|
duplicate=False).order_by('date')
|
||||||
|
|
||||||
|
markerworkouts = workouts.filter(rankingpiece=True)
|
||||||
|
outids = [w.id for w in markerworkouts]
|
||||||
|
dates = [arrow.get(w.date).datetime for w in markerworkouts]
|
||||||
|
testpower = [w.goldmedalstandard if w.rankingpiece else np.nan for w in markerworkouts]
|
||||||
|
|
||||||
|
testduration = [w.goldmedalseconds if w.rankingpiece else 0 for w in markerworkouts]
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pd.DataFrame({
|
||||||
'id':outids,
|
'id':outids,
|
||||||
@@ -1813,8 +1821,8 @@ def goldmedalscorechart(user,startdate=None,enddate=None):
|
|||||||
})
|
})
|
||||||
df.sort_values(['date'],inplace=True)
|
df.sort_values(['date'],inplace=True)
|
||||||
|
|
||||||
df['testdup'] = df['testpower'].shift(1)
|
#df['testdup'] = df['testpower'].shift(1)
|
||||||
df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1)
|
#df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1)
|
||||||
#df['date'] = df.apply(lambda x: newtestpowerdate(x), axis=1)
|
#df['date'] = df.apply(lambda x: newtestpowerdate(x), axis=1)
|
||||||
|
|
||||||
|
|
||||||
@@ -1985,41 +1993,16 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7,
|
|||||||
workouts = Workout.objects.filter(user=user.rower,date__gte=startdate,
|
workouts = Workout.objects.filter(user=user.rower,date__gte=startdate,
|
||||||
date__lte=enddate,
|
date__lte=enddate,
|
||||||
workouttype__in=mytypes.rowtypes,
|
workouttype__in=mytypes.rowtypes,
|
||||||
duplicate=False)
|
duplicate=False).order_by('date')
|
||||||
dates,testpower,testduration,fatigues,fitnesses,impulses, outids = build_goldmedalstandards(
|
|
||||||
workouts,kfitness
|
|
||||||
)
|
|
||||||
|
|
||||||
|
markerworkouts = workouts.filter(rankingpiece=True)
|
||||||
df = pd.DataFrame({
|
outids = [w.id for w in markerworkouts]
|
||||||
'id': outids,
|
dates = [arrow.get(w.date).datetime for w in workouts]
|
||||||
'date':dates,
|
testpower = [w.goldmedalstandard if w.rankingpiece else np.nan for w in workouts]
|
||||||
'testpower':testpower,
|
impulses = [np.nan for w in workouts]
|
||||||
'testduration':testduration,
|
testduration = [w.goldmedalseconds if w.rankingpiece else 0 for w in workouts]
|
||||||
'fatigue':fatigues,
|
fitnesses = [np.nan for w in workouts]
|
||||||
'fitness':fitnesses,
|
fatigues = [np.nan for w in workouts]
|
||||||
'impulse':impulses,
|
|
||||||
})
|
|
||||||
df.sort_values(['date'],inplace=True)
|
|
||||||
if showtests:
|
|
||||||
df['testdup'] = df['testpower'].shift(1)
|
|
||||||
df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1)
|
|
||||||
df['id'] = df.apply(lambda x: newtestpowerid(x),axis=1)
|
|
||||||
|
|
||||||
#try:
|
|
||||||
# df['testpower'].iloc[-1] = df['testdup'].iloc[-1]
|
|
||||||
#except IndexError:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
dates = [d for d in df['date']]
|
|
||||||
testpower = df['testpower'].values.tolist()
|
|
||||||
fatigues = df['fatigue'].values.tolist()
|
|
||||||
fitnesses = df['fitness'].values.tolist()
|
|
||||||
testduration = df['testduration'].values.tolist()
|
|
||||||
impulses = df['impulse'].tolist()
|
|
||||||
|
|
||||||
outids = df['id'].unique()
|
|
||||||
|
|
||||||
fatigues,fitnesses,dates,testpower,testduration,impulses = getfatigues(fatigues,
|
fatigues,fitnesses,dates,testpower,testduration,impulses = getfatigues(fatigues,
|
||||||
fitnesses,
|
fitnesses,
|
||||||
@@ -2031,7 +2014,6 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7,
|
|||||||
kfatigue,kfitness)
|
kfatigue,kfitness)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pd.DataFrame({
|
||||||
'date':dates,
|
'date':dates,
|
||||||
'testpower':testpower,
|
'testpower':testpower,
|
||||||
|
|||||||
Reference in New Issue
Block a user