Skip to content

Commit

Permalink
small improvement for reducing the complexity of the graphs:
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingBird95 committed Apr 26, 2018
1 parent ed1db99 commit 2a2e264
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
11 changes: 11 additions & 0 deletions flask_monitoringdashboard/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pkg_resources
from flask import url_for
from werkzeug.routing import BuildError
import numpy as np

from flask_monitoringdashboard import config
from flask_monitoringdashboard.database.endpoint import get_monitor_rule
Expand Down Expand Up @@ -52,3 +53,13 @@ def get_url(end):
return url_for(end)
except BuildError:
return None


def simplify(values, n=5):
"""
Simplify a list of values. It returns a list that is representative for the input
:param values: list of values
:param n: length of the returned list
:return: list with n values: min, q1, median, q3, max
"""
return [np.percentile(values, i * 100 // (n-1)) for i in range(n)]
3 changes: 2 additions & 1 deletion flask_monitoringdashboard/views/dashboard/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask_monitoringdashboard import blueprint
from flask_monitoringdashboard.core.auth import secure
from flask_monitoringdashboard.core.plot import get_layout, get_figure, boxplot, get_margin
from flask_monitoringdashboard.core.utils import simplify
from flask_monitoringdashboard.database.function_calls import get_endpoints, get_data_per_endpoint

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

layout = get_layout(
height=350 + 40 * len(endpoints),
Expand Down
2 changes: 1 addition & 1 deletion flask_monitoringdashboard/views/dashboard/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_stacked_bar(form):
showlegend=True,
title=TITLE,
xaxis={'title': 'Number of requests'},
yaxis={'autorange': 'reversed'}
yaxis={'type': 'category', 'autorange': 'reversed'}
)

return get_figure(layout=layout, data=data)
5 changes: 3 additions & 2 deletions flask_monitoringdashboard/views/dashboard/versions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import render_template

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

layout = get_layout(
height=350 + 40 * len(versions),
title=TITLE,
xaxis={'title': 'Execution time (ms)'},
yaxis={'autorange': 'reversed'},
yaxis={'type': 'category', 'autorange': 'reversed'},
margin=get_margin()
)
return get_figure(layout=layout, data=data)

0 comments on commit 2a2e264

Please sign in to comment.