Merge branch 'feature/restapi' into develop
This commit is contained in:
@@ -70,14 +70,14 @@ from rowers.dataprep import timedeltaconv
|
||||
def interactive_histoall(theworkouts):
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair'
|
||||
|
||||
therows = []
|
||||
for workout in theworkouts:
|
||||
f1 = workout.csvfilename
|
||||
rowdata = rdata(f1)
|
||||
if rowdata != 0:
|
||||
therows.append(rowdata)
|
||||
|
||||
histopwr = histodata(therows)
|
||||
ids = [w.id for w in theworkouts]
|
||||
|
||||
rowdata = dataprep.getsmallrowdata_db(['power'],ids=ids)
|
||||
|
||||
histopwr = rowdata['power'].values
|
||||
if len(histopwr) == 0:
|
||||
return "","CSV file not found","",""
|
||||
|
||||
# throw out nans
|
||||
histopwr = histopwr[~np.isinf(histopwr)]
|
||||
histopwr = histopwr[histopwr > 25]
|
||||
@@ -496,18 +496,15 @@ def interactive_chart(id=0,promember=0):
|
||||
else:
|
||||
TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair'
|
||||
|
||||
rowdata,row = dataprep.getrowdata(id=id)
|
||||
if rowdata == 0:
|
||||
|
||||
datadf,row = dataprep.getrowdata_db(id=id)
|
||||
if datadf.empty:
|
||||
return "","CSV Data File Not Found"
|
||||
|
||||
datadf = dataprep.dataprep(rowdata.df)
|
||||
|
||||
source = ColumnDataSource(
|
||||
datadf
|
||||
)
|
||||
|
||||
|
||||
|
||||
plot = Figure(x_axis_type="datetime",y_axis_type="datetime",
|
||||
plot_width=400,
|
||||
plot_height=400,
|
||||
@@ -554,10 +551,10 @@ def interactive_chart(id=0,promember=0):
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
plot.extra_y_ranges = {"hr": Range1d(start=100,end=200)}
|
||||
plot.extra_y_ranges = {"hrax": Range1d(start=100,end=200)}
|
||||
plot.line('time','hr',source=source,color="red",
|
||||
y_range_name="hr", legend="Heart Rate")
|
||||
plot.add_layout(LinearAxis(y_range_name="hr",axis_label="HR"),'right')
|
||||
y_range_name="hrax", legend="Heart Rate")
|
||||
plot.add_layout(LinearAxis(y_range_name="hrax",axis_label="HR"),'right')
|
||||
|
||||
plot.legend.location = "bottom_right"
|
||||
|
||||
@@ -570,8 +567,10 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
|
||||
yparam1='power',
|
||||
yparam2='spm'):
|
||||
|
||||
datadf = dataprep.smalldataprep(theworkouts,xparam,yparam1,yparam2)
|
||||
|
||||
# datadf = dataprep.smalldataprep(theworkouts,xparam,yparam1,yparam2)
|
||||
ids = [w.id for w in theworkouts]
|
||||
datadf = dataprep.getsmallrowdata_db([xparam,yparam1,yparam2],ids=ids)
|
||||
|
||||
axlabels = {
|
||||
'time': 'Time',
|
||||
'distance': 'Distance (m)',
|
||||
@@ -666,6 +665,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
|
||||
else:
|
||||
datadf['yname2'] = yparam1
|
||||
|
||||
|
||||
source = ColumnDataSource(
|
||||
datadf
|
||||
)
|
||||
@@ -678,7 +678,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
|
||||
if (promember==1):
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,resize,crosshair'
|
||||
else:
|
||||
TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair'
|
||||
TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,crosshair'
|
||||
|
||||
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
|
||||
tools=TOOLS,
|
||||
@@ -862,384 +862,6 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
|
||||
return [script,div,js_resources,css_resources]
|
||||
|
||||
|
||||
def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
xparam='spm',
|
||||
yparam1='power',
|
||||
yparam2='hr',
|
||||
):
|
||||
|
||||
|
||||
therows = []
|
||||
for workout in theworkouts:
|
||||
f1 = workout.csvfilename
|
||||
rowdata = rdata(f1)
|
||||
if rowdata != 0:
|
||||
therows.append(rowdata.df)
|
||||
|
||||
datadf = pd.concat(therows)
|
||||
|
||||
axlabels = {
|
||||
'time': 'Time',
|
||||
'distance': 'Distance (m)',
|
||||
'hr': 'Heart Rate (bpm)',
|
||||
'spm': 'Stroke Rate (spm)',
|
||||
'pace': 'Pace (/500m)',
|
||||
'power': 'Power (Watt)',
|
||||
'averageforce': 'Average Drive Force (lbs)',
|
||||
'drivelength': 'Drive Length (m)',
|
||||
'peakforce': 'Peak Drive Force (lbs)',
|
||||
'forceratio': 'Average/Peak Drive Force Ratio',
|
||||
'driveenergy': 'Work per Stroke (J)',
|
||||
'drivespeed': 'Drive Speed (m/s)',
|
||||
'None': '',
|
||||
}
|
||||
|
||||
yparamname1 = axlabels[yparam1]
|
||||
yparamname2 = axlabels[yparam2]
|
||||
|
||||
yaxminima = {
|
||||
'hr':100,
|
||||
'spm':15,
|
||||
'pace': 1.0e3*210,
|
||||
'power': 0,
|
||||
'averageforce': 0,
|
||||
'peakforce': 0,
|
||||
'forceratio':0,
|
||||
'drivelength':0.5,
|
||||
'driveenergy': 0,
|
||||
'drivespeed': 0,
|
||||
}
|
||||
|
||||
yaxmaxima = {
|
||||
'hr':200,
|
||||
'spm':45,
|
||||
'pace':1.0e3*90,
|
||||
'power': 600,
|
||||
'averageforce':200,
|
||||
'peakforce':400,
|
||||
'forceratio':1,
|
||||
'drivelength':2.0,
|
||||
'driveenergy': 1000,
|
||||
'drivespeed':4,
|
||||
}
|
||||
|
||||
|
||||
datadf = dataprep.dataprep(datadf)
|
||||
|
||||
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':
|
||||
datadf = datadf[datadf[yparam2] > 0]
|
||||
|
||||
# check if dataframe not empty
|
||||
if datadf.empty:
|
||||
return ['','<p>No non-zero data in selection</p>','','']
|
||||
|
||||
|
||||
datadf['x1'] = datadf.ix[:,xparam]
|
||||
tseconds = datadf.ix[:,'timesecs']
|
||||
|
||||
|
||||
datadf['y1'] = datadf.ix[:,yparam1]
|
||||
if yparam2 != 'None':
|
||||
datadf['y2'] = datadf.ix[:,yparam2]
|
||||
else:
|
||||
datadf['y2'] = datadf['y1']
|
||||
|
||||
|
||||
if xparam=='time':
|
||||
xaxmax = tseconds.max()
|
||||
xaxmin = tseconds.min()
|
||||
xaxmax = 1.0e3*xaxmax
|
||||
xaxmin = 1.0e3*xaxmin
|
||||
elif xparam=='distance':
|
||||
xaxmax = datadf['x1'].max()
|
||||
xaxmin = datadf['x1'].min()
|
||||
else:
|
||||
xaxmax = yaxmaxima[xparam]
|
||||
xaxmin = yaxminima[xparam]
|
||||
|
||||
# average values
|
||||
if xparam != 'time':
|
||||
x1mean = datadf['x1'].mean()
|
||||
else:
|
||||
x1mean = 0
|
||||
|
||||
y1mean = datadf['y1'].mean()
|
||||
y2mean = datadf['y2'].mean()
|
||||
|
||||
if xparam != 'time':
|
||||
xvals = pd.Series(xaxmin+np.arange(100)*(xaxmax-xaxmin)/100.)
|
||||
else:
|
||||
xvals = pd.Series(np.arange(100))
|
||||
|
||||
x_axis_type = 'linear'
|
||||
y_axis_type = 'linear'
|
||||
if xparam == 'time':
|
||||
x_axis_type = 'datetime'
|
||||
|
||||
if yparam1 == 'pace':
|
||||
y_axis_type = 'datetime'
|
||||
y1mean = datadf.ix[:,'pseconds'].mean()
|
||||
|
||||
datadf['xname'] = xparam
|
||||
datadf['yname1'] = yparam1
|
||||
if yparam2 != 'None':
|
||||
datadf['yname2'] = yparam2
|
||||
else:
|
||||
datadf['yname2'] = yparam1
|
||||
|
||||
source = ColumnDataSource(
|
||||
datadf
|
||||
)
|
||||
|
||||
source2 = ColumnDataSource(
|
||||
datadf.copy()
|
||||
)
|
||||
|
||||
# Add hover to this comma-separated string and see what changes
|
||||
if (promember==1):
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair'
|
||||
else:
|
||||
TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair'
|
||||
|
||||
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
|
||||
tools=TOOLS,
|
||||
toolbar_location="above",
|
||||
toolbar_sticky=False)
|
||||
|
||||
x1means = Span(location=x1mean,dimension='height',line_color='green',
|
||||
line_dash=[6,6], line_width=2)
|
||||
|
||||
y1means = Span(location=y1mean,dimension='width',line_color='blue',
|
||||
line_dash=[6,6],line_width=2)
|
||||
y2means = y1means
|
||||
|
||||
xlabel = Label(x=370,y=130,x_units='screen',y_units='screen',
|
||||
text=xparam+": {x1mean:6.2f}".format(x1mean=x1mean),
|
||||
background_fill_alpha=.7,
|
||||
text_color='green',
|
||||
)
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance'):
|
||||
plot.add_layout(x1means)
|
||||
plot.add_layout(xlabel)
|
||||
|
||||
plot.add_layout(y1means)
|
||||
|
||||
y1label = Label(x=370,y=100,x_units='screen',y_units='screen',
|
||||
text=yparam1+": {y1mean:6.2f}".format(y1mean=y1mean),
|
||||
background_fill_alpha=.7,
|
||||
text_color='blue',
|
||||
)
|
||||
if yparam1 != 'time' and yparam1 != 'pace':
|
||||
plot.add_layout(y1label)
|
||||
|
||||
y2label = y1label
|
||||
plot.circle('x1','y1',source=source2,fill_alpha=0.3,line_color=None,
|
||||
legend=yparamname1,
|
||||
)
|
||||
|
||||
plot.xaxis.axis_label = axlabels[xparam]
|
||||
plot.yaxis.axis_label = axlabels[yparam1]
|
||||
|
||||
|
||||
yrange1 = Range1d(start=yaxminima[yparam1],end=yaxmaxima[yparam1])
|
||||
plot.y_range = yrange1
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance'):
|
||||
xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam])
|
||||
plot.x_range = xrange1
|
||||
|
||||
if xparam == 'time':
|
||||
xrange1 = Range1d(start=xaxmin,end=xaxmax)
|
||||
plot.x_range = xrange1
|
||||
plot.xaxis[0].formatter = DatetimeTickFormatter(
|
||||
hours = ["%H"],
|
||||
minutes = ["%M"],
|
||||
seconds = ["%S"],
|
||||
days = ["0"],
|
||||
months = [""],
|
||||
years = [""]
|
||||
)
|
||||
|
||||
|
||||
|
||||
if yparam1 == 'pace':
|
||||
plot.yaxis[0].formatter = DatetimeTickFormatter(
|
||||
seconds = ["%S"],
|
||||
minutes = ["%M"]
|
||||
)
|
||||
|
||||
if yparam2 != 'None':
|
||||
yrange2 = Range1d(start=yaxminima[yparam2],end=yaxmaxima[yparam2])
|
||||
plot.extra_y_ranges = {"yax2": yrange2}
|
||||
|
||||
plot.circle('x1','y2',color="red",y_range_name="yax2",
|
||||
legend=yparamname2,
|
||||
source=source2,fill_alpha=0.3,line_color=None)
|
||||
|
||||
plot.add_layout(LinearAxis(y_range_name="yax2",
|
||||
axis_label=axlabels[yparam2]),'right')
|
||||
|
||||
y2means = Span(location=y2mean,dimension='width',line_color='red',
|
||||
line_dash=[6,6],line_width=2,y_range_name="yax2")
|
||||
|
||||
|
||||
plot.add_layout(y2means)
|
||||
y2label = Label(x=370,y=70,x_units='screen',y_units='screen',
|
||||
text=yparam2+": {y2mean:6.2f}".format(y2mean=y2mean),
|
||||
background_fill_alpha=.7,
|
||||
text_color='red',
|
||||
)
|
||||
if yparam2 != 'pace' and yparam2 != 'time':
|
||||
plot.add_layout(y2label)
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
|
||||
hover.tooltips = OrderedDict([
|
||||
('Time','@ftime'),
|
||||
('Pace','@fpace'),
|
||||
('HR','@hr{int}'),
|
||||
('SPM','@spm{1.1}'),
|
||||
('Power','@power{int}'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
callback = CustomJS(args = dict(source=source,source2=source2,
|
||||
x1means=x1means,
|
||||
y1means=y1means,
|
||||
y1label=y1label,
|
||||
y2label=y2label,
|
||||
xlabel=xlabel,
|
||||
y2means=y2means), code="""
|
||||
var data = source.data
|
||||
var data2 = source2.data
|
||||
var x1 = data['x1']
|
||||
var y1 = data['y1']
|
||||
var y2 = data['y2']
|
||||
var spm1 = data['spm']
|
||||
var time1 = data['time']
|
||||
var pace1 = data['pace']
|
||||
var hr1 = data['hr']
|
||||
var distance1 = data['distance']
|
||||
var power1 = data['power']
|
||||
var xname = data['xname'][0]
|
||||
var yname1 = data['yname1'][0]
|
||||
var yname2 = data['yname2'][0]
|
||||
|
||||
var minspm = minspm.value
|
||||
var maxspm = maxspm.value
|
||||
var mindist = mindist.value
|
||||
var maxdist = maxdist.value
|
||||
var xm = 0
|
||||
var ym1 = 0
|
||||
var ym2 = 0
|
||||
|
||||
data2['x1'] = []
|
||||
data2['y1'] = []
|
||||
data2['y2'] = []
|
||||
data2['spm'] = []
|
||||
data2['time'] = []
|
||||
data2['pace'] = []
|
||||
data2['hr'] = []
|
||||
data2['distance'] = []
|
||||
data2['power'] = []
|
||||
data2['x1mean'] = []
|
||||
data2['y1mean'] = []
|
||||
data2['y2mean'] = []
|
||||
data2['xvals'] = []
|
||||
data2['y1vals'] = []
|
||||
data2['y2vals'] = []
|
||||
|
||||
for (i=0; i<x1.length; i++) {
|
||||
if (spm1[i]>=minspm && spm1[i]<=maxspm) {
|
||||
if (distance1[i]>=mindist && distance1[i]<=maxdist) {
|
||||
data2['x1'].push(x1[i])
|
||||
data2['y1'].push(y1[i])
|
||||
data2['y2'].push(y2[i])
|
||||
data2['spm'].push(spm1[i])
|
||||
data2['time'].push(time1[i])
|
||||
data2['pace'].push(pace1[i])
|
||||
data2['hr'].push(hr1[i])
|
||||
data2['distance'].push(distance1[i])
|
||||
data2['power'].push(power1[i])
|
||||
|
||||
xm += x1[i]
|
||||
ym1 += y1[i]
|
||||
ym2 += y2[i]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xm /= data2['x1'].length
|
||||
ym1 /= data2['x1'].length
|
||||
ym2 /= data2['x1'].length
|
||||
|
||||
data2['x1mean'] = [xm,xm]
|
||||
data2['y1mean'] = [ym1,ym1]
|
||||
data2['y2mean'] = [ym2,ym2]
|
||||
x1means.location = xm
|
||||
y1means.location = ym1
|
||||
y2means.location = ym2
|
||||
y1label.text = yname1+': '+ym1.toFixed(2)
|
||||
y2label.text = yname2+': '+ym2.toFixed(2)
|
||||
xlabel.text = xname+': '+xm.toFixed(2)
|
||||
|
||||
source2.trigger('change');
|
||||
""")
|
||||
|
||||
slider_spm_min = Slider(start=15.0, end=55,value=15.0, step=.1,
|
||||
title="Min SPM",callback=callback)
|
||||
callback.args["minspm"] = slider_spm_min
|
||||
|
||||
|
||||
slider_spm_max = Slider(start=15.0, end=55,value=55.0, step=.1,
|
||||
title="Max SPM",callback=callback)
|
||||
callback.args["maxspm"] = slider_spm_max
|
||||
|
||||
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)
|
||||
callback.args["mindist"] = slider_dist_min
|
||||
|
||||
slider_dist_max = Slider(start=0,end=distmax,value=distmax,
|
||||
step=1,
|
||||
title="Max Distance",callback=callback)
|
||||
callback.args["maxdist"] = slider_dist_max
|
||||
|
||||
layout = layoutrow([layoutcolumn([slider_spm_min,
|
||||
slider_spm_max,
|
||||
slider_dist_min,
|
||||
slider_dist_max,
|
||||
],
|
||||
),
|
||||
plot])
|
||||
|
||||
script, div = components(layout)
|
||||
js_resources = INLINE.render_js()
|
||||
css_resources = INLINE.render_css()
|
||||
|
||||
|
||||
|
||||
return [script,div,js_resources,css_resources]
|
||||
|
||||
|
||||
|
||||
def interactive_flex_chart2(id=0,promember=0,
|
||||
@@ -1292,8 +914,8 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
'drivespeed':4,
|
||||
}
|
||||
|
||||
rowdata,row = dataprep.getrowdata(id=id)
|
||||
if rowdata == 0:
|
||||
rowdata,row = dataprep.getrowdata_db(id=id)
|
||||
if rowdata.empty:
|
||||
return "","CSV Data File Not Found"
|
||||
|
||||
workoutstateswork = [1,4,5,8,9,6,7]
|
||||
@@ -1302,16 +924,10 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
|
||||
if workstrokesonly:
|
||||
try:
|
||||
rowdata.df = rowdata.df[~rowdata.df[' WorkoutState'].isin(workoutstatesrest)]
|
||||
rowdata = rowdata[~rowdata['workoutstate'].isin(workoutstatesrest)]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
rowdata = dataprep.dataprep(rowdata.df)
|
||||
|
||||
|
||||
# get user
|
||||
# u = User.objects.get(id=row.user.id)
|
||||
|
||||
rowdata['x1'] = rowdata.ix[:,xparam]
|
||||
|
||||
rowdata['y1'] = rowdata.ix[:,yparam1]
|
||||
@@ -1634,15 +1250,10 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
|
||||
def interactive_bar_chart(id=0,promember=0):
|
||||
# check if valid ID exists (workout exists)
|
||||
rowdata,row = dataprep.getrowdata(id=id)
|
||||
if rowdata == 0:
|
||||
rowdata,row = dataprep.getrowdata_db(id=id)
|
||||
if rowdata.empty:
|
||||
return "","CSV Data File Not Found"
|
||||
|
||||
rowdata = dataprep.dataprep(rowdata.df,bands=True,barchart=True)
|
||||
|
||||
|
||||
|
||||
|
||||
# Add hover to this comma-separated string and see what changes
|
||||
if (promember==1):
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair'
|
||||
@@ -1653,8 +1264,6 @@ def interactive_bar_chart(id=0,promember=0):
|
||||
rowdata
|
||||
)
|
||||
|
||||
|
||||
|
||||
plot = Figure(x_axis_type="datetime",y_axis_type="datetime",
|
||||
toolbar_sticky=False,
|
||||
plot_width=920,
|
||||
@@ -1751,19 +1360,14 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
|
||||
|
||||
|
||||
# check if valid ID exists (workout exists)
|
||||
rowdata1,row1 = dataprep.getrowdata(id=id1)
|
||||
rowdata2,row2 = dataprep.getrowdata(id=id2)
|
||||
if rowdata1 == 0:
|
||||
rowdata1,row1 = dataprep.getrowdata_db(id=id1)
|
||||
rowdata2,row2 = dataprep.getrowdata_db(id=id2)
|
||||
if rowdata1.empty:
|
||||
return "","CSV Data File Not Found"
|
||||
|
||||
if rowdata2 == 0:
|
||||
if rowdata2.empty:
|
||||
return "","CSV Data File Not Found"
|
||||
|
||||
rowdata1 = dataprep.dataprep(rowdata1.df)
|
||||
rowdata2 = dataprep.dataprep(rowdata2.df)
|
||||
|
||||
|
||||
|
||||
x1 = rowdata1.ix[:,xparam]
|
||||
x2 = rowdata2.ix[:,xparam]
|
||||
|
||||
@@ -1899,12 +1503,10 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
|
||||
|
||||
def interactive_otw_advanced_pace_chart(id=0,promember=0):
|
||||
# check if valid ID exists (workout exists)
|
||||
rowdata,row = dataprep.getrowdata(id=id)
|
||||
if rowdata == 0:
|
||||
rowdata,row = dataprep.getrowdata_db(id=id)
|
||||
if rowdata.empty:
|
||||
return "","CSV Data File Not Found"
|
||||
|
||||
rowdata = dataprep.dataprep(rowdata.df,otwpower=True)
|
||||
|
||||
# Add hover to this comma-separated string and see what changes
|
||||
if (promember==1):
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair'
|
||||
|
||||
Reference in New Issue
Block a user