Merge branch 'develop' into feature/restapi
This commit is contained in:
@@ -5,9 +5,11 @@ from rowingdata import cumcpdata,histodata
|
||||
|
||||
from rowingdata import rowingdata as rrdata
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc
|
||||
from bokeh.models import CustomJS,Slider
|
||||
from bokeh.charts import Histogram
|
||||
from bokeh.charts import Histogram,HeatMap
|
||||
from bokeh.resources import CDN,INLINE
|
||||
from bokeh.embed import components
|
||||
from bokeh.layouts import layout,widgetbox
|
||||
@@ -68,14 +70,13 @@ 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','power','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]
|
||||
@@ -494,18 +495,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,
|
||||
@@ -552,10 +550,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"
|
||||
|
||||
@@ -563,23 +561,15 @@ def interactive_chart(id=0,promember=0):
|
||||
|
||||
return [script,div]
|
||||
|
||||
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)
|
||||
|
||||
def interactive_cum_flex_chart2(theworkouts,promember=0,
|
||||
xparam='spm',
|
||||
yparam1='power',
|
||||
yparam2='spm'):
|
||||
|
||||
# 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)',
|
||||
@@ -626,21 +616,11 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
}
|
||||
|
||||
|
||||
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]
|
||||
datadf = datadf[datadf[yparam1] > 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]
|
||||
|
||||
datadf = datadf[datadf[xparam] > 0]
|
||||
|
||||
if yparam2 != 'None':
|
||||
datadf = datadf[datadf[yparam2] > 0]
|
||||
@@ -651,9 +631,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
|
||||
datadf['x1'] = datadf.ix[:,xparam]
|
||||
tseconds = datadf.ix[:,'timesecs']
|
||||
|
||||
|
||||
|
||||
datadf['y1'] = datadf.ix[:,yparam1]
|
||||
if yparam2 != 'None':
|
||||
datadf['y2'] = datadf.ix[:,yparam2]
|
||||
@@ -661,12 +639,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
datadf['y2'] = datadf['y1']
|
||||
|
||||
|
||||
if xparam=='time':
|
||||
xaxmax = tseconds.max()
|
||||
xaxmin = tseconds.min()
|
||||
xaxmax = 1.0e3*xaxmax
|
||||
xaxmin = 1.0e3*xaxmin
|
||||
elif xparam=='distance':
|
||||
if xparam=='distance':
|
||||
xaxmax = datadf['x1'].max()
|
||||
xaxmin = datadf['x1'].min()
|
||||
else:
|
||||
@@ -674,27 +647,16 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
xaxmin = yaxminima[xparam]
|
||||
|
||||
# average values
|
||||
if xparam != 'time':
|
||||
x1mean = datadf['x1'].mean()
|
||||
else:
|
||||
x1mean = 0
|
||||
x1mean = datadf['x1'].mean()
|
||||
|
||||
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))
|
||||
|
||||
xvals = pd.Series(xaxmin+np.arange(100)*(xaxmax-xaxmin)/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
|
||||
@@ -703,6 +665,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
else:
|
||||
datadf['yname2'] = yparam1
|
||||
|
||||
|
||||
source = ColumnDataSource(
|
||||
datadf
|
||||
)
|
||||
@@ -713,9 +676,9 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
# 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'
|
||||
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,
|
||||
@@ -735,9 +698,9 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
text_color='green',
|
||||
)
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance'):
|
||||
plot.add_layout(x1means)
|
||||
plot.add_layout(xlabel)
|
||||
|
||||
plot.add_layout(x1means)
|
||||
plot.add_layout(xlabel)
|
||||
|
||||
plot.add_layout(y1means)
|
||||
|
||||
@@ -746,8 +709,8 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
background_fill_alpha=.7,
|
||||
text_color='blue',
|
||||
)
|
||||
if yparam1 != 'time' and yparam1 != 'pace':
|
||||
plot.add_layout(y1label)
|
||||
|
||||
plot.add_layout(y1label)
|
||||
|
||||
y2label = y1label
|
||||
plot.circle('x1','y1',source=source2,fill_alpha=0.3,line_color=None,
|
||||
@@ -761,29 +724,9 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
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
|
||||
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])
|
||||
@@ -809,18 +752,6 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
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,
|
||||
@@ -835,11 +766,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
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]
|
||||
@@ -856,11 +783,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
data2['y1'] = []
|
||||
data2['y2'] = []
|
||||
data2['spm'] = []
|
||||
data2['time'] = []
|
||||
data2['pace'] = []
|
||||
data2['hr'] = []
|
||||
data2['distance'] = []
|
||||
data2['power'] = []
|
||||
data2['x1mean'] = []
|
||||
data2['y1mean'] = []
|
||||
data2['y2mean'] = []
|
||||
@@ -875,11 +798,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
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]
|
||||
@@ -944,6 +863,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
|
||||
|
||||
|
||||
def interactive_flex_chart2(id=0,promember=0,
|
||||
xparam='time',
|
||||
yparam1='pace',
|
||||
@@ -994,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]
|
||||
@@ -1004,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]
|
||||
@@ -1336,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'
|
||||
@@ -1355,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,
|
||||
@@ -1453,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]
|
||||
|
||||
@@ -1601,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