Private
Public Access
1
0

better calculation of world class record

This commit is contained in:
Sander Roosendaal
2020-12-05 14:21:37 +01:00
parent 1dd0c0cff9
commit 0bb0237aee
3 changed files with 40 additions and 8 deletions

View File

@@ -1026,6 +1026,14 @@ from rowers.datautils import p0
from rowers.utils import calculate_age
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):
cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id)
try:
@@ -1033,21 +1041,30 @@ def fitscore(rower,workout):
except:
df, delta, cpvalues = setcp(workout)
if df.empty:
df, delta, cpvalues = setcp(workout)
age = calculate_age(rower.birthdate,today=workout.date)
agerecords = CalcAgePerformance.objects.filter(
age=age,
sex=rower.sex,
weightcategory = rower.weightcategory
)
wcdurations = []
wcpower = []
getrecords = len(agerecords) == 0
for record in agerecords:
wcdurations.append(record.duration)
wcpower.append(record.power)
if record.power > 0:
wcdurations.append(record.duration)
wcpower.append(record.power)
else:
getrecords = True
if len(agerecords)==0:
durations = [1,4,10,20,30,60]
distances = []
if getrecords:
durations = [1,4,30,60]
distances = [100,500,1000,2000,5000,6000,10000,21097,42195]
df2 = pd.DataFrame(
list(
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]))
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))
else:
factor = fitfunc(p0,wcdurations.mean()/wcpower.mean())
p1wc = [p0[0]/factor,p0[1]/factor,p0[2],p0[3]]
success = 0
return 0,0
times = df['delta']
@@ -1079,6 +1097,7 @@ def fitscore(rower,workout):
wcpowers = fitfunc(p1wc,times)
scores = 100.*powers/wcpowers
try:
indexmax = scores.idxmax()
delta = df.loc[indexmax,'delta']
@@ -1127,7 +1146,6 @@ def setcp(workout,background=False):
return job.id
if not strokesdf.empty:
totaltime = strokesdf['time'].max()
try: