From d4a9060c368e4b487ca3186c12dfb024d5afc8d1 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 8 Jun 2017 16:53:30 -0700 Subject: [PATCH] updated OTW CP plot --- rowers/interactiveplots.py | 12 ++++++++---- rowers/views.py | 36 +++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 6f6a5c4a..3e782204 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -645,10 +645,14 @@ def interactive_otwcpchart(powerdf,promember=0): # message = "CP model fit didn't give correct results" + deltas = fitt.apply(lambda x: timedeltaconv(x)) + ftime = niceformat(deltas) + sourcecomplex = ColumnDataSource( data = dict( - power = fitpower, - duration = fitt + CP = fitpower, + duration = fitt, + ftime = ftime ) ) @@ -671,7 +675,7 @@ def interactive_otwcpchart(powerdf,promember=0): y_range_name = "watermark", ) - plot.line('Delta','CP',source=source,color='red',line_width=5, + plot.circle('Delta','CP',source=source,fill_color='red',size=15, legend='Power Data') plot.xaxis.axis_label = "Duration (seconds)" plot.yaxis.axis_label = "Power (W)" @@ -689,7 +693,7 @@ def interactive_otwcpchart(powerdf,promember=0): hover.mode = 'mouse' - plot.line('duration','power',source=sourcecomplex,legend="CP Model", + plot.line('duration','CP',source=sourcecomplex,legend="CP Model", color='green') script, div = components(plot) diff --git a/rowers/views.py b/rowers/views.py index 44a06fd7..21d06331 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -2903,9 +2903,9 @@ def otwrankings_view(request,theuser=0, else: maxt = 1000. - + maxlog10 = np.log10(maxt) - logarr = np.arange(500)*maxlog10/500. + logarr = np.arange(100)*maxlog10/100. logarr = [int(10.**(la)) for la in logarr] logarr = pd.Series(logarr) logarr.drop_duplicates(keep='first',inplace=True) @@ -2920,8 +2920,9 @@ def otwrankings_view(request,theuser=0, dfgrouped = df.groupby(['workoutid']) for id,group in dfgrouped: - tt = group['time'] - ww = group['power'] + tt = group['time'].copy() + ww = group['power'].copy() + try: avgpower[id] = int(ww.mean()) except ValueError: @@ -2931,19 +2932,20 @@ def otwrankings_view(request,theuser=0, 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] - if not np.isnan(deltat) and not np.isnan(wmax): - dt.append(deltat) - cpw.append(wmax) - except KeyError: - pass + w_roll = ww.rolling(i+2).mean().dropna() + if len(w_roll): + # 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] + if not np.isnan(deltat) and not np.isnan(wmax): + dt.append(deltat) + cpw.append(wmax) + except KeyError: + pass dt = pd.Series(dt)