removing obsolete code
This commit is contained in:
@@ -1797,174 +1797,37 @@ def performance_chart(user, startdate=None, enddate=None, kfitness=42, kfatigue=
|
|||||||
tz=datetime.timezone.utc).replace(tzinfo=None))
|
tz=datetime.timezone.utc).replace(tzinfo=None))
|
||||||
df = df.loc[mask]
|
df = df.loc[mask]
|
||||||
|
|
||||||
source = ColumnDataSource(
|
df2 = pd.DataFrame({
|
||||||
data=dict(
|
"testpower" :df['testpower'],
|
||||||
testpower=df['testpower'],
|
"testduration":df['testduration'].apply(
|
||||||
testduration=df['testduration'].apply(
|
lambda x: totaltime_sec_to_string(x, shorten=True)),
|
||||||
lambda x: totaltime_sec_to_string(x, shorten=True)),
|
"fitness":df['fitness'],
|
||||||
date=df['date'],
|
"fatigue":df['fatigue'],
|
||||||
fdate=df['date'].map(lambda x: x.strftime('%d-%m-%Y')),
|
"form":df['form'],
|
||||||
fitness=df['fitness'],
|
"impulse":df['impulse'],
|
||||||
fatigue=df['fatigue'],
|
"date": df['date'].map(lambda x: x.strftime('%Y-%m-%d')),
|
||||||
form=df['form'],
|
})
|
||||||
impulse=df['impulse']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
plot = figure(tools=TOOLS, x_axis_type='datetime',
|
|
||||||
width=900, height=300,
|
|
||||||
toolbar_location="above",
|
|
||||||
toolbar_sticky=False)
|
|
||||||
|
|
||||||
# add watermark
|
df2.fillna(value=0, inplace=True)
|
||||||
watermarkurl = "/static/img/logo7.png"
|
|
||||||
watermarkrange = Range1d(start=0, end=1)
|
|
||||||
watermarkalpha = 0.6
|
|
||||||
watermarkx = 0.99
|
|
||||||
watermarky = 0.01
|
|
||||||
watermarkw = 184
|
|
||||||
watermarkh = 35
|
|
||||||
watermarkanchor = 'bottom_right'
|
|
||||||
plot.extra_y_ranges = {"watermark": watermarkrange}
|
|
||||||
plot.extra_x_ranges = {"watermark": watermarkrange}
|
|
||||||
|
|
||||||
plot.image_url([watermarkurl], watermarkx, watermarky,
|
data_dict = df2.to_dict("records")
|
||||||
watermarkw, watermarkh,
|
|
||||||
global_alpha=watermarkalpha,
|
|
||||||
w_units='screen',
|
|
||||||
h_units='screen',
|
|
||||||
anchor=watermarkanchor,
|
|
||||||
dilate=True,
|
|
||||||
x_range_name="watermark",
|
|
||||||
y_range_name="watermark",
|
|
||||||
)
|
|
||||||
|
|
||||||
fitlabel = 'Fitness'
|
chart_data = {
|
||||||
fatiguelabel = 'Fatigue'
|
'data': data_dict,
|
||||||
formlabel = 'Freshness'
|
'title': 'Performance Manager '+user.first_name,
|
||||||
rightaxlabel = 'Freshness'
|
'plotform' : doform,
|
||||||
if dofatigue: # pragma: no cover
|
'plotfatigue': dofatigue,
|
||||||
yaxlabel = 'Fitness/Fatigue'
|
}
|
||||||
else: # pragma: no cover
|
|
||||||
yaxlabel = 'Fitness'
|
|
||||||
|
|
||||||
if modelchoice == 'banister': # pragma: no cover
|
|
||||||
fitlabel = 'PTE (fitness)'
|
|
||||||
fatiguelabel = 'NTE (fatigue)'
|
|
||||||
formlabel = 'Performance'
|
|
||||||
rightaxlabel = 'Performance'
|
|
||||||
if dofatigue:
|
|
||||||
yaxlabel = 'PTE/NTE'
|
|
||||||
else:
|
|
||||||
yaxlabel = 'PTE'
|
|
||||||
|
|
||||||
|
|
||||||
plot.xaxis.axis_label = None
|
script, div = get_chart("/performance", chart_data)
|
||||||
plot.yaxis.axis_label = yaxlabel
|
|
||||||
|
|
||||||
y2rangemin = df.loc[:, ['form']].min().min()
|
|
||||||
y2rangemax = df.loc[:, ['form']].max().max()
|
|
||||||
|
|
||||||
if dofatigue: # pragma: no cover
|
|
||||||
y1rangemax = df.loc[:, ['fitness', 'fatigue']].max().max()*1.02
|
|
||||||
else: # pragma: no cover
|
|
||||||
y1rangemax = df.loc[:, ['fitness']].max().max()*1.02
|
|
||||||
|
|
||||||
if doform: # pragma: no cover
|
|
||||||
plot.extra_y_ranges["yax2"] = Range1d(start=y2rangemin, end=y2rangemax)
|
|
||||||
plot.add_layout(LinearAxis(y_range_name="yax2",
|
|
||||||
axis_label=rightaxlabel), "right")
|
|
||||||
|
|
||||||
plot.line('date', 'fitness', source=source, color='blue',
|
|
||||||
legend_label=fitlabel)
|
|
||||||
band = Band(base='date', upper='fitness', lower=0, source=source, level='underlay',
|
|
||||||
fill_alpha=0.2, fill_color='blue')
|
|
||||||
plot.add_layout(band)
|
|
||||||
|
|
||||||
if dofatigue: # pragma: no cover
|
|
||||||
plot.line('date', 'fatigue', source=source, color='red',
|
|
||||||
legend_label=fatiguelabel)
|
|
||||||
if doform: # pragma: no cover
|
|
||||||
plot.line('date', 'form', source=source, color='green',
|
|
||||||
legend_label=formlabel, y_range_name="yax2")
|
|
||||||
|
|
||||||
plot.legend.location = "top_left"
|
|
||||||
|
|
||||||
#plot.sizing_mode = 'scale_both'
|
|
||||||
|
|
||||||
startdate = datetime.datetime.combine(
|
|
||||||
startdate, datetime.datetime.min.time())
|
|
||||||
enddate = datetime.datetime.combine(enddate, datetime.datetime.min.time())
|
|
||||||
|
|
||||||
xrange = Range1d(
|
|
||||||
startdate, enddate,
|
|
||||||
)
|
|
||||||
plot.x_range = xrange
|
|
||||||
plot.y_range = Range1d(
|
|
||||||
start=0, end=y1rangemax,
|
|
||||||
)
|
|
||||||
plot.title.text = 'Performance Manager '+user.first_name
|
|
||||||
|
|
||||||
hover = plot.select(dict(type=HoverTool))
|
|
||||||
|
|
||||||
linked_crosshair = CrosshairTool(dimensions='height')
|
|
||||||
|
|
||||||
hover.tooltips = OrderedDict([
|
|
||||||
('Date', '@fdate'),
|
|
||||||
(fitlabel, '@fitness{int}'),
|
|
||||||
(fatiguelabel, '@fatigue{int}'),
|
|
||||||
(formlabel, '@form{int}'),
|
|
||||||
('Impulse', '@impulse{int}')
|
|
||||||
])
|
|
||||||
|
|
||||||
if showtests:
|
|
||||||
hover.tooltips = OrderedDict([
|
|
||||||
('Date', '@fdate'),
|
|
||||||
(fitlabel, '@fitness{int}'),
|
|
||||||
(fatiguelabel, '@fatigue{int}'),
|
|
||||||
(formlabel, '@form{int}'),
|
|
||||||
('Impulse', '@impulse{int}'),
|
|
||||||
('Gold Medal Score', '@testpower{int}'),
|
|
||||||
('Test', '@testduration'),
|
|
||||||
])
|
|
||||||
|
|
||||||
plot2 = figure(tools=TOOLS2, x_axis_type='datetime',
|
|
||||||
width=900, height=150,
|
|
||||||
toolbar_location=None,
|
|
||||||
toolbar_sticky=False)
|
|
||||||
|
|
||||||
plot2.x_range = xrange
|
|
||||||
plot2.y_range = Range1d(0, df['impulse'].max())
|
|
||||||
|
|
||||||
plot2.vbar(x=df['date'], top=df['impulse'], color='gray')
|
|
||||||
plot2.vbar(x=df['date'], top=0*df['testpower']+df['impulse'], color='red')
|
|
||||||
|
|
||||||
#plot2.sizing_mode = 'scale_both'
|
|
||||||
plot2.yaxis.axis_label = 'Impulse'
|
|
||||||
plot2.xaxis.axis_label = 'Date'
|
|
||||||
|
|
||||||
plot.add_tools(linked_crosshair)
|
|
||||||
plot2.add_tools(linked_crosshair)
|
|
||||||
|
|
||||||
mylayout = layoutcolumn([plot, plot2])
|
|
||||||
|
|
||||||
try:
|
|
||||||
script, div = components(mylayout)
|
|
||||||
except Exception as e: # pragma: no cover
|
|
||||||
df.dropna(inplace=True, axis=0, how='any')
|
|
||||||
return (
|
|
||||||
'',
|
|
||||||
'Something went wrong with the chart ({nrworkouts} workouts, {nrdata} datapoints, error {e})'.format(
|
|
||||||
nrworkouts=workouts.count(),
|
|
||||||
nrdata=len(df),
|
|
||||||
e=e,
|
|
||||||
), 0, 0, 0, []
|
|
||||||
)
|
|
||||||
|
|
||||||
return [script, div, endfitness, endfatigue, endform, outids]
|
return [script, div, endfitness, endfatigue, endform, outids]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def interactive_histoall(theworkouts, histoparam, includereststrokes,
|
def interactive_histoall(theworkouts, histoparam, includereststrokes,
|
||||||
spmmin=0, spmmax=55,
|
spmmin=0, spmmax=55,
|
||||||
extratitle='',
|
extratitle='',
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
<script type='text/javascript'
|
<script type='text/javascript'
|
||||||
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||||
</script>
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
|
|
||||||
|
<script src="https://d3js.org/d3.v6.js">
|
||||||
|
</script>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function submit_form() {
|
function submit_form() {
|
||||||
@@ -25,11 +34,14 @@
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
|
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
console.log(data.div);
|
|
||||||
|
|
||||||
// var parsedJSON = $.parseJSON(data); //
|
// var parsedJSON = $.parseJSON(data); //
|
||||||
$("#id_script").replaceWith('<div id="id_script">'+data.script+'</d'+'iv>');
|
$("#id_script").replaceWith('<div id="id_script">'+data.script+'</d'+'iv>');
|
||||||
|
|
||||||
|
// $('#id_script').remove()
|
||||||
|
|
||||||
$("#id_chart").replaceWith('<div id="id_chart">'+data.div+'</d'+'iv>');
|
$("#id_chart").replaceWith('<div id="id_chart">'+data.div+'</d'+'iv>');
|
||||||
|
$("#id_chart").append(data.script)
|
||||||
$("#endfitness").html(data.endfitness)
|
$("#endfitness").html(data.endfitness)
|
||||||
$("#endfatigue").html(data.endfatigue)
|
$("#endfatigue").html(data.endfatigue)
|
||||||
$("#endform").html(data.endform)
|
$("#endform").html(data.endform)
|
||||||
@@ -59,19 +71,6 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block main %}
|
|
||||||
|
|
||||||
|
|
||||||
<script src="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.js"></script>
|
|
||||||
<script async="true" type="text/javascript">
|
|
||||||
Bokeh.set_log_level("info");
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div id="id_script">
|
|
||||||
{{ chartscript |safe }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -83,10 +82,12 @@
|
|||||||
|
|
||||||
|
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
|
<canvas hidden id="canvas"></canvas>
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
<div id="id_chart">
|
<div id="id_chart">
|
||||||
{{ the_div|safe }}
|
{{ the_div|safe }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<li class="grid_1">
|
<li class="grid_1">
|
||||||
<form id="performanceform" enctype="multipart/form-data" method="post">
|
<form id="performanceform" enctype="multipart/form-data" method="post">
|
||||||
@@ -188,6 +189,9 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<div id="id_script">
|
||||||
|
{{ chartscript |safe }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user