Private
Public Access
1
0

Flex Chart updated

This commit is contained in:
sanderroosendaal
2016-11-02 17:41:54 +01:00
parent 030e2df146
commit a14ab53415

View File

@@ -577,7 +577,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
if rowdata != 0: if rowdata != 0:
therows.append(rowdata.df) therows.append(rowdata.df)
thedata = pd.concat(therows) datadf = pd.concat(therows)
axlabels = { axlabels = {
@@ -623,7 +623,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
} }
datadf = dataprep.dataprep(thedata) datadf = dataprep.dataprep(datadf)
if yparam1 != 'pace' and yparam1 != 'time': if yparam1 != 'pace' and yparam1 != 'time':
datadf = datadf[datadf[yparam1] > 0] datadf = datadf[datadf[yparam1] > 0]
@@ -911,19 +911,6 @@ def interactive_flex_chart2(id=0,promember=0,
plottype='line', plottype='line',
workstrokesonly=False): workstrokesonly=False):
csvcolumns = {
'time': 'TimeStamp (sec)',
'distance': 'cum_dist',
'hr': ' HRCur (bpm)',
'spm': ' Cadence (stokes/min)',
'pace': ' Stroke500mPace (sec/500m)',
'power': ' Power (watts)',
'averageforce': ' AverageDriveForce (lbs)',
'drivelength': ' DriveLength (meters)',
'peakforce': ' PeakDriveForce (lbs)',
'driveenergy': 'driveenergy',
'drivespeed': 'drivespeed',
}
axlabels = { axlabels = {
'time': 'Time', 'time': 'Time',
@@ -978,64 +965,41 @@ def interactive_flex_chart2(id=0,promember=0,
except KeyError: except KeyError:
pass pass
rowdata = dataprep.dataprep(rowdata.df)
rowdata.df['driveenergy'] = rowdata.df[' DriveLength (meters)']*rowdata.df[' AverageDriveForce (lbs)']*4.44822
spm = rowdata.df.ix[:,csvcolumns['spm']]
hr = rowdata.df.ix[:,csvcolumns['hr']]
f = rowdata.df['TimeStamp (sec)'].diff().mean()
windowsize = 2*(int(10./(f)))+1
if windowsize <= 3:
windowsize = 5
if windowsize > 3:
spm = savgol_filter(spm,windowsize,3)
hr = savgol_filter(hr,windowsize,3)
rowdata.df[' Cadence (stokes/min)'] = spm
rowdata.df[' HRCur (bpm)'] = hr
drivelength = rowdata.df[' DriveLength (meters)']
if windowsize > 3:
drivelength = savgol_filter(drivelength,windowsize,3)
rowdata.df[' DriveLength (meters)'] = drivelength
rowdata.df['drivespeed'] = drivelength/rowdata.df[' DriveTime (ms)']*1.0e3
# get user # get user
# u = User.objects.get(id=row.user.id) # u = User.objects.get(id=row.user.id)
x1 = rowdata.df.ix[:,csvcolumns[xparam]] rowdata['x1'] = rowdata.ix[:,xparam]
y1 = rowdata.df.ix[:,csvcolumns[yparam1]]
rowdata['y1'] = rowdata.ix[:,yparam1]
tseconds = rowdata.ix[:,'timesecs']
if yparam2 != 'None': if yparam2 != 'None':
y2 = rowdata.df.ix[:,csvcolumns[yparam2]] rowdata['y2'] = rowdata.ix[:,yparam2]
else: else:
y2 = y1 rowdata['y2'] = rowdata['y1']
if xparam=='time': if xparam=='time':
xaxmax = 1.0e3*x1.max() xaxmax = 1.0e3*tseconds.max()
xaxmin = 1.0e3*x1.min() xaxmin = 1.0e3*tseconds.min()
x1 = x1.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
elif xparam=='distance': elif xparam=='distance':
xaxmax = x1.max() xaxmax = rowdata['x1'].max()
xaxmin = x1.min() xaxmin = rowdata['x1'].min()
else: else:
xaxmax = yaxmaxima[xparam] xaxmax = yaxmaxima[xparam]
xaxmin = yaxminima[xparam] xaxmin = yaxminima[xparam]
# average values # average values
if xparam != 'time': if xparam != 'time':
x1mean = x1.mean() x1mean = rowdata['x1'].mean()
else: else:
x1mean = 0 x1mean = 0
y1mean = y1.mean() y1mean = rowdata['y1'].mean()
y2mean = y2.mean() y2mean = rowdata['y2'].mean()
if xparam != 'time': if xparam != 'time':
xvals = xaxmin+np.arange(100)*(xaxmax-xaxmin)/100. xvals = xaxmin+np.arange(100)*(xaxmax-xaxmin)/100.
@@ -1045,7 +1009,7 @@ def interactive_flex_chart2(id=0,promember=0,
# constant power plot # constant power plot
if yparam1 == 'driveenergy': if yparam1 == 'driveenergy':
if xparam == 'spm': if xparam == 'spm':
yconstantpower = y1.mean()*x1.mean()/xvals yconstantpower = rowdata['y1'].mean()*rowdata['x1'].mean()/xvals
x_axis_type = 'linear' x_axis_type = 'linear'
y_axis_type = 'linear' y_axis_type = 'linear'
@@ -1054,66 +1018,17 @@ def interactive_flex_chart2(id=0,promember=0,
if yparam1 == 'pace': if yparam1 == 'pace':
y_axis_type = 'datetime' y_axis_type = 'datetime'
y1mean = 1.0e3*y1mean y1mean = rowdata.ix[:,'pseconds'].mean()
y1 = y1.fillna(method='ffill').fillna(method='ffill').apply(lambda x: timedeltaconv(x))
time = rowdata.df.ix[:,csvcolumns['time']]
time = time-time[time.index[0]]
hr = rowdata.df.ix[:,csvcolumns['hr']]
pace = rowdata.df.ix[:,csvcolumns['pace']]
distance = rowdata.df.ix[:,csvcolumns['distance']]
power = rowdata.df.ix[:,csvcolumns['power']]
# prepare data # prepare data
source = ColumnDataSource( source = ColumnDataSource(
data = dict( rowdata
x1=x1,
y1=y1,
y2=y2,
time=niceformat(
time.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
),
pace=nicepaceformat(
pace.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
),
hr = hr,
spm = spm,
spmc=np.rint(10*spm)/10.,
distance=distance,
power=power,
y1mean=[y1mean,y1mean],
y2mean=[y2mean,y2mean],
x1mean=[x1mean,x1mean],
)
) )
# second source for filtering # second source for filtering
source2 = ColumnDataSource( source2 = ColumnDataSource(
data = dict( rowdata.copy()
x1=x1,
y1=y1,
y2=y2,
time=niceformat(
time.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
),
pace=nicepaceformat(
pace.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
),
hr = hr,
spm = spm,
spmc=np.rint(10*spm)/10.,
distance=distance,
power=power,
y1mean=[y1mean,y1mean],
y2mean=[y2mean,y2mean],
x1mean=[x1mean,x1mean],
)
) )
# Add hover to this comma-separated string and see what changes # Add hover to this comma-separated string and see what changes
@@ -1220,7 +1135,7 @@ def interactive_flex_chart2(id=0,promember=0,
('Distance','@distance'), ('Distance','@distance'),
('Pace','@pace'), ('Pace','@pace'),
('HR','@hr'), ('HR','@hr'),
('SPM','@spmc{1.1}'), ('SPM','@spm{1.1}'),
('Power','@power{int}'), ('Power','@power{int}'),
]) ])
@@ -1239,7 +1154,6 @@ def interactive_flex_chart2(id=0,promember=0,
var time1 = data['time'] var time1 = data['time']
var pace1 = data['pace'] var pace1 = data['pace']
var hr1 = data['hr'] var hr1 = data['hr']
var spmc1 = data['spmc']
var distance1 = data['distance'] var distance1 = data['distance']
var power1 = data['power'] var power1 = data['power']
@@ -1258,7 +1172,6 @@ def interactive_flex_chart2(id=0,promember=0,
data2['time'] = [] data2['time'] = []
data2['pace'] = [] data2['pace'] = []
data2['hr'] = [] data2['hr'] = []
data2['spmc'] = []
data2['distance'] = [] data2['distance'] = []
data2['power'] = [] data2['power'] = []
data2['x1mean'] = [] data2['x1mean'] = []
@@ -1278,7 +1191,6 @@ def interactive_flex_chart2(id=0,promember=0,
data2['time'].push(time1[i]) data2['time'].push(time1[i])
data2['pace'].push(pace1[i]) data2['pace'].push(pace1[i])
data2['hr'].push(hr1[i]) data2['hr'].push(hr1[i])
data2['spmc'].push(spmc1[i])
data2['distance'].push(distance1[i]) data2['distance'].push(distance1[i])
data2['power'].push(power1[i]) data2['power'].push(power1[i])
@@ -1313,7 +1225,7 @@ def interactive_flex_chart2(id=0,promember=0,
title="Max SPM",callback=callback) title="Max SPM",callback=callback)
callback.args["maxspm"] = slider_spm_max callback.args["maxspm"] = slider_spm_max
distmax = 100+100*int(distance.max()/100.) distmax = 100+100*int(rowdata['distance'].max()/100.)
slider_dist_min = Slider(start=0,end=distmax,value=0,step=1, slider_dist_min = Slider(start=0,end=distmax,value=0,step=1,
title="Min Distance",callback=callback) title="Min Distance",callback=callback)