fitness-fit has now right algo
This commit is contained in:
@@ -25,6 +25,8 @@ import itertools
|
|||||||
from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc
|
from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc
|
||||||
from bokeh.models import CustomJS,Slider, TextInput,BoxAnnotation, Band
|
from bokeh.models import CustomJS,Slider, TextInput,BoxAnnotation, Band
|
||||||
|
|
||||||
|
import arrow
|
||||||
|
|
||||||
from rowers.utils import myqueue, totaltime_sec_to_string
|
from rowers.utils import myqueue, totaltime_sec_to_string
|
||||||
import django_rq
|
import django_rq
|
||||||
queue = django_rq.get_queue('default')
|
queue = django_rq.get_queue('default')
|
||||||
@@ -102,6 +104,16 @@ import rowers.datautils as datautils
|
|||||||
|
|
||||||
from pandas.core.groupby.groupby import DataError
|
from pandas.core.groupby.groupby import DataError
|
||||||
|
|
||||||
|
def newtestpower(x):
|
||||||
|
try:
|
||||||
|
if abs(x['testpower'] - x['testdup']) < 1:
|
||||||
|
return np.nan
|
||||||
|
except (AttributeError,TypeError):
|
||||||
|
return np.nan
|
||||||
|
|
||||||
|
|
||||||
|
return x['testpower']
|
||||||
|
|
||||||
def build_goldmedalstandards(workouts,kfitness):
|
def build_goldmedalstandards(workouts,kfitness):
|
||||||
dates = []
|
dates = []
|
||||||
testpower = []
|
testpower = []
|
||||||
@@ -113,20 +125,48 @@ def build_goldmedalstandards(workouts,kfitness):
|
|||||||
goldmedalstandards = []
|
goldmedalstandards = []
|
||||||
goldmedaldurations = []
|
goldmedaldurations = []
|
||||||
ids = []
|
ids = []
|
||||||
|
workoutdt = []
|
||||||
for w in workouts:
|
for w in workouts:
|
||||||
goldmedalstandard,goldmedalseconds = dataprep.workout_goldmedalstandard(w)
|
goldmedalstandard,goldmedalseconds = dataprep.workout_goldmedalstandard(w)
|
||||||
ids.append(w.id)
|
ids.append(w.id)
|
||||||
goldmedalstandards.append(goldmedalstandard)
|
if w.workouttype in mytypes.otwtypes:
|
||||||
goldmedaldurations.append(goldmedalseconds)
|
goldmedalstandard = goldmedalstandard / (1.-w.user.otwslack/100.)
|
||||||
|
if goldmedalseconds > 60:
|
||||||
|
goldmedalstandards.append(goldmedalstandard)
|
||||||
|
goldmedaldurations.append(goldmedalseconds)
|
||||||
|
else:
|
||||||
|
goldmedalstandards.append(0)
|
||||||
|
goldmedaldurations.append(0)
|
||||||
|
workoutdt.append(arrow.get(w.startdatetime).datetime)
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pd.DataFrame({
|
||||||
'workout':ids,
|
'workout':ids,
|
||||||
|
'workoutdt': workoutdt,
|
||||||
'goldmedalstandard':goldmedalstandards,
|
'goldmedalstandard':goldmedalstandards,
|
||||||
'goldmedalduration':goldmedaldurations,
|
'goldmedalduration':goldmedaldurations,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
df.sort_values(['workoutdt'],inplace=True)
|
||||||
|
|
||||||
|
#for id, row in df.iterrows():
|
||||||
|
# d = row['workoutdt']
|
||||||
|
# dd = d-datetime.timedelta(days=90)
|
||||||
|
# mask = df['workoutdt']>dd
|
||||||
|
# mask2 = df['workoutdt']<=d
|
||||||
|
# df2 = df.where(mask & mask2)
|
||||||
|
# powertest = df2['goldmedalstandard'].max()
|
||||||
|
# idx = df2['goldmedalstandard'].argmax()
|
||||||
|
# durationtest = df2['goldmedalduration'].values[idx]
|
||||||
|
# dates.append(d)
|
||||||
|
# testpower.append(powertest)
|
||||||
|
# testduration.append(durationtest)
|
||||||
|
# fatigues.append(np.nan)
|
||||||
|
# fitnesses.append(np.nan)
|
||||||
|
|
||||||
for w in workouts:
|
for w in workouts:
|
||||||
ids = [w.id for w in workouts.filter(date__gte=w.date-datetime.timedelta(days=kfitness),
|
ids = [w.id for w in workouts.filter(date__gte=w.date-datetime.timedelta(days=90),
|
||||||
date__lte=w.date)]
|
date__lte=w.date)]
|
||||||
|
|
||||||
powerdf = df[df['workout'].isin(ids)]
|
powerdf = df[df['workout'].isin(ids)]
|
||||||
@@ -134,9 +174,14 @@ def build_goldmedalstandards(workouts,kfitness):
|
|||||||
powertest = powerdf['goldmedalstandard'].max()
|
powertest = powerdf['goldmedalstandard'].max()
|
||||||
durationtest = powerdf.loc[indexmax,'goldmedalduration']
|
durationtest = powerdf.loc[indexmax,'goldmedalduration']
|
||||||
|
|
||||||
dates.append(datetime.datetime.combine(w.date,datetime.datetime.min.time()))
|
|
||||||
testpower.append(powertest)
|
dates.append(arrow.get(w.date).datetime)
|
||||||
testduration.append(durationtest)
|
if powertest > 0:
|
||||||
|
testpower.append(powertest)
|
||||||
|
testduration.append(durationtest)
|
||||||
|
else:
|
||||||
|
testpower.append(np.nan)
|
||||||
|
testduration.append(np.nan)
|
||||||
|
|
||||||
fatigues.append(np.nan)
|
fatigues.append(np.nan)
|
||||||
fitnesses.append(np.nan)
|
fitnesses.append(np.nan)
|
||||||
@@ -156,7 +201,7 @@ def get_testpower(workouts,fitnesstestsecs,kfitness):
|
|||||||
try:
|
try:
|
||||||
df = pd.read_parquet(cpfile)
|
df = pd.read_parquet(cpfile)
|
||||||
df['workout'] = w.id
|
df['workout'] = w.id
|
||||||
df['workoutdate'] = w.date.strftime('%d-%m-%Y')
|
df['workoutdate'] = arrow.get(w.date.strftime('%d-%m-%Y')).datetime
|
||||||
data.append(df)
|
data.append(df)
|
||||||
except:
|
except:
|
||||||
strokesdf = dataprep.getsmallrowdata_db(['power','workoutid','time'],ids=[w.id])
|
strokesdf = dataprep.getsmallrowdata_db(['power','workoutid','time'],ids=[w.id])
|
||||||
@@ -203,7 +248,7 @@ def get_testpower(workouts,fitnesstestsecs,kfitness):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
dates.append(datetime.datetime.combine(w.date,datetime.datetime.min.time()))
|
dates.append(arrow.get(w.date).datetime)
|
||||||
testpower.append(powertest)
|
testpower.append(powertest)
|
||||||
testduration.append(fitnesstestsecs)
|
testduration.append(fitnesstestsecs)
|
||||||
fatigues.append(np.nan)
|
fatigues.append(np.nan)
|
||||||
@@ -1710,7 +1755,7 @@ def getfatigues(
|
|||||||
|
|
||||||
fatigues.append(fatigue)
|
fatigues.append(fatigue)
|
||||||
fitnesses.append(fitness)
|
fitnesses.append(fitness)
|
||||||
dates.append(datetime.datetime.combine(date,datetime.datetime.min.time()))
|
dates.append(arrow.get(date).datetime)
|
||||||
testpower.append(np.nan)
|
testpower.append(np.nan)
|
||||||
testduration.append(np.nan)
|
testduration.append(np.nan)
|
||||||
|
|
||||||
@@ -1978,8 +2023,7 @@ def fitnessfit_chart(workouts,user,workoutmode='water',startdate=None,
|
|||||||
|
|
||||||
|
|
||||||
df['testdup'] = df['testpower'].shift(1)
|
df['testdup'] = df['testpower'].shift(1)
|
||||||
df['testpower'] = df.apply(lambda x: np.nan if abs(x['testpower'] - x['testdup']) < 1 \
|
df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1)
|
||||||
else x['testpower'],axis=1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
df['testpower'].iloc[-1] = df['testdup'].iloc[-1]
|
df['testpower'].iloc[-1] = df['testdup'].iloc[-1]
|
||||||
|
|||||||
@@ -1678,13 +1678,9 @@ def fitness_from_cp_view(request,userid=0,mode='rower',
|
|||||||
|
|
||||||
workouts = Workout.objects.filter(user=therower,date__gte=startdate,
|
workouts = Workout.objects.filter(user=therower,date__gte=startdate,
|
||||||
date__lte=enddate,
|
date__lte=enddate,
|
||||||
workouttype__in=mytypes.otwtypes,
|
workouttype__in=mytypes.rowtypes,
|
||||||
duplicate=False)
|
duplicate=False)
|
||||||
if mode == 'rower':
|
|
||||||
workouts = Workout.objects.filter(user=therower,date__gte=startdate,
|
|
||||||
date__lte=enddate,workouttype__in=mytypes.otetypes,
|
|
||||||
duplicate=False)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
script,thediv = fitnessfit_chart(
|
script,thediv = fitnessfit_chart(
|
||||||
|
|||||||
Reference in New Issue
Block a user