first bit of plotting extra metrics
Need to look at the data duplication - where does it come from
This commit is contained in:
@@ -1547,7 +1547,26 @@ def getrowdata_db(id=0, doclean=False, convertnewtons=True):
|
|||||||
|
|
||||||
def getsmallrowdata_db(columns, ids=[], doclean=True, workstrokesonly=True):
|
def getsmallrowdata_db(columns, ids=[], doclean=True, workstrokesonly=True):
|
||||||
prepmultipledata(ids)
|
prepmultipledata(ids)
|
||||||
data = read_cols_df_sql(ids, columns)
|
data,extracols = read_cols_df_sql(ids, columns)
|
||||||
|
if extracols and len(ids)==1:
|
||||||
|
w = Workout.objects.get(id=ids[0])
|
||||||
|
row = rdata(w.csvfilename)
|
||||||
|
f = row.df['TimeStamp (sec)'].diff().mean()
|
||||||
|
if f != 0 and not np.isnan(f):
|
||||||
|
windowsize = 2 * (int(10. / (f))) + 1
|
||||||
|
else:
|
||||||
|
windowsize = 1
|
||||||
|
for c in extracols:
|
||||||
|
try:
|
||||||
|
cdata = row.df[c]
|
||||||
|
cdata.fillna(inplace=True,method='bfill')
|
||||||
|
# This doesn't work because sometimes data are duplicated at save
|
||||||
|
cdata2 = savgol_filter(cdata.values,windowsize,3)
|
||||||
|
|
||||||
|
print len(cdata),len(cdata2),'mies'
|
||||||
|
data[c] = cdata
|
||||||
|
except KeyError:
|
||||||
|
data[c] = 0
|
||||||
|
|
||||||
# convert newtons
|
# convert newtons
|
||||||
|
|
||||||
@@ -1622,9 +1641,12 @@ def read_cols_df_sql(ids, columns, convertnewtons=True):
|
|||||||
# axx = [ax[0] for ax in axes]
|
# axx = [ax[0] for ax in axes]
|
||||||
axx = [f.name for f in StrokeData._meta.get_fields()]
|
axx = [f.name for f in StrokeData._meta.get_fields()]
|
||||||
|
|
||||||
|
extracols = []
|
||||||
|
|
||||||
for c in columns:
|
for c in columns:
|
||||||
if not c in axx:
|
if not c in axx:
|
||||||
columns.remove(c)
|
columns.remove(c)
|
||||||
|
extracols.append(c)
|
||||||
|
|
||||||
columns = list(columns) + ['distance', 'spm', 'workoutid']
|
columns = list(columns) + ['distance', 'spm', 'workoutid']
|
||||||
columns = [x for x in columns if x != 'None']
|
columns = [x for x in columns if x != 'None']
|
||||||
@@ -1673,7 +1695,7 @@ def read_cols_df_sql(ids, columns, convertnewtons=True):
|
|||||||
'averageforce'] * lbstoN
|
'averageforce'] * lbstoN
|
||||||
|
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
return df
|
return df,extracols
|
||||||
|
|
||||||
# Read stroke data from the DB for a Workout ID. Returns a pandas dataframe
|
# Read stroke data from the DB for a Workout ID. Returns a pandas dataframe
|
||||||
|
|
||||||
@@ -1973,6 +1995,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if bands:
|
if bands:
|
||||||
# HR bands
|
# HR bands
|
||||||
data['hr_ut2'] = rowdatadf.ix[:, 'hr_ut2']
|
data['hr_ut2'] = rowdatadf.ix[:, 'hr_ut2']
|
||||||
@@ -2133,6 +2156,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
|
|||||||
# write data if id given
|
# write data if id given
|
||||||
if id != 0:
|
if id != 0:
|
||||||
data['workoutid'] = id
|
data['workoutid'] = id
|
||||||
|
|
||||||
engine = create_engine(database_url, echo=False)
|
engine = create_engine(database_url, echo=False)
|
||||||
with engine.connect() as conn, conn.begin():
|
with engine.connect() as conn, conn.begin():
|
||||||
data.to_sql('strokedata', engine, if_exists='append', index=False)
|
data.to_sql('strokedata', engine, if_exists='append', index=False)
|
||||||
|
|||||||
@@ -2177,11 +2177,17 @@ def interactive_flex_chart2(id=0,promember=0,
|
|||||||
|
|
||||||
|
|
||||||
rowdata['xname'] = axlabels[xparam]
|
rowdata['xname'] = axlabels[xparam]
|
||||||
|
try:
|
||||||
rowdata['yname1'] = axlabels[yparam1]
|
rowdata['yname1'] = axlabels[yparam1]
|
||||||
|
except KeyError:
|
||||||
|
rowdata['yname1'] = yparam1
|
||||||
if yparam2 != 'None':
|
if yparam2 != 'None':
|
||||||
|
try:
|
||||||
rowdata['yname2'] = axlabels[yparam2]
|
rowdata['yname2'] = axlabels[yparam2]
|
||||||
|
except KeyError:
|
||||||
|
rowdata['yname2'] = yparam2
|
||||||
else:
|
else:
|
||||||
rowdata['yname2'] = axlabels[yparam1]
|
rowdata['yname2'] = rowdata['yname1']
|
||||||
|
|
||||||
|
|
||||||
# prepare data
|
# prepare data
|
||||||
@@ -2281,7 +2287,12 @@ def interactive_flex_chart2(id=0,promember=0,
|
|||||||
plot.title.text_font_size=value("1.0em")
|
plot.title.text_font_size=value("1.0em")
|
||||||
|
|
||||||
plot.xaxis.axis_label = axlabels[xparam]
|
plot.xaxis.axis_label = axlabels[xparam]
|
||||||
plot.yaxis.axis_label = axlabels[yparam1]
|
try:
|
||||||
|
yaxlabel = axlabels[yparam1]
|
||||||
|
except KeyError:
|
||||||
|
yaxlabel = yparam1
|
||||||
|
|
||||||
|
plot.yaxis.axis_label = yaxlabel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2289,7 +2300,13 @@ def interactive_flex_chart2(id=0,promember=0,
|
|||||||
plot.y_range = yrange1
|
plot.y_range = yrange1
|
||||||
|
|
||||||
if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'):
|
if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'):
|
||||||
xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam])
|
try:
|
||||||
|
xrange1 = Range1d(start=yaxminima[xparam],
|
||||||
|
end=yaxmaxima[xparam])
|
||||||
|
except KeyError:
|
||||||
|
xrange1 = Range1d(start=rowdata[xparam].min(),
|
||||||
|
end=rowdata[xparam].max())
|
||||||
|
|
||||||
plot.x_range = xrange1
|
plot.x_range = xrange1
|
||||||
|
|
||||||
if xparam == 'time':
|
if xparam == 'time':
|
||||||
@@ -2313,22 +2330,32 @@ def interactive_flex_chart2(id=0,promember=0,
|
|||||||
|
|
||||||
|
|
||||||
if yparam2 != 'None':
|
if yparam2 != 'None':
|
||||||
yrange2 = Range1d(start=yaxminima[yparam2],end=yaxmaxima[yparam2])
|
try:
|
||||||
|
yrange2 = Range1d(start=yaxminima[yparam2],
|
||||||
|
end=yaxmaxima[yparam2])
|
||||||
|
except KeyError:
|
||||||
|
yrange2 = Range1d(start=rowdata[yparam2].min(),
|
||||||
|
end=rowdata[yparam2].max())
|
||||||
|
|
||||||
plot.extra_y_ranges["yax2"] = yrange2
|
plot.extra_y_ranges["yax2"] = yrange2
|
||||||
#= {"yax2": yrange2}
|
#= {"yax2": yrange2}
|
||||||
|
try:
|
||||||
|
axlegend = axlabels[yparam2]
|
||||||
|
except KeyError:
|
||||||
|
axlegend = str(yparam2)+' '
|
||||||
|
|
||||||
if plottype=='line':
|
if plottype=='line':
|
||||||
plot.line('x1','y2',color="red",y_range_name="yax2",
|
plot.line('x1','y2',color="red",y_range_name="yax2",
|
||||||
legend=axlabels[yparam2],
|
legend=axlegend,
|
||||||
source=source2)
|
source=source2)
|
||||||
|
|
||||||
elif plottype=='scatter':
|
elif plottype=='scatter':
|
||||||
plot.scatter('x1','y2',source=source2,legend=axlabels[yparam2]
|
plot.scatter('x1','y2',source=source2,legend=axlegend,
|
||||||
,fill_alpha=0.4,
|
fill_alpha=0.4,
|
||||||
line_color=None,color="red",y_range_name="yax2")
|
line_color=None,color="red",y_range_name="yax2")
|
||||||
|
|
||||||
plot.add_layout(LinearAxis(y_range_name="yax2",
|
plot.add_layout(LinearAxis(y_range_name="yax2",
|
||||||
axis_label=axlabels[yparam2]),'right')
|
axis_label=axlegend),'right')
|
||||||
|
|
||||||
y2means = Span(location=y2mean,dimension='width',line_color='red',
|
y2means = Span(location=y2mean,dimension='width',line_color='red',
|
||||||
line_dash=[6,6],line_width=2,y_range_name="yax2")
|
line_dash=[6,6],line_width=2,y_range_name="yax2")
|
||||||
@@ -2336,7 +2363,7 @@ def interactive_flex_chart2(id=0,promember=0,
|
|||||||
|
|
||||||
plot.add_layout(y2means)
|
plot.add_layout(y2means)
|
||||||
y2label = Label(x=100,y=70,x_units='screen',y_units='screen',
|
y2label = Label(x=100,y=70,x_units='screen',y_units='screen',
|
||||||
text=axlabels[yparam2]+": {y2mean:6.2f}".format(y2mean=y2mean),
|
text=axlegend+": {y2mean:6.2f}".format(y2mean=y2mean),
|
||||||
background_fill_alpha=.7,
|
background_fill_alpha=.7,
|
||||||
background_fill_color='white',
|
background_fill_color='white',
|
||||||
text_color='red',
|
text_color='red',
|
||||||
|
|||||||
Reference in New Issue
Block a user