moving age group records to c2stuff
This commit is contained in:
@@ -29,6 +29,70 @@ queue = django_rq.get_queue('default')
|
|||||||
queuelow = django_rq.get_queue('low')
|
queuelow = django_rq.get_queue('low')
|
||||||
queuehigh = django_rq.get_queue('low')
|
queuehigh = django_rq.get_queue('low')
|
||||||
from rowers.utils import myqueue
|
from rowers.utils import myqueue
|
||||||
|
from rowers.models import C2WorldClassAgePerformance
|
||||||
|
|
||||||
|
def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
||||||
|
distance=2000,duration=None,indf=pd.DataFrame()):
|
||||||
|
|
||||||
|
if not indf.empty:
|
||||||
|
if not duration:
|
||||||
|
df = indf[indf['distance'] == distance]
|
||||||
|
else:
|
||||||
|
duration = 60*int(duration)
|
||||||
|
df = indf[indf['duration'] == duration]
|
||||||
|
else:
|
||||||
|
if not duration:
|
||||||
|
df = pd.DataFrame(
|
||||||
|
list(
|
||||||
|
C2WorldClassAgePerformance.objects.filter(
|
||||||
|
distance=distance,
|
||||||
|
sex=sex,
|
||||||
|
weightcategory=weightcategory
|
||||||
|
).values()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
duration=60*int(duration)
|
||||||
|
df = pd.DataFrame(
|
||||||
|
list(
|
||||||
|
C2WorldClassAgePerformance.objects.filter(
|
||||||
|
duration=duration,
|
||||||
|
sex=sex,
|
||||||
|
weightcategory=weightcategory
|
||||||
|
).values()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not df.empty:
|
||||||
|
ages = df['age']
|
||||||
|
powers = df['power']
|
||||||
|
|
||||||
|
#poly_coefficients = np.polyfit(ages,powers,6)
|
||||||
|
fitfunc = lambda pars, x: np.abs(pars[0])*(1-x/max(120,pars[1]))-np.abs(pars[2])*np.exp(-x/np.abs(pars[3]))+np.abs(pars[4])*(np.sin(np.pi*x/max(50,pars[5])))
|
||||||
|
errfunc = lambda pars, x,y: fitfunc(pars,x)-y
|
||||||
|
|
||||||
|
p0 = [700,120,700,10,100,100]
|
||||||
|
|
||||||
|
try:
|
||||||
|
p1, success = optimize.leastsq(errfunc,p0[:],
|
||||||
|
args = (ages,powers))
|
||||||
|
except:
|
||||||
|
p1 = p0
|
||||||
|
success = 0
|
||||||
|
|
||||||
|
if success:
|
||||||
|
power = fitfunc(p1, float(age))
|
||||||
|
|
||||||
|
#power = np.polyval(poly_coefficients,age)
|
||||||
|
|
||||||
|
power = 0.5*(np.abs(power)+power)
|
||||||
|
else:
|
||||||
|
power = 0
|
||||||
|
else:
|
||||||
|
power = 0
|
||||||
|
|
||||||
|
return power
|
||||||
|
|
||||||
|
|
||||||
oauth_data = {
|
oauth_data = {
|
||||||
'client_id': C2_CLIENT_ID,
|
'client_id': C2_CLIENT_ID,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from __future__ import unicode_literals
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from rowers.utils import lbstoN
|
from rowers.utils import lbstoN
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from rowers.models import C2WorldClassAgePerformance
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from scipy import optimize
|
from scipy import optimize
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@@ -397,64 +397,3 @@ def calc_trimp(df,sex,hrmax,hrmin,hrftp):
|
|||||||
return trimp,hrtss
|
return trimp,hrtss
|
||||||
|
|
||||||
|
|
||||||
def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
|
||||||
distance=2000,duration=None,indf=pd.DataFrame()):
|
|
||||||
|
|
||||||
if not indf.empty:
|
|
||||||
if not duration:
|
|
||||||
df = indf[indf['distance'] == distance]
|
|
||||||
else:
|
|
||||||
duration = 60*int(duration)
|
|
||||||
df = indf[indf['duration'] == duration]
|
|
||||||
else:
|
|
||||||
if not duration:
|
|
||||||
df = pd.DataFrame(
|
|
||||||
list(
|
|
||||||
C2WorldClassAgePerformance.objects.filter(
|
|
||||||
distance=distance,
|
|
||||||
sex=sex,
|
|
||||||
weightcategory=weightcategory
|
|
||||||
).values()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
duration=60*int(duration)
|
|
||||||
df = pd.DataFrame(
|
|
||||||
list(
|
|
||||||
C2WorldClassAgePerformance.objects.filter(
|
|
||||||
duration=duration,
|
|
||||||
sex=sex,
|
|
||||||
weightcategory=weightcategory
|
|
||||||
).values()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not df.empty:
|
|
||||||
ages = df['age']
|
|
||||||
powers = df['power']
|
|
||||||
|
|
||||||
#poly_coefficients = np.polyfit(ages,powers,6)
|
|
||||||
fitfunc = lambda pars, x: np.abs(pars[0])*(1-x/max(120,pars[1]))-np.abs(pars[2])*np.exp(-x/np.abs(pars[3]))+np.abs(pars[4])*(np.sin(np.pi*x/max(50,pars[5])))
|
|
||||||
errfunc = lambda pars, x,y: fitfunc(pars,x)-y
|
|
||||||
|
|
||||||
p0 = [700,120,700,10,100,100]
|
|
||||||
|
|
||||||
try:
|
|
||||||
p1, success = optimize.leastsq(errfunc,p0[:],
|
|
||||||
args = (ages,powers))
|
|
||||||
except:
|
|
||||||
p1 = p0
|
|
||||||
success = 0
|
|
||||||
|
|
||||||
if success:
|
|
||||||
power = fitfunc(p1, float(age))
|
|
||||||
|
|
||||||
#power = np.polyval(poly_coefficients,age)
|
|
||||||
|
|
||||||
power = 0.5*(np.abs(power)+power)
|
|
||||||
else:
|
|
||||||
power = 0
|
|
||||||
else:
|
|
||||||
power = 0
|
|
||||||
|
|
||||||
return power
|
|
||||||
|
|||||||
Reference in New Issue
Block a user