Exemple #1
0
 def test_get_versions(self):
     """
         Test whether the function returns the right values.
     """
     from flask_monitoringdashboard import config
     from flask_monitoringdashboard.database.versions import get_versions
     with session_scope() as db_session:
         result = get_versions(db_session)
         self.assertEqual(len(result), 1)
         self.assertEqual(result[0], config.version)
Exemple #2
0
def versions(endpoint_id=None):
    """
    :param endpoint_id: integer
    :return: A JSON-list with all versions of a specific endpoint (version represented by a string)
    """
    with session_scope() as db_session:
        version_dates = get_versions(db_session, endpoint_id)
        dicts = []
        for vt in version_dates:
            dicts.append({'version': vt[0], 'date': vt[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)
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])
Exemple #5
0
def test_get_versions(session, request_1):
    for version, first_request in get_versions(session):
        if version == request_1.version_requested:
            assert first_request == request_1.time_requested
            return
    assert False, "Shouldn't reach here"