Merge branch 'feature/newranking' into develop
This commit is contained in:
@@ -1102,6 +1102,62 @@ def workout_goldmedalstandard(workout):
|
||||
else:
|
||||
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):
|
||||
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
|
||||
try:
|
||||
@@ -1470,6 +1526,9 @@ def checkbreakthrough(w, r):
|
||||
|
||||
# submit email task to send email about breakthrough workout
|
||||
if isbreakthrough:
|
||||
if not w.duplicate:
|
||||
w.rankingpiece = True
|
||||
w.save()
|
||||
if r.getemailnotifications and not r.emailbounced:
|
||||
job = myqueue(queuehigh,handle_sendemail_breakthrough,
|
||||
w.id,
|
||||
@@ -1480,6 +1539,9 @@ def checkbreakthrough(w, r):
|
||||
|
||||
# submit email task to send email about breakthrough workout
|
||||
if ishard:
|
||||
if not w.duplicate:
|
||||
w.rankingpiece = True
|
||||
w.save()
|
||||
if r.getemailnotifications and not r.emailbounced:
|
||||
job = myqueue(queuehigh,handle_sendemail_hard,
|
||||
w.id,
|
||||
@@ -1724,6 +1786,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
|
||||
# check for duplicate start times and duration
|
||||
duplicate = checkduplicates(r,workoutdate,workoutstartdatetime,workoutenddatetime)
|
||||
if duplicate:
|
||||
rankingpiece = False
|
||||
|
||||
# test title length
|
||||
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)
|
||||
|
||||
isbreakthrough, ishard = checkbreakthrough(w, r)
|
||||
marker = check_marker(w)
|
||||
|
||||
return (w.id, message)
|
||||
|
||||
|
||||
+22
-40
@@ -1801,9 +1801,17 @@ def goldmedalscorechart(user,startdate=None,enddate=None):
|
||||
duplicate=False)
|
||||
|
||||
# marker workouts
|
||||
dates,testpower,testduration,fatigues,fitnesses,impulses, outids = build_goldmedalstandards(
|
||||
workouts,42
|
||||
)
|
||||
workouts = Workout.objects.filter(user=user.rower,date__gte=startdate,
|
||||
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({
|
||||
'id':outids,
|
||||
@@ -1813,8 +1821,8 @@ def goldmedalscorechart(user,startdate=None,enddate=None):
|
||||
})
|
||||
df.sort_values(['date'],inplace=True)
|
||||
|
||||
df['testdup'] = df['testpower'].shift(1)
|
||||
df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1)
|
||||
#df['testdup'] = df['testpower'].shift(1)
|
||||
#df['testpower'] = df.apply(lambda x: newtestpower(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,
|
||||
date__lte=enddate,
|
||||
workouttype__in=mytypes.rowtypes,
|
||||
duplicate=False)
|
||||
dates,testpower,testduration,fatigues,fitnesses,impulses, outids = build_goldmedalstandards(
|
||||
workouts,kfitness
|
||||
)
|
||||
duplicate=False).order_by('date')
|
||||
|
||||
|
||||
df = pd.DataFrame({
|
||||
'id': outids,
|
||||
'date':dates,
|
||||
'testpower':testpower,
|
||||
'testduration':testduration,
|
||||
'fatigue':fatigues,
|
||||
'fitness':fitnesses,
|
||||
'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()
|
||||
markerworkouts = workouts.filter(rankingpiece=True)
|
||||
outids = [w.id for w in markerworkouts]
|
||||
dates = [arrow.get(w.date).datetime for w in workouts]
|
||||
testpower = [w.goldmedalstandard if w.rankingpiece else np.nan for w in workouts]
|
||||
impulses = [np.nan for w in workouts]
|
||||
testduration = [w.goldmedalseconds if w.rankingpiece else 0 for w in workouts]
|
||||
fitnesses = [np.nan for w in workouts]
|
||||
fatigues = [np.nan for w in workouts]
|
||||
|
||||
fatigues,fitnesses,dates,testpower,testduration,impulses = getfatigues(fatigues,
|
||||
fitnesses,
|
||||
@@ -2031,7 +2014,6 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7,
|
||||
kfatigue,kfitness)
|
||||
|
||||
|
||||
|
||||
df = pd.DataFrame({
|
||||
'date':dates,
|
||||
'testpower':testpower,
|
||||
|
||||
Reference in New Issue
Block a user