better calculation of world class record
This commit is contained in:
@@ -1026,6 +1026,14 @@ from rowers.datautils import p0
|
|||||||
from rowers.utils import calculate_age
|
from rowers.utils import calculate_age
|
||||||
from scipy import optimize
|
from scipy import optimize
|
||||||
|
|
||||||
|
def workout_goldmedalstandard(workout):
|
||||||
|
if workout.goldmedalstandard > 0:
|
||||||
|
return workout.goldmedalstandard
|
||||||
|
goldmedalstandard,goldmedalduration = fitscore(workout.user,workout)
|
||||||
|
workout.goldmedalstandard = goldmedalstandard
|
||||||
|
workout.save()
|
||||||
|
return goldmedalstandard
|
||||||
|
|
||||||
def fitscore(rower,workout):
|
def fitscore(rower,workout):
|
||||||
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
|
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
|
||||||
try:
|
try:
|
||||||
@@ -1033,21 +1041,30 @@ def fitscore(rower,workout):
|
|||||||
except:
|
except:
|
||||||
df, delta, cpvalues = setcp(workout)
|
df, delta, cpvalues = setcp(workout)
|
||||||
|
|
||||||
|
if df.empty:
|
||||||
|
df, delta, cpvalues = setcp(workout)
|
||||||
|
|
||||||
age = calculate_age(rower.birthdate,today=workout.date)
|
age = calculate_age(rower.birthdate,today=workout.date)
|
||||||
|
|
||||||
agerecords = CalcAgePerformance.objects.filter(
|
agerecords = CalcAgePerformance.objects.filter(
|
||||||
age=age,
|
age=age,
|
||||||
sex=rower.sex,
|
sex=rower.sex,
|
||||||
weightcategory = rower.weightcategory
|
weightcategory = rower.weightcategory
|
||||||
)
|
)
|
||||||
|
|
||||||
wcdurations = []
|
wcdurations = []
|
||||||
wcpower = []
|
wcpower = []
|
||||||
|
getrecords = len(agerecords) == 0
|
||||||
for record in agerecords:
|
for record in agerecords:
|
||||||
wcdurations.append(record.duration)
|
if record.power > 0:
|
||||||
wcpower.append(record.power)
|
wcdurations.append(record.duration)
|
||||||
|
wcpower.append(record.power)
|
||||||
|
else:
|
||||||
|
getrecords = True
|
||||||
|
|
||||||
if len(agerecords)==0:
|
if getrecords:
|
||||||
durations = [1,4,10,20,30,60]
|
durations = [1,4,30,60]
|
||||||
distances = []
|
distances = [100,500,1000,2000,5000,6000,10000,21097,42195]
|
||||||
df2 = pd.DataFrame(
|
df2 = pd.DataFrame(
|
||||||
list(
|
list(
|
||||||
C2WorldClassAgePerformance.objects.filter(
|
C2WorldClassAgePerformance.objects.filter(
|
||||||
@@ -1066,12 +1083,13 @@ def fitscore(rower,workout):
|
|||||||
fitfunc = lambda pars,x: pars[0]/(1+(x/pars[2])) + pars[1]/(1+(x/pars[3]))
|
fitfunc = lambda pars,x: pars[0]/(1+(x/pars[2])) + pars[1]/(1+(x/pars[3]))
|
||||||
errfunc = lambda pars,x,y: fitfunc(pars,x)-y
|
errfunc = lambda pars,x,y: fitfunc(pars,x)-y
|
||||||
|
|
||||||
if len(wcdurations)>4:
|
if len(wcdurations)>=4:
|
||||||
p1wc, success = optimize.leastsq(errfunc, p0[:],args=(wcdurations,wcpower))
|
p1wc, success = optimize.leastsq(errfunc, p0[:],args=(wcdurations,wcpower))
|
||||||
else:
|
else:
|
||||||
factor = fitfunc(p0,wcdurations.mean()/wcpower.mean())
|
factor = fitfunc(p0,wcdurations.mean()/wcpower.mean())
|
||||||
p1wc = [p0[0]/factor,p0[1]/factor,p0[2],p0[3]]
|
p1wc = [p0[0]/factor,p0[1]/factor,p0[2],p0[3]]
|
||||||
success = 0
|
success = 0
|
||||||
|
return 0,0
|
||||||
|
|
||||||
|
|
||||||
times = df['delta']
|
times = df['delta']
|
||||||
@@ -1079,6 +1097,7 @@ def fitscore(rower,workout):
|
|||||||
wcpowers = fitfunc(p1wc,times)
|
wcpowers = fitfunc(p1wc,times)
|
||||||
scores = 100.*powers/wcpowers
|
scores = 100.*powers/wcpowers
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
indexmax = scores.idxmax()
|
indexmax = scores.idxmax()
|
||||||
delta = df.loc[indexmax,'delta']
|
delta = df.loc[indexmax,'delta']
|
||||||
@@ -1127,7 +1146,6 @@ def setcp(workout,background=False):
|
|||||||
return job.id
|
return job.id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not strokesdf.empty:
|
if not strokesdf.empty:
|
||||||
totaltime = strokesdf['time'].max()
|
totaltime = strokesdf['time'].max()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import json
|
|||||||
|
|
||||||
from scipy import optimize
|
from scipy import optimize
|
||||||
from scipy.signal import savgol_filter
|
from scipy.signal import savgol_filter
|
||||||
|
from scipy.interpolate import griddata
|
||||||
|
|
||||||
import rowingdata
|
import rowingdata
|
||||||
from rowingdata import make_cumvalues
|
from rowingdata import make_cumvalues
|
||||||
@@ -333,7 +334,11 @@ def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
|||||||
|
|
||||||
power = 0.5*(np.abs(power)+power)
|
power = 0.5*(np.abs(power)+power)
|
||||||
else:
|
else:
|
||||||
power = 0
|
new_age = np.range([age])
|
||||||
|
ww = griddata(ages.values,
|
||||||
|
powers.values,
|
||||||
|
new_age,method='linear',rescale=True)
|
||||||
|
power = 0.5*(np.abs(power)+power)
|
||||||
else:
|
else:
|
||||||
power = 0
|
power = 0
|
||||||
|
|
||||||
|
|||||||
@@ -3497,6 +3497,15 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
|
|||||||
|
|
||||||
# Normalized power & TSS
|
# Normalized power & TSS
|
||||||
tss,normp = dataprep.workout_rscore(w)
|
tss,normp = dataprep.workout_rscore(w)
|
||||||
|
goldmedalstandard = dataprep.workout_goldmedalstandard(w)
|
||||||
|
|
||||||
|
|
||||||
|
if not np.isnan(goldmedalstandard) and goldmedalstandard > 0:
|
||||||
|
otherstats['goldmedalstandard'] = {
|
||||||
|
'verbose_name': 'Gold Medal Standard',
|
||||||
|
'value': int(goldmedalstandard),
|
||||||
|
'unit': '%',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if not np.isnan(tss) and tss != 0:
|
if not np.isnan(tss) and tss != 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user