Flex Chart updated
This commit is contained in:
@@ -577,7 +577,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
if rowdata != 0:
|
||||
therows.append(rowdata.df)
|
||||
|
||||
thedata = pd.concat(therows)
|
||||
datadf = pd.concat(therows)
|
||||
|
||||
|
||||
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':
|
||||
datadf = datadf[datadf[yparam1] > 0]
|
||||
@@ -911,19 +911,6 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
plottype='line',
|
||||
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 = {
|
||||
'time': 'Time',
|
||||
@@ -978,64 +965,41 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
except KeyError:
|
||||
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
|
||||
# u = User.objects.get(id=row.user.id)
|
||||
|
||||
x1 = rowdata.df.ix[:,csvcolumns[xparam]]
|
||||
|
||||
y1 = rowdata.df.ix[:,csvcolumns[yparam1]]
|
||||
rowdata['x1'] = rowdata.ix[:,xparam]
|
||||
|
||||
rowdata['y1'] = rowdata.ix[:,yparam1]
|
||||
|
||||
tseconds = rowdata.ix[:,'timesecs']
|
||||
|
||||
if yparam2 != 'None':
|
||||
y2 = rowdata.df.ix[:,csvcolumns[yparam2]]
|
||||
rowdata['y2'] = rowdata.ix[:,yparam2]
|
||||
else:
|
||||
y2 = y1
|
||||
rowdata['y2'] = rowdata['y1']
|
||||
|
||||
if xparam=='time':
|
||||
xaxmax = 1.0e3*x1.max()
|
||||
xaxmin = 1.0e3*x1.min()
|
||||
x1 = x1.fillna(method='ffill').apply(lambda x: timedeltaconv(x))
|
||||
xaxmax = 1.0e3*tseconds.max()
|
||||
xaxmin = 1.0e3*tseconds.min()
|
||||
elif xparam=='distance':
|
||||
xaxmax = x1.max()
|
||||
xaxmin = x1.min()
|
||||
xaxmax = rowdata['x1'].max()
|
||||
xaxmin = rowdata['x1'].min()
|
||||
else:
|
||||
xaxmax = yaxmaxima[xparam]
|
||||
xaxmin = yaxminima[xparam]
|
||||
|
||||
# average values
|
||||
if xparam != 'time':
|
||||
x1mean = x1.mean()
|
||||
x1mean = rowdata['x1'].mean()
|
||||
else:
|
||||
x1mean = 0
|
||||
|
||||
y1mean = y1.mean()
|
||||
y2mean = y2.mean()
|
||||
y1mean = rowdata['y1'].mean()
|
||||
y2mean = rowdata['y2'].mean()
|
||||
|
||||
if xparam != 'time':
|
||||
xvals = xaxmin+np.arange(100)*(xaxmax-xaxmin)/100.
|
||||
@@ -1045,7 +1009,7 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
# constant power plot
|
||||
if yparam1 == 'driveenergy':
|
||||
if xparam == 'spm':
|
||||
yconstantpower = y1.mean()*x1.mean()/xvals
|
||||
yconstantpower = rowdata['y1'].mean()*rowdata['x1'].mean()/xvals
|
||||
|
||||
x_axis_type = 'linear'
|
||||
y_axis_type = 'linear'
|
||||
@@ -1054,66 +1018,17 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
|
||||
if yparam1 == 'pace':
|
||||
y_axis_type = 'datetime'
|
||||
y1mean = 1.0e3*y1mean
|
||||
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']]
|
||||
y1mean = rowdata.ix[:,'pseconds'].mean()
|
||||
|
||||
|
||||
# prepare data
|
||||
source = ColumnDataSource(
|
||||
data = dict(
|
||||
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],
|
||||
)
|
||||
rowdata
|
||||
)
|
||||
|
||||
# second source for filtering
|
||||
source2 = ColumnDataSource(
|
||||
data = dict(
|
||||
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],
|
||||
)
|
||||
rowdata.copy()
|
||||
)
|
||||
|
||||
# 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'),
|
||||
('Pace','@pace'),
|
||||
('HR','@hr'),
|
||||
('SPM','@spmc{1.1}'),
|
||||
('SPM','@spm{1.1}'),
|
||||
('Power','@power{int}'),
|
||||
])
|
||||
|
||||
@@ -1239,7 +1154,6 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
var time1 = data['time']
|
||||
var pace1 = data['pace']
|
||||
var hr1 = data['hr']
|
||||
var spmc1 = data['spmc']
|
||||
var distance1 = data['distance']
|
||||
var power1 = data['power']
|
||||
|
||||
@@ -1258,7 +1172,6 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
data2['time'] = []
|
||||
data2['pace'] = []
|
||||
data2['hr'] = []
|
||||
data2['spmc'] = []
|
||||
data2['distance'] = []
|
||||
data2['power'] = []
|
||||
data2['x1mean'] = []
|
||||
@@ -1278,7 +1191,6 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
data2['time'].push(time1[i])
|
||||
data2['pace'].push(pace1[i])
|
||||
data2['hr'].push(hr1[i])
|
||||
data2['spmc'].push(spmc1[i])
|
||||
data2['distance'].push(distance1[i])
|
||||
data2['power'].push(power1[i])
|
||||
|
||||
@@ -1313,7 +1225,7 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
title="Max SPM",callback=callback)
|
||||
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,
|
||||
title="Min Distance",callback=callback)
|
||||
|
||||
Reference in New Issue
Block a user