def ips(endpoint_id): """ :param endpoint_id: integer :return: A JSON-list with all IP-addresses of a specific endpoint (ip represented by a string) """ with session_scope() as session: ips_hits = get_ips(session, endpoint_id) dicts = [] for ih in ips_hits: dicts.append({'ip': ih[0], 'hits': ih[1]}) return jsonify(dicts)
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)