Skip to content

Commit 2378f16

Browse files
committed
Implemented selection procedure for 2 graphs
1 parent f74d93d commit 2378f16

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

dashboard/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def get_session_id():
1111
# implement here your own custom function
12-
return "12345"
12+
return "1234"
1313

1414
dashboard.config.get_group_by = get_session_id
1515
dashboard.bind(app=user_app)

dashboard/routings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ def static(filename):
2727
# All rules below are for viewing the dashboard-pages
2828
@blueprint.route('/')
2929
def index():
30-
return redirect(url_for('dashboard.measurements'))
30+
return redirect(url_for('dashboard.measurements', index=0))

dashboard/routings/measurements.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ def measurements(index):
2424

2525
# returns a page with the number of requests per endpoint
2626
if index == 1:
27-
page = 'measurements/endpoint_pygal.html'
27+
page = 'measurements/measurements_pygal.html'
2828
graph = get_stacked_bar()
2929

3030
# returns a page with the execution times per version
3131
elif index == 2:
32-
page = 'measurements/endpoint_plotly.html'
32+
page = 'measurements/measurements_plotly.html'
3333
graph = get_boxplot_per_version()
3434

3535
# returns a page with the execution time per endpoint
3636
elif index == 3:
37-
page = 'measurements/endpoint_plotly.html'
37+
page = 'measurements/measurements_plotly.html'
3838
graph = get_boxplot_per_endpoint()
3939

4040
# default: return a page with a heatmap of number of requests
4141
else:
4242
index = 0
43-
page = 'measurements/endpoint_plotly.html'
43+
page = 'measurements/measurements_plotly.html'
4444
graph = get_heatmap(end=None)
4545

4646
return render_template(page, link=config.link, curr=2, times=get_times(),

dashboard/routings/result.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import plotly
55
import plotly.graph_objs as go
66
import pygal
7-
from flask import session, url_for, render_template
7+
from flask import session, url_for, render_template, request
88
from flask_wtf import FlaskForm
99
from werkzeug.routing import BuildError
1010
from wtforms import SelectMultipleField, SubmitField
@@ -18,7 +18,7 @@
1818
from dashboard.routings.measurements import get_heatmap
1919

2020

21-
@blueprint.route('/result/<end>/<int:index>')
21+
@blueprint.route('/result/<end>/<int:index>', methods=['GET', 'POST'])
2222
@secure
2323
def result(end, index=0):
2424
rule = get_monitor_rule(end)
@@ -36,13 +36,15 @@ def result(end, index=0):
3636

3737
# returns a page with the time per version per user
3838
elif index == 3:
39-
page = 'endpoint/endpoint_pygal.html'
40-
graph, _ = get_time_per_version_per_user(end, get_versions(end))
39+
graph, form = get_time_per_version_per_user(end, get_versions(end))
40+
return render_template('endpoint/endpoint_with_selection.html', link=config.link, session=session, rule=rule,
41+
url=url, graph=graph, end=end, index=index, form=form)
4142

4243
# returns a page with the time per version per ip
4344
elif index == 4:
44-
page = 'endpoint/endpoint_pygal.html'
45-
graph, _ = get_time_per_version_per_ip(end, get_versions(end))
45+
graph, form = get_time_per_version_per_ip(end, get_versions(end))
46+
return render_template('endpoint/endpoint_with_selection.html', link=config.link, session=session, rule=rule,
47+
url=url, graph=graph, end=end, index=index, form=form)
4648

4749
# returns a page with the time per version
4850
elif index == 5:
@@ -150,20 +152,22 @@ def get_time_per_version_per_user(end, versions):
150152
for v in versions:
151153
user_data[d][v.version] = 0
152154

153-
# create a form to select several users
155+
# create a form to select users
154156
choices = []
155157
for d in list(user_data):
156158
choices.append((d, d))
157-
print(choices)
158159

159-
class UserForm(FlaskForm):
160-
users = SelectMultipleField(
160+
class SelectionForm(FlaskForm):
161+
selection = SelectMultipleField(
161162
'Pick Things!',
162163
choices=choices,
163164
)
164165
submit = SubmitField('Render graph')
165166

166-
user_form = UserForm()
167+
form = SelectionForm(request.form)
168+
selection = []
169+
if request.method == 'POST':
170+
selection = [str(item) for item in form.data['selection']]
167171

168172
# fill the rows with data
169173
for d in get_endpoint_results(end, FunctionCall.group_by):
@@ -176,10 +180,12 @@ class UserForm(FlaskForm):
176180
# add rows to the charts
177181
for d in [str(c.group_by) for c in get_endpoint_column(end, FunctionCall.group_by)]:
178182
data = []
179-
for v in versions:
180-
data.append(user_data[d][v.version])
181-
graph.add(d, data, formatter=formatter)
182-
return graph.render_data_uri(), user_form
183+
# render full graph if no selection is made, else render only the users that are selected
184+
if selection == [] or d in selection:
185+
for v in versions:
186+
data.append(user_data[d][v.version])
187+
graph.add(d, data, formatter=formatter)
188+
return graph.render_data_uri(), form
183189

184190

185191
def get_time_per_version_per_ip(end, versions):
@@ -189,20 +195,22 @@ def get_time_per_version_per_ip(end, versions):
189195
for v in versions:
190196
ip_data[d][v.version] = 0
191197

192-
# create a form to select several ips
198+
# create a form to select users
193199
choices = []
194200
for d in list(ip_data):
195201
choices.append((d, d))
196-
print(choices)
197202

198-
class UserForm(FlaskForm):
199-
users = SelectMultipleField(
203+
class SelectionForm(FlaskForm):
204+
selection = SelectMultipleField(
200205
'Pick Things!',
201206
choices=choices,
202207
)
203208
submit = SubmitField('Render graph')
204209

205-
user_form = UserForm()
210+
form = SelectionForm(request.form)
211+
selection = []
212+
if request.method == 'POST':
213+
selection = [str(item) for item in form.data['selection']]
206214

207215
# fill the rows with data
208216
for d in get_endpoint_results(end, FunctionCall.ip):
@@ -215,10 +223,12 @@ class UserForm(FlaskForm):
215223
# add rows to the charts
216224
for d in [str(c.ip) for c in get_endpoint_column(end, FunctionCall.ip)]:
217225
data = []
218-
for v in versions:
219-
data.append(ip_data[d][v.version])
220-
graph.add(d, data, formatter=formatter)
221-
return graph.render_data_uri(), user_form
226+
# render full graph if no selection is made, else render only the users that are selected
227+
if selection == [] or d in selection:
228+
for v in versions:
229+
data.append(ip_data[d][v.version])
230+
graph.add(d, data, formatter=formatter)
231+
return graph.render_data_uri(), form
222232

223233

224234
def get_time_per_version(end, versions):

dashboard/templates/endpoint/endpoint_pygal.html renamed to dashboard/templates/endpoint/endpoint_with_selection.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{% extends "endpoint/endpoint_base.html" %}
22
{% block graph_content %}
3+
<br />
4+
<form action="#" method="post">
5+
{{ form.selection(style="width: 200px; height: 300px;") }}
6+
<br />
7+
{{ form.submit }}
8+
</form>
39
<div class="col-md-12 col-sm-12">
410
<embed type="image/svg+xml" src={{ graph|safe }}></embed>
511
</div>

0 commit comments

Comments
 (0)