Private
Public Access
1
0

first bit of plotting extra metrics

Need to look at the data duplication - where does it come from
This commit is contained in:
Sander Roosendaal
2017-11-28 23:12:32 +01:00
parent 79d20bb860
commit 4e5b661923
2 changed files with 65 additions and 14 deletions

View File

@@ -1547,8 +1547,27 @@ def getrowdata_db(id=0, doclean=False, convertnewtons=True):
def getsmallrowdata_db(columns, ids=[], doclean=True, workstrokesonly=True):
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
if doclean:
@@ -1622,9 +1641,12 @@ def read_cols_df_sql(ids, columns, convertnewtons=True):
# axx = [ax[0] for ax in axes]
axx = [f.name for f in StrokeData._meta.get_fields()]
extracols = []
for c in columns:
if not c in axx:
columns.remove(c)
extracols.append(c)
columns = list(columns) + ['distance', 'spm', 'workoutid']
columns = [x for x in columns if x != 'None']
@@ -1673,7 +1695,7 @@ def read_cols_df_sql(ids, columns, convertnewtons=True):
'averageforce'] * lbstoN
engine.dispose()
return df
return df,extracols
# 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:
# HR bands
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
if id != 0:
data['workoutid'] = id
engine = create_engine(database_url, echo=False)
with engine.connect() as conn, conn.begin():
data.to_sql('strokedata', engine, if_exists='append', index=False)

View File

@@ -2175,13 +2175,19 @@ def interactive_flex_chart2(id=0,promember=0,
except KeyError:
y1mean = 0
rowdata['xname'] = axlabels[xparam]
rowdata['yname1'] = axlabels[yparam1]
try:
rowdata['yname1'] = axlabels[yparam1]
except KeyError:
rowdata['yname1'] = yparam1
if yparam2 != 'None':
rowdata['yname2'] = axlabels[yparam2]
try:
rowdata['yname2'] = axlabels[yparam2]
except KeyError:
rowdata['yname2'] = yparam2
else:
rowdata['yname2'] = axlabels[yparam1]
rowdata['yname2'] = rowdata['yname1']
# prepare data
@@ -2281,7 +2287,12 @@ def interactive_flex_chart2(id=0,promember=0,
plot.title.text_font_size=value("1.0em")
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
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
if xparam == 'time':
@@ -2313,22 +2330,32 @@ def interactive_flex_chart2(id=0,promember=0,
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
#= {"yax2": yrange2}
try:
axlegend = axlabels[yparam2]
except KeyError:
axlegend = str(yparam2)+' '
if plottype=='line':
plot.line('x1','y2',color="red",y_range_name="yax2",
legend=axlabels[yparam2],
legend=axlegend,
source=source2)
elif plottype=='scatter':
plot.scatter('x1','y2',source=source2,legend=axlabels[yparam2]
,fill_alpha=0.4,
plot.scatter('x1','y2',source=source2,legend=axlegend,
fill_alpha=0.4,
line_color=None,color="red",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',
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)
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_color='white',
text_color='red',