Private
Public Access
1
0

got to point where chart is generated (L2936)

This commit is contained in:
Sander Roosendaal
2017-06-05 15:54:25 +02:00
parent 5e0d99b720
commit 0449ff432f
2 changed files with 42 additions and 81 deletions

View File

@@ -2856,13 +2856,6 @@ def otwrankings_view(request,theuser=0,
thedistances = []
theworkouts = []
thesecs = []
rankingdistances.sort()
rankingdurations.sort()
theworkouts = Workout.objects.filter(user=r,rankingpiece=True,
workouttype='water',
@@ -2878,10 +2871,10 @@ def otwrankings_view(request,theuser=0,
thesecs = []
for w in theworkouts:
timesecs = 3600*workouts[0].duration.hour
timesecs += 60*workouts[0].duration.minute
timesecs += workouts[0].duration.second
timesecs += 1.e-5*workouts[0].duration.microsecond
timesecs = 3600*w.duration.hour
timesecs += 60*w.duration.minute
timesecs += w.duration.second
timesecs += 1.e-5*w.duration.microsecond
thesecs.append(timesecs)
@@ -2890,7 +2883,10 @@ def otwrankings_view(request,theuser=0,
maxlog10 = np.log10(maxt)
logarr = np.arange(100)*maxlog10/100.
logarr = 10.**(logarr)
logarr = [int(10.**(la)) for la in logarr]
logarr = pd.Series(logarr)
logarr.drop_duplicates(keep='first',inplace=True)
logarr = logarr.values
delta = []
cpvalue = []
@@ -2899,25 +2895,34 @@ def otwrankings_view(request,theuser=0,
for id,group in dfgrouped:
tt = group['time']
ww = group['power']
length = len(ww)
dt = []
cpw = []
for i in range(length):
w_roll = ww.rolling(i)
# now goes with # data points - should be fixed seconds
t_0 = tt.ix[w_roll.idxmax(axis=1)]
t_1 = tt.ix[w_roll.idxmax(axis=1)-i]
deltat = t_1-t_0
wmax = w_roll.ix[w_roll.idxmax(axis=1)]
dt.append(deltat)
cpw.append(wmax)
if not np.isnan(ww.mean()):
length = len(ww)
dt = []
cpw = []
for i in range(length-2):
w_roll = ww.rolling(i+2,min_periods=2).mean()
# now goes with # data points - should be fixed seconds
indexmax = w_roll.idxmax(axis=1)
try:
t_0 = tt.ix[indexmax]
t_1 = tt.ix[indexmax-i-2]
deltat = 1.0e-3*(t_0-t_1)
wmax = w_roll.ix[indexmax]
dt.append(deltat)
cpw.append(wmax)
except KeyError:
pass
cpvalues = griddata(dt,cpw,logarr,method='linear',fill_value=0)
dt = pd.Series(dt)
cpw = pd.Series(cpw)
cpvalues = griddata(dt.values,
cpw.values,
logarr,method='linear',fill_value=0)
for cpv in cpvalues:
cpvalue.append(cpv)
for d in logarr:
delta.append(d)
for cpv in cpvalues:
cpvalue.append(cpv)
for d in logarr:
delta.append(d)
dt = pd.Series(delta,name='Delta')
cpvalue = pd.Series(cpvalue,name='CP')
@@ -2928,9 +2933,9 @@ def otwrankings_view(request,theuser=0,
'CP':cpvalue,
})
powerdf.sort_value(['Delta','CP'],ascending=[1,0]
powerdf.sort_values(['Delta','CP'],ascending=[1,0])
powerdf.drop_duplicates(subset='Delta',keep='first')
# create interactive plot
if len(thedistances) !=0 :
@@ -2966,61 +2971,11 @@ def otwrankings_view(request,theuser=0,
else:
form = PredictedPieceForm()
rankingdistances.sort()
rankingdurations.sort()
predictions = []
cpredictions = []
for rankingdistance in rankingdistances:
# Paul's model
p = paulslope*np.log10(rankingdistance)+paulintercept
velo = 500./p
t = rankingdistance/velo
pwr = 2.8*(velo**3)
a = {'distance':rankingdistance,
'duration':timedeltaconv(t),
'pace':timedeltaconv(p),
'power':int(pwr)}
predictions.append(a)
# CP model -
pwr2 = p1[0]/(1+t/p1[2])
pwr2 += p1[1]/(1+t/p1[3])
if pwr2 <= 0:
pwr2 = 50.
velo2 = (pwr2/2.8)**(1./3.)
if np.isnan(velo2) or velo2 <= 0:
velo2 = 1.0
t2 = rankingdistance/velo2
pwr3 = p1[0]/(1+t2/p1[2])
pwr3 += p1[1]/(1+t2/p1[3])
if pwr3 <= 0:
pwr3 = 50.
velo3 = (pwr3/2.8)**(1./3.)
if np.isnan(velo3) or velo3 <= 0:
velo3 = 1.0
t3 = rankingdistance/velo3
p3 = 500./velo3
a = {'distance':rankingdistance,
'duration':timedeltaconv(t3),
'pace':timedeltaconv(p3),
'power':int(pwr3)}
cpredictions.append(a)
for rankingduration in rankingdurations:
t = 3600.*rankingduration.hour