Skip to content

Commit 2a2e264

Browse files
committed
small improvement for reducing the complexity of the graphs:
1 parent ed1db99 commit 2a2e264

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

flask_monitoringdashboard/core/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pkg_resources
22
from flask import url_for
33
from werkzeug.routing import BuildError
4+
import numpy as np
45

56
from flask_monitoringdashboard import config
67
from flask_monitoringdashboard.database.endpoint import get_monitor_rule
@@ -52,3 +53,13 @@ def get_url(end):
5253
return url_for(end)
5354
except BuildError:
5455
return None
56+
57+
58+
def simplify(values, n=5):
59+
"""
60+
Simplify a list of values. It returns a list that is representative for the input
61+
:param values: list of values
62+
:param n: length of the returned list
63+
:return: list with n values: min, q1, median, q3, max
64+
"""
65+
return [np.percentile(values, i * 100 // (n-1)) for i in range(n)]

flask_monitoringdashboard/views/dashboard/endpoints.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from flask_monitoringdashboard import blueprint
44
from flask_monitoringdashboard.core.auth import secure
55
from flask_monitoringdashboard.core.plot import get_layout, get_figure, boxplot, get_margin
6+
from flask_monitoringdashboard.core.utils import simplify
67
from flask_monitoringdashboard.database.function_calls import get_endpoints, get_data_per_endpoint
78

89
TITLE = 'Global execution time for every endpoint'
@@ -25,7 +26,7 @@ def get_boxplot_per_endpoint():
2526
for endpoint in endpoints:
2627
values = [c.execution_time for c in get_data_per_endpoint(endpoint)]
2728
if values:
28-
data.append(boxplot(values, name=endpoint))
29+
data.append(boxplot(simplify(values, 10), name=endpoint))
2930

3031
layout = get_layout(
3132
height=350 + 40 * len(endpoints),

flask_monitoringdashboard/views/dashboard/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_stacked_bar(form):
3131
showlegend=True,
3232
title=TITLE,
3333
xaxis={'title': 'Number of requests'},
34-
yaxis={'autorange': 'reversed'}
34+
yaxis={'type': 'category', 'autorange': 'reversed'}
3535
)
3636

3737
return get_figure(layout=layout, data=data)

flask_monitoringdashboard/views/dashboard/versions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from flask import render_template
22

33
from flask_monitoringdashboard import blueprint
4+
from flask_monitoringdashboard.core.utils import simplify
45
from flask_monitoringdashboard.core.colors import get_color
56
from flask_monitoringdashboard.core.auth import secure
67
from flask_monitoringdashboard.core.plot import boxplot, get_layout, get_figure, get_margin
@@ -30,13 +31,13 @@ def get_boxplot_per_version():
3031
for version in versions:
3132
values = [c.execution_time for c in get_data_per_version(version)]
3233
name = "{} {}".format(version, get_date_first_request(version).strftime("%b %d %H:%M"))
33-
data.append(boxplot(name=name, values=values, marker={'color': get_color(version)}))
34+
data.append(boxplot(name=name, values=simplify(values, 10), marker={'color': get_color(version)}))
3435

3536
layout = get_layout(
3637
height=350 + 40 * len(versions),
3738
title=TITLE,
3839
xaxis={'title': 'Execution time (ms)'},
39-
yaxis={'autorange': 'reversed'},
40+
yaxis={'type': 'category', 'autorange': 'reversed'},
4041
margin=get_margin()
4142
)
4243
return get_figure(layout=layout, data=data)

0 commit comments

Comments
 (0)