changed to exponential function
This commit is contained in:
@@ -53,6 +53,7 @@ import stravastuff
|
||||
|
||||
from rowers.dataprep import rdata
|
||||
import rowers.dataprep as dataprep
|
||||
import rowers.metrics as metrics
|
||||
|
||||
from rowers.metrics import axes,axlabels,yaxminima,yaxmaxima
|
||||
|
||||
@@ -1069,24 +1070,38 @@ def interactive_otwcpchart(powerdf,promember=0):
|
||||
|
||||
return [script,div,p1,ratio,message]
|
||||
|
||||
def interactive_agegroup_plot(df):
|
||||
def interactive_agegroup_plot(df,distance=2000,duration=None,
|
||||
sex='male',weightcategory='hwt'):
|
||||
|
||||
age = df['age']
|
||||
power = df['power']
|
||||
name = df['name']
|
||||
season = df['season']
|
||||
|
||||
poly_coefficients = np.polyfit(age,power,6)
|
||||
# poly_coefficients = np.polyfit(age,power,6)
|
||||
|
||||
age2 = np.linspace(11,95)
|
||||
poly_vals = np.polyval(poly_coefficients,age2)
|
||||
# poly_vals = np.polyval(poly_coefficients,age2)
|
||||
# poly_vals = 0.5*(np.abs(poly_vals)+poly_vals)
|
||||
|
||||
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]
|
||||
|
||||
p1, success = optimize.leastsq(errfunc,p0[:],
|
||||
args = (age,power))
|
||||
|
||||
expo_vals = fitfunc(p1, age2)
|
||||
expo_vals = 0.5*(np.abs(expo_vals)+expo_vals)
|
||||
|
||||
|
||||
source = ColumnDataSource(
|
||||
data = dict(
|
||||
age = age,
|
||||
power = power,
|
||||
age2 = age2,
|
||||
poly_vals = poly_vals,
|
||||
expo_vals = expo_vals,
|
||||
season = season,
|
||||
name=name,
|
||||
)
|
||||
@@ -1097,9 +1112,10 @@ def interactive_agegroup_plot(df):
|
||||
plot = Figure(tools=TOOLS,plot_width=900)
|
||||
plot.circle('age','power',source=source,fill_color='red',size=15,
|
||||
legend='World Record')
|
||||
plot.line(age2,poly_vals)
|
||||
|
||||
plot.line(age2,expo_vals)
|
||||
plot.xaxis.axis_label = "Age"
|
||||
plot.yaxis.axis_label = "Concept2 2k power"
|
||||
plot.yaxis.axis_label = "Concept2 power"
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from utils import lbstoN
|
||||
import numpy as np
|
||||
from models import C2WorldClassAgePerformance
|
||||
import pandas as pd
|
||||
from scipy import optimize
|
||||
|
||||
rowingmetrics = (
|
||||
('time',{
|
||||
@@ -347,9 +348,20 @@ def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
||||
ages = df['age']
|
||||
powers = df['power']
|
||||
|
||||
poly_coefficients = np.polyfit(ages,powers,6)
|
||||
#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
|
||||
|
||||
power = np.polyval(poly_coefficients,age)
|
||||
p0 = [700,120,700,10,100,100]
|
||||
|
||||
p1, success = optimize.leastsq(errfunc,p0[:],
|
||||
args = (ages,powers))
|
||||
|
||||
power = fitfunc(p1, float(age))
|
||||
|
||||
#power = np.polyval(poly_coefficients,age)
|
||||
|
||||
power = 0.5*(np.abs(power)+power)
|
||||
else:
|
||||
power = 0
|
||||
|
||||
|
||||
@@ -11312,7 +11312,9 @@ def agegrouprecordview(request,sex='male',weightcategory='hwt',
|
||||
)
|
||||
|
||||
|
||||
script,div = interactive_agegroup_plot(df)
|
||||
script,div = interactive_agegroup_plot(df,sex=sex,distance=distance,
|
||||
duration=duration,
|
||||
weightcategory=weightcategory)
|
||||
|
||||
return render(request, 'agegroupchart.html',
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user