diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 2da4538f..5d841ba9 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -123,8 +123,10 @@ def dataprep(rowdatadf): data = DataFrame( dict( time = t2, + timesecs = t, hr = hr, pace = p2, + pseconds=p, spm = spm, cumdist = cumdist, ftime = niceformat(t2), diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 8de6985c..9797be53 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -624,53 +624,60 @@ def interactive_cum_flex_chart(theworkouts,promember=0, datadf = dataprep.dataprep(thedata) - # thedata['driveenergy'] = thedata[' DriveLength (meters)']*thedata[' AverageDriveForce (lbs)']*4.44822 - - # throw out zeros from dataframe - #thedata = thedata[thedata[csvcolumns[yparam1]] > 0] - #thedata = thedata[thedata[csvcolumns[xparam]] > 0] - datadf = datadf[datadf[yparam1] > 0] - datadf = datadf[datadf[xparam] > 0] + if yparam1 != 'pace' and yparam1 != 'time': + datadf = datadf[datadf[yparam1] > 0] + elif yparam1 == 'time': + datadf = datadf[datadf['timesecs'] > 0] + else: + datadf = datadf[datadf['pseconds']>0] + + if xparam != 'time' and xparam != 'pace': + datadf = datadf[datadf[xparam] > 0] + elif xparam == 'time': + datadf = datadf[datadf['timesecs']>0] + else: + datadf = datadf[datadf['pseconds']>0] + if yparam2 != 'None': - #thedata = thedata[thedata[csvcolumns[yparam2]] > 0] - datadf = datadf[thedata[yparam2] > 0] + datadf = datadf[datadf[yparam2] > 0] # check if dataframe not empty if datadf.empty: return ['','
No non-zero data in selection
','',''] - x1 = datadf.ix[:,xparam] + datadf['x1'] = datadf.ix[:,xparam] + tseconds = datadf.ix[:,'timesecs'] + - y1 = datadf.ix[:,yparam1] + datadf['y1'] = datadf.ix[:,yparam1] if yparam2 != 'None': - y2 = datadf.ix[:,yparam2] + datadf['y2'] = datadf.ix[:,yparam2] else: - y2 = y1 + datadf['y2'] = datadf['y1'] if xparam=='time': - xaxmax = x1.max() - xaxmin = x1.min() + xaxmax = tseconds.max() + xaxmin = tseconds.min() xaxmax = 1.0e3*xaxmax xaxmin = 1.0e3*xaxmin - x1 = x1.fillna(method='ffill').apply(lambda x: timedeltaconv(x)) elif xparam=='distance': - xaxmax = x1.max() - xaxmin = x1.min() + xaxmax = datadf['x1'].max() + xaxmin = datadf['x1'].min() else: xaxmax = yaxmaxima[xparam] xaxmin = yaxminima[xparam] # average values if xparam != 'time': - x1mean = x1.mean() + x1mean = datadf['x1'].mean() else: x1mean = 0 - y1mean = y1.mean() - y2mean = y2.mean() + y1mean = datadf['y1'].mean() + y2mean = datadf['y2'].mean() if xparam != 'time': xvals = pd.Series(xaxmin+np.arange(100)*(xaxmax-xaxmin)/100.) @@ -684,18 +691,16 @@ def interactive_cum_flex_chart(theworkouts,promember=0, if yparam1 == 'pace': y_axis_type = 'datetime' - y1 = y1.fillna(method='ffill').apply(lambda x: timedeltaconv(x)) + y1mean = datadf.ix[:,'pseconds'].mean() - time = datadf.ix[:,'time'] - hr = datadf.ix[:,'hr'] - pace = datadf.ix[:,'pace'] - distance = datadf.ix[:,'distance'] - power = datadf.ix[:,'power'] - ftime = datadf.ix[:,'ftime'] - fpace = datadf.ix[:,'fpace'] - spm = datadf.ix[:,'spm'] + source = ColumnDataSource( + datadf + ) + source2 = ColumnDataSource( + datadf.copy() + ) # Add hover to this comma-separated string and see what changes if (promember==1): @@ -720,37 +725,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0, plot.add_layout(y1means) - source = ColumnDataSource( - data = dict( - x1=x1, - y1=y1, - y2=y2, - time=ftime, - pace=fpace, - hr = hr, - spm = spm, - distance=distance, - power=power, - ) - ) - - source2 = ColumnDataSource( - data = dict( - x1=x1, - y1=y1, - y2=y2, - time=ftime, - pace=fpace, - hr = hr, - spm = spm, - distance=distance, - power=power, - ) - ) - - - # plot.circle('x1','y1',source=source,legend=yparam1,size=3) plot.circle('x1','y1',source=source2,fill_alpha=0.3,line_color=None, legend=yparamname1, ) @@ -900,7 +875,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0, title="Max SPM",callback=callback) callback.args["maxspm"] = slider_spm_max - distmax = 100+100*int(distance.max()/100.) + distmax = 100+100*int(datadf['distance'].max()/100.) slider_dist_min = Slider(start=0,end=distmax,value=0,step=1, title="Min Distance",callback=callback) @@ -1070,7 +1045,7 @@ def interactive_flex_chart2(id=0,promember=0, # constant power plot if yparam1 == 'driveenergy': if xparam == 'spm': - yconstantpower = y1.median()*x1.median()/xvals + yconstantpower = y1.mean()*x1.mean()/xvals x_axis_type = 'linear' y_axis_type = 'linear' diff --git a/rowers/tests.py b/rowers/tests.py index 01d0da49..e0e5a797 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -793,10 +793,6 @@ class subroutinetests(TestCase): duration="0:55:00",distance=8000, csvfilename=filename) - def test_seconds(self): - seconds = [30.3,75.8,3900.3,104670.2] - res = iplots.get_datetimes(seconds) - def c2stuff(self): data = c2stuff.createc2workoutdata(self.w) diff --git a/rowers/views.py b/rowers/views.py index 2478d4f3..8de43357 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1204,8 +1204,8 @@ def cum_flex(request,theuser=0, xparam='spm', yparam1='power', yparam2='None', - startdate=timezone.now()-datetime.timedelta(days=30), - enddate=timezone.now(), + startdate=timezone.now()-datetime.timedelta(days=10), + enddate=timezone.now()+datetime.timedelta(days=1), deltadays=-1, startdatestring="", enddatestring=""):