def get_boxplot_endpoints(endpoint=None, form=None): """ Generates a box plot visualization for the unit test endpoint hits performance results. :param endpoint: if specified, generate box plot for a specific endpoint, otherwise, generate for all tests :param form: the form that can be used for showing a subset of the data :return: """ trace = [] with session_scope() as db_session: if form: ids = get_travis_builds(db_session, limit=form.get_slider_value()) else: ids = get_travis_builds(db_session) if not ids: return None for id in ids: if endpoint: values = get_endpoint_measurements_job(db_session, name=endpoint, job_id=id) else: values = get_endpoint_measurements(db_session, suite=id) trace.append(boxplot(values=values, label='{} -'.format(id))) layout = get_layout(xaxis={'title': 'Execution time (ms)'}, yaxis={ 'title': 'Travis Build', 'autorange': 'reversed' }) return get_figure(layout=layout, data=trace)
def get_boxplot_tests(form=None): """ Generates a box plot visualization for the unit test performance results. :param form: the form that can be used for showing a subset of the data :return: """ trace = [] with session_scope() as db_session: if form: suites = get_test_suites(db_session, limit=form.get_slider_value()) else: suites = get_test_suites(db_session) if not suites: return None for s in suites: values = get_suite_measurements(db_session, suite=s) trace.append(boxplot(values=values, label='{} -'.format(s))) layout = get_layout(xaxis={'title': 'Execution time (ms)'}, yaxis={ 'title': 'Travis Build', 'autorange': 'reversed' }) return get_figure(layout=layout, data=trace)
def endpoint_graph(): """ Creates a graph with the execution times per endpoint :return: """ with session_scope() as db_session: data = get_endpoint_data_grouped(db_session, lambda x: simplify(x, 10)) values = [ boxplot(get_value(data, end.id, default=[]), name=end.name) for end in get_endpoints(db_session) ] layout = get_layout(height=350 + 40 * len(values), xaxis={'title': 'Execution time (ms)'}, margin=get_margin()) return get_figure(layout, values)
def version_ip_graph(db_session, endpoint_id, form): """ :param db_session: session for the database :param endpoint_id: the endpoint to filter the data on :param form: form for reducing the size of the graph :return: an HTML bubble plot """ users = get_ips(db_session, endpoint_id, form.get_slider_value(0)) versions = get_versions(db_session, endpoint_id, form.get_slider_value(1)) first_request = get_first_requests(db_session, endpoint_id) values = get_two_columns_grouped(db_session, Request.ip, Request.endpoint_id == endpoint_id) data = [[get_value(values, (user, v)) for v in versions] for user in users] average = get_average_bubble_size(data) trace = [ scatter(x=[ format_version(v, get_value(first_request, v)) for v in versions ], hovertext=[ 'Time: {:,.1f}ms'.format(data[i][j]) for j in range(len(versions)) ], y=[users[i]] * len(versions), name=users[i], mode='markers', marker={ 'color': [get_color(users[i])] * len(versions), 'size': [math.sqrt(d) for d in data[i]], 'sizeref': average, 'sizemode': 'area' }) for i in range(len(users)) ] layout = get_layout(height=350 + 40 * len(trace), xaxis={ 'title': 'Versions', 'type': 'category' }, yaxis={ 'title': 'IP-addresses', 'type': 'category', 'autorange': 'reversed' }, margin=get_margin(b=200)) return get_figure(layout, trace)
def version_usage_graph(db_session, form): """ Used for getting a Heatmap with an overview of which endpoints are used in which versions :param db_session: session for the database :param form: instance of SliderForm :return: """ endpoints = get_endpoints(db_session) versions = get_versions(db_session, limit=form.get_slider_value()) requests = [ count_requests_group(db_session, Request.version_requested == v) for v in versions ] total_hits = [] hits = [[]] * len(endpoints) for hits_version in requests: total_hits.append(max(1, sum([value for key, value in hits_version]))) for j in range(len(endpoints)): hits[j] = [0] * len(versions) for i in range(len(versions)): hits[j][i] = get_value(requests[i], endpoints[j].id) * 100 / total_hits[i] layout = get_layout(xaxis={ 'title': 'Versions', 'type': 'category' }, yaxis={ 'type': 'category', 'autorange': 'reversed' }, margin=get_margin()) trace = heatmap(z=hits, x=versions, y=['{} '.format(e.name) for e in endpoints], colorbar={ 'titleside': 'top', 'tickmode': 'array', }) return get_figure(layout=layout, data=[trace])
def users_graph(id, form): """ Return an HTML box plot with a specific number of :param id: get the data for this endpoint only :param form: instance of SliderForm :return: """ with session_scope() as db_session: users = get_users(db_session, id, form.get_slider_value()) times = get_user_data_grouped(db_session, lambda x: simplify(x, 10), Request.endpoint_id == id) data = [boxplot(name=u, values=get_value(times, u)) for u in users] layout = get_layout(height=350 + 40 * len(data), xaxis={'title': 'Execution time (ms)'}, yaxis={ 'type': 'category', 'title': 'User' }) return get_figure(layout, data)
def requests_graph(form): """ Returns a horizontal box plot with the number of requests per day. :param form: must be the form that is obtained by get_daterange_form :return: """ days = form.get_days() with session_scope() as db_session: hits = count_requests_per_day(db_session, days) data = [barplot(x=[get_value(hits_day, end.id) for hits_day in hits], y=days, name=end.name) for end in get_endpoints(db_session)] layout = get_layout( barmode='stack', height=350 + 40 * len(days), showlegend=True, xaxis={'title': 'Number of requests'}, yaxis={'type': 'category'} ) return get_figure(layout=layout, data=data)
def hourly_load_graph(form, endpoint_id=None): """ Return HTML string for generating a Heatmap. :param form: A SelectDateRangeForm, which is used to filter the selection :param endpoint_id: optionally, filter the data on a specific endpoint :return: HTML code with the graph """ # list of hours: 0:00 - 23:00 hours = ['0{}:00'.format(h) for h in range(0, 10) ] + ['{}:00'.format(h) for h in range(10, 24)] days = form.get_days() # create empty 2D-list: [hour][day] heatmap_data = numpy.zeros((len(hours), len(days))) # add data from database to heatmap_data start_datetime = to_utc_datetime( datetime.datetime.combine(form.start_date.data, datetime.time(0, 0, 0, 0))) end_datetime = to_utc_datetime( datetime.datetime.combine(form.end_date.data, datetime.time(23, 59, 59))) with session_scope() as db_session: for time, count in get_num_requests(db_session, endpoint_id, start_datetime, end_datetime): parsed_time = datetime.datetime.strptime(time, '%Y-%m-%d %H:%M:%S') day_index = (parsed_time - start_datetime).days hour_index = int(to_local_datetime(parsed_time).strftime('%H')) heatmap_data[hour_index][day_index] = count start_datetime = to_local_datetime(start_datetime - datetime.timedelta( days=1)).strftime('%Y-%m-%d 12:00:00') end_datetime = to_local_datetime( form.end_date.data).strftime('%Y-%m-%d 12:00:00') layout = get_layout(xaxis=go.XAxis(range=[start_datetime, end_datetime])) return get_figure(layout, [plot_heatmap(x=days, y=hours, z=heatmap_data)])
def versions_graph(db_session, endpoint_id, form): times = get_version_data_grouped(db_session, lambda x: simplify(x, 10), Request.endpoint_id == endpoint_id) first_requests = get_first_requests(db_session, endpoint_id, form.get_slider_value()) data = [ boxplot(name=format_version( request.version_requested, get_value(first_requests, request.version_requested)), values=get_value(times, request.version_requested), marker={'color': get_color(request.version_requested)}) for request in first_requests ] layout = get_layout(height=350 + 40 * len(first_requests), xaxis={'title': 'Execution time (ms)'}, yaxis={ 'type': 'category', 'title': 'Version', 'autorange': 'reversed' }, margin=get_margin()) return get_figure(layout=layout, data=data)