v1 instroke_compare
This commit is contained in:
@@ -2756,12 +2756,14 @@ def forcecurve_multi_interactive_chart(selected): # pragma: no cover
|
||||
return (script, div)
|
||||
|
||||
def instroke_multi_interactive_chart(selected, *args, **kwargs): # pragma: no cover
|
||||
df_plot = pd.DataFrame()
|
||||
df2 = []
|
||||
ids = [analysis.id for analysis in selected]
|
||||
metrics = list(set([analysis.metric for analysis in selected]))
|
||||
maximum_values = {}
|
||||
workouts = []
|
||||
for metric in metrics:
|
||||
maximum_values[metric] = 0
|
||||
cntr = 1
|
||||
for analysis in selected:
|
||||
#start_second, end_second, spm_min, spm_max, name
|
||||
activeminutesmin = int(analysis.start_second/60.)
|
||||
@@ -2781,79 +2783,48 @@ def instroke_multi_interactive_chart(selected, *args, **kwargs): # pragma: no co
|
||||
if mean_vals.max() > maximum_values[analysis.metric]:
|
||||
maximum_values[analysis.metric] = mean_vals.max()
|
||||
xvals = np.arange(len(mean_vals))
|
||||
xname = 'x_'+str(analysis.id)
|
||||
yname = 'y_'+str(analysis.id)
|
||||
df_plot[xname] = pd.Series(xvals)
|
||||
df_plot[yname] = pd.Series(mean_vals)
|
||||
|
||||
if len(metrics) > 1:
|
||||
for analysis in selected:
|
||||
yname = 'y_'+str(analysis.id)
|
||||
df_plot[yname] = df_plot[yname] / maximum_values[analysis.metric]
|
||||
data2 = pd.DataFrame({
|
||||
'x': pd.Series(xvals),
|
||||
'y': pd.Series(mean_vals),
|
||||
|
||||
})
|
||||
data2['id'] = cntr
|
||||
df2.append(data2)
|
||||
|
||||
source = ColumnDataSource(
|
||||
df_plot
|
||||
)
|
||||
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,crosshair'
|
||||
plot = figure(width=920,tools=TOOLS,
|
||||
toolbar_location='above',
|
||||
toolbar_sticky=False)
|
||||
|
||||
#plot.sizing_mode = 'stretch_both'
|
||||
|
||||
# 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}
|
||||
|
||||
if len(metrics)>1:
|
||||
plot.yaxis.axis_label = 'Scaled'
|
||||
else:
|
||||
plot.yaxis.axis_label = metrics[0]
|
||||
|
||||
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",
|
||||
)
|
||||
|
||||
colors = itertools.cycle(palette)
|
||||
|
||||
try:
|
||||
items = itertools.izip(ids, colors)
|
||||
except AttributeError:
|
||||
items = zip(ids, colors)
|
||||
|
||||
for id, color in items:
|
||||
xname = 'x_'+str(id)
|
||||
yname = 'y_'+str(id)
|
||||
analysis = InStrokeAnalysis.objects.get(id=id)
|
||||
legendlabel = '{name} - {metric} - {workout}'.format(
|
||||
name = analysis.name,
|
||||
metric = analysis.metric,
|
||||
date = analysis.date,
|
||||
workout = str(analysis.workout)
|
||||
)
|
||||
plot.line(xname,yname,source=source,legend_label=legendlabel,
|
||||
line_width=2, color=color)
|
||||
workouts.append({'id': cntr, 'label': legendlabel})
|
||||
cntr = cntr + 1
|
||||
|
||||
script, div = components(plot)
|
||||
|
||||
ytitle = metrics[0]
|
||||
if len(metrics) > 1:
|
||||
cntr = 1
|
||||
for analysis in selected:
|
||||
df2[cntr-1]['y'] = df2[cntr-1]['y'] / maximum_values[analysis.metric]
|
||||
ytitle = 'Scaled'
|
||||
cntr = cntr+1
|
||||
|
||||
return (script, div)
|
||||
df2 = pd.concat(df2, axis=0)
|
||||
|
||||
data_dict = df2.to_dict("records")
|
||||
|
||||
chart_data = {
|
||||
'title': '',
|
||||
'data': data_dict,
|
||||
'ytitle': ytitle,
|
||||
'workouts': workouts,
|
||||
}
|
||||
|
||||
script, div = get_chart("/instroke_compare", chart_data)
|
||||
|
||||
return script, div
|
||||
|
||||
|
||||
def instroke_interactive_chart(df,metric, workout, spm_min, spm_max,
|
||||
activeminutesmin, activeminutesmax,
|
||||
|
||||
@@ -6,24 +6,20 @@
|
||||
|
||||
{% block main %}
|
||||
|
||||
{{ js_res | safe }}
|
||||
{{ css_res| safe }}
|
||||
|
||||
<script src="https://cdn.pydata.org/bokeh/release/bokeh-3.1.1.min.js"></script>
|
||||
<script src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-3.1.1.min.js"></script>
|
||||
<script src="https://d3js.org/d3.v6.js"></script>
|
||||
<script async="true" type="text/javascript">
|
||||
Bokeh.set_log_level("info");
|
||||
</script>
|
||||
|
||||
{{ the_script |safe }}
|
||||
|
||||
<h1>In-Stroke Analysis for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
|
||||
|
||||
<ul class="main-content">
|
||||
<canvas hidden id="canvas"></canvas>
|
||||
{% if the_div %}
|
||||
<li class="grid_4">
|
||||
<div id="theplot" class="flexplot">
|
||||
{{ the_div|safe }}
|
||||
{{ the_script |safe }}
|
||||
</div>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user