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))
|
||||
df = df.loc[mask]
|
||||
|
||||
source = ColumnDataSource(
|
||||
data=dict(
|
||||
testpower=df['testpower'],
|
||||
testduration=df['testduration'].apply(
|
||||
lambda x: totaltime_sec_to_string(x, shorten=True)),
|
||||
date=df['date'],
|
||||
fdate=df['date'].map(lambda x: x.strftime('%d-%m-%Y')),
|
||||
fitness=df['fitness'],
|
||||
fatigue=df['fatigue'],
|
||||
form=df['form'],
|
||||
impulse=df['impulse']
|
||||
)
|
||||
)
|
||||
df2 = pd.DataFrame({
|
||||
"testpower" :df['testpower'],
|
||||
"testduration":df['testduration'].apply(
|
||||
lambda x: totaltime_sec_to_string(x, shorten=True)),
|
||||
"fitness":df['fitness'],
|
||||
"fatigue":df['fatigue'],
|
||||
"form":df['form'],
|
||||
"impulse":df['impulse'],
|
||||
"date": df['date'].map(lambda x: x.strftime('%Y-%m-%d')),
|
||||
})
|
||||
|
||||
|
||||
plot = figure(tools=TOOLS, x_axis_type='datetime',
|
||||
width=900, height=300,
|
||||
toolbar_location="above",
|
||||
toolbar_sticky=False)
|
||||
|
||||
# add watermark
|
||||
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}
|
||||
df2.fillna(value=0, inplace=True)
|
||||
|
||||
plot.image_url([watermarkurl], watermarkx, watermarky,
|
||||
watermarkw, watermarkh,
|
||||
global_alpha=watermarkalpha,
|
||||
w_units='screen',
|
||||
h_units='screen',
|
||||
anchor=watermarkanchor,
|
||||
dilate=True,
|
||||
x_range_name="watermark",
|
||||
y_range_name="watermark",
|
||||
)
|
||||
data_dict = df2.to_dict("records")
|
||||
|
||||
fitlabel = 'Fitness'
|
||||
fatiguelabel = 'Fatigue'
|
||||
formlabel = 'Freshness'
|
||||
rightaxlabel = 'Freshness'
|
||||
if dofatigue: # pragma: no cover
|
||||
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'
|
||||
chart_data = {
|
||||
'data': data_dict,
|
||||
'title': 'Performance Manager '+user.first_name,
|
||||
'plotform' : doform,
|
||||
'plotfatigue': dofatigue,
|
||||
}
|
||||
|
||||
|
||||
plot.xaxis.axis_label = None
|
||||
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, []
|
||||
)
|
||||
script, div = get_chart("/performance", chart_data)
|
||||
|
||||
return [script, div, endfitness, endfatigue, endform, outids]
|
||||
|
||||
|
||||
|
||||
def interactive_histoall(theworkouts, histoparam, includereststrokes,
|
||||
spmmin=0, spmmax=55,
|
||||
extratitle='',
|
||||
|
||||
@@ -8,6 +8,15 @@
|
||||
<script type='text/javascript'
|
||||
src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'>
|
||||
</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>
|
||||
|
||||
function submit_form() {
|
||||
@@ -25,11 +34,14 @@
|
||||
dataType: 'json',
|
||||
|
||||
success: function(data) {
|
||||
console.log(data.div);
|
||||
|
||||
// var parsedJSON = $.parseJSON(data); //
|
||||
$("#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").append(data.script)
|
||||
$("#endfitness").html(data.endfitness)
|
||||
$("#endfatigue").html(data.endfatigue)
|
||||
$("#endform").html(data.endform)
|
||||
@@ -59,19 +71,6 @@
|
||||
});
|
||||
});
|
||||
</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">
|
||||
<canvas hidden id="canvas"></canvas>
|
||||
<li class="grid_4">
|
||||
<div id="id_chart">
|
||||
{{ the_div|safe }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
<li class="grid_1">
|
||||
<form id="performanceform" enctype="multipart/form-data" method="post">
|
||||
@@ -188,6 +189,9 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div id="id_script">
|
||||
{{ chartscript |safe }}
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user