diff --git a/rowers/views.py b/rowers/views.py index 8e15110d..1ac5a4ab 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -138,6 +138,8 @@ from scipy.special import lambertw from dataprep import timedeltaconv +from scipy.interpolate import griddata + LOCALTIMEZONE = tz('Etc/UTC') USER_LANGUAGE = 'en-US' @@ -2873,15 +2875,10 @@ def otwrankings_view(request,theuser=0, columns = ['power','workoutid','time'] df = dataprep.getsmallrowdata_db(columns,ids=theids) - dfgrouped = df.groupby(['workoutid']) - for id in theids: - tt = df['time'] - + thesecs = [] + for w in theworkouts: - - thedistances.append(w.distance) - - timesecs = 3600*workouts[0].duration.hour + 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 @@ -2889,11 +2886,51 @@ def otwrankings_view(request,theuser=0, thesecs.append(timesecs) + maxt = pd.Series(thesecs).max() - thesecs = np.array(thesecs) + maxlog10 = np.log10(maxt) + logarr = np.arange(100)*maxlog10/100. + logarr = 10.**(logarr) - theavpower = 2.8*(thevelos**3) + delta = [] + cpvalue = [] + + dfgrouped = df.groupby(['workoutid']) + 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) + cpvalues = griddata(dt,cpw,logarr,method='linear',fill_value=0) + + 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') + + + powerdf = pd.DataFrame({ + 'Delta':delta, + 'CP':cpvalue, + }) + + powerdf.sort_value(['Delta','CP'],ascending=[1,0] + powerdf.drop_duplicates(subset='Delta',keep='first') + # create interactive plot if len(thedistances) !=0 :