Private
Public Access
1
0

Merge branch 'feature/flexcharts' into develop

This commit is contained in:
Sander Roosendaal
2020-11-04 18:32:40 +01:00
5 changed files with 55 additions and 52 deletions

View File

@@ -2203,7 +2203,6 @@ def getsmallrowdata_db(columns, ids=[], doclean=True,workstrokesonly=True,comput
if compute and len(df):
data = df.copy()
if doclean:
print('aap')
data = clean_df_stats(data, ignorehr=True,
workstrokesonly=workstrokesonly)
data.dropna(axis=1,how='all',inplace=True)

View File

@@ -85,7 +85,7 @@ import rowers.dataprep as dataprep
import rowers.metrics as metrics
import rowers.c2stuff as c2stuff
from rowers.metrics import axes,axlabels,yaxminima,yaxmaxima
from rowers.metrics import axes,axlabels,yaxminima,yaxmaxima,get_yaxminima,get_yaxmaxima
from rowers.utils import lbstoN
from rowers.datautils import p0
@@ -4413,12 +4413,13 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
def interactive_flex_chart2(id=0,promember=0,
def interactive_flex_chart2(id,r,promember=0,
xparam='time',
yparam1='pace',
yparam2='hr',
plottype='line',
workstrokesonly=False):
workstrokesonly=False,
mode='rower'):
watermarkurl = "/static/img/logo7.png"
watermarksource = ColumnDataSource(dict(
@@ -4535,8 +4536,8 @@ def interactive_flex_chart2(id=0,promember=0,
xaxmin = rowdata['x1'].min()
else:
try:
xaxmax = yaxmaxima[xparam]
xaxmin = yaxminima[xparam]
xaxmax = get_yaxmaxima(r,xparam,mode)
xaxmin = get_yaxminima(r,xparam,mode)
except KeyError:
xaxmax = rowdata['x1'].max()
xaxmin = rowdata['x1'].min()
@@ -4733,8 +4734,8 @@ def interactive_flex_chart2(id=0,promember=0,
try:
yrange1 = Range1d(start=yaxminima[yparam1],
end=yaxmaxima[yparam1])
yrange1 = Range1d(start=get_yaxminima(r,yparam1,mode),
end=get_yaxmaxima(r,yparam1,mode))
except KeyError:
yrange1 = Range1d(start=rowdata[yparam1].min(),
end=rowdata[yparam1].max())
@@ -4743,8 +4744,8 @@ def interactive_flex_chart2(id=0,promember=0,
if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'):
try:
xrange1 = Range1d(start=yaxminima[xparam],
end=yaxmaxima[xparam])
xrange1 = Range1d(start=get_yaxminima(r,xparam,mode),
end=get_yaxmaxima(r,xparam,mode))
except KeyError:
xrange1 = Range1d(start=rowdata[xparam].min(),
end=rowdata[xparam].max())
@@ -4773,8 +4774,8 @@ def interactive_flex_chart2(id=0,promember=0,
if yparam2 != 'None':
try:
yrange2 = Range1d(start=yaxminima[yparam2],
end=yaxmaxima[yparam2])
yrange2 = Range1d(start=get_yaxminima(r,yparam2,mode),
end=get_yaxmaxima(r,yparam2,mode))
except KeyError:
yrange2 = Range1d(start=rowdata[yparam2].min(),
end=rowdata[yparam2].max())

View File

@@ -12,6 +12,7 @@ from scipy import optimize
from django.utils import timezone
from math import log10
from rowers.mytypes import otwtypes,otetypes
nometrics = [
'originalvelo',
@@ -361,6 +362,26 @@ yaxminima = {ax[0]:ax[2] for ax in axes}
yaxmaxima = {ax[0]:ax[3] for ax in axes}
def get_yaxminima(r,metric,mode):
if metric == 'pace':
if mode in otetypes:
return r.slowpaceerg
else:
return r.slowpaceotw
return yaxminima[metric]
def get_yaxmaxima(r,metric,mode):
if metric == 'pace':
if mode in otetypes:
return r.fastpaceerg
else:
return r.fastpaceotw
return yaxmaxima[metric]
defaultfavoritecharts = (
{
'yparam1':'pace',

View File

@@ -18,6 +18,7 @@ class InteractiveChartTest(TestCase):
gdproptindate=timezone.now()
)
self.nu = datetime.datetime.now()
self.r = r
self.filename = 'rowers/tests/testdata/testdata.csv'
self.wotw = Workout.objects.create(name='testworkout',
@@ -75,14 +76,14 @@ class InteractiveChartTest(TestCase):
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart5(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,promember=0,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,promember=0,
xparam='time',
yparam1='pace',yparam2='hr')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
def test_interactive_chart6(self, mocked_sqlalchemy,mocked_read_df_sql):
res = iplots.interactive_flex_chart2(self.wote.id,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,
promember=0,xparam='distance',
yparam1='pace',yparam2='hr')
@@ -91,49 +92,50 @@ class InteractiveChartTest(TestCase):
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
def test_interactive_chart7(self, mocked_sqlalchemy,mocked_read_df_sql,
mocked_getsmallrowdata_db):
res = iplots.interactive_flex_chart2(self.wote.id,promember=0,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,promember=0,
xparam='time',
yparam1='pace',yparam2='spm')
yparam1='pace',yparam2='spm',mode='water')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
def test_interactive_chart8(self, mocked_sqlalchemy,mocked_read_df_sql,
mocked_getsmallrowdata_db):
res = iplots.interactive_flex_chart2(self.wote.id,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,
promember=0,xparam='distance',
yparam1='pace',yparam2='spm')
yparam1='pace',yparam2='spm',mode='water')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
def test_interactive_chart9(self, mocked_sqlalchemy,mocked_read_df_sql,
mocked_getsmallrowdata_db):
res = iplots.interactive_flex_chart2(self.wote.id,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,
promember=1,xparam='time',
yparam1='pace',yparam2='hr')
yparam1='pace',yparam2='hr',mode='water')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
def test_interactive_chart10(self, mocked_sqlalchemy,mocked_read_df_sql,
mocked_getsmallrowdata_db):
res = iplots.interactive_flex_chart2(self.wote.id,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,
promember=1,xparam='distance',
yparam1='pace',yparam2='hr')
yparam1='pace',yparam2='hr',mode='water')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
def test_interactive_chart11(self, mocked_sqlalchemy,mocked_read_df_sql,
mocked_getsmallrowdata_db):
res = iplots.interactive_flex_chart2(self.wote.id,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,
promember=1,xparam='time',
yparam1='pace',yparam2='spm')
yparam1='pace',yparam2='spm',mode='water')
@patch('rowers.dataprep.create_engine')
@patch('rowers.dataprep.read_df_sql')
@patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
def test_interactive_chart12(self, mocked_sqlalchemy,mocked_read_df_sql,
mocked_getsmallrowdata_db):
res = iplots.interactive_flex_chart2(self.wote.id,promember=1,
res = iplots.interactive_flex_chart2(self.wote.id,self.r,
promember=1,
xparam='distance',
yparam1='pace',yparam2='spm')
yparam1='pace',yparam2='spm',mode='water')

View File

@@ -3832,35 +3832,15 @@ def workout_flexchart3_view(request,*args,**kwargs):
# xparam = xparam.replace('_slsh_','/')
# create interactive plot
try:
(
script,
div,
js_resources,
css_resources,
workstrokesonly
) = interactive_flex_chart2(
encoder.decode_hex(id),xparam=xparam,yparam1=yparam1,
(
script, div, js_resources, css_resources, workstrokesonly
) = interactive_flex_chart2(
encoder.decode_hex(id),request.user.rower,
xparam=xparam,yparam1=yparam1,
yparam2=yparam2,
promember=promember,plottype=plottype,
workstrokesonly=workstrokesonly
workstrokesonly=workstrokesonly,mode=row.workouttype
)
except ValueError:
(
script,
div,
js_resources,
css_resources,
workstrokesonly
) = interactive_flex_chart2(
encoder.decode_hex(id),xparam=xparam,yparam1=yparam1,
yparam2=yparam2,
promember=promember,plottype=plottype,
workstrokesonly=workstrokesonly
)
js_resources = ""
css_resources = ""
axchoicesbasic = {ax[0]:ax[1] for ax in axes if ax[4]=='basic'}
axchoicespro = {ax[0]:ax[1] for ax in axes if ax[4]=='pro'}