Esempio n. 1
0
def show(metric_name, start_timestamp, end_timestamp):
    start_timestamp = int(start_timestamp)
    end_timestamp = int(end_timestamp)

    metric_changes = sorted(
        logic.get_major_changes_for_metric(
            flask.g.db,
            start_timestamp,
            end_timestamp,
            metric_name,
        ))
    metric_changes = [(datetime.datetime.fromtimestamp(timestamp).strftime(
        '%Y-%m-%d %H:%M:%S', ), sha,
                       CommitDeltaPresenter.from_data(
                           metric_name,
                           DeltaPresenter('javascript:;', value),
                       )) for timestamp, sha, value in metric_changes]

    override_classname = ('color-override' if metric_name
                          in metric_config.color_overrides else '')

    rendered_template = render_template(
        'changes.mako',
        changes=metric_changes,
        override_classname=override_classname,
    )

    return simplejson.dumps({'body': rendered_template})
Esempio n. 2
0
def show(metric_name, start_timestamp, end_timestamp):
    start_timestamp = int(start_timestamp)
    end_timestamp = int(end_timestamp)

    metric_changes = sorted(logic.get_major_changes_for_metric(
        flask.g.db, start_timestamp, end_timestamp, metric_name,
    ))
    metric_changes = [
        (
            datetime.datetime.fromtimestamp(timestamp).strftime(
                '%Y-%m-%d %H:%M:%S',
            ),
            sha,
            CommitDeltaPresenter.from_data(
                metric_name,
                DeltaPresenter('javascript:;', value),
            )
        )
        for timestamp, sha, value in metric_changes
    ]

    override_classname = (
        'color-override'
        if metric_name in metric_config.color_overrides
        else ''
    )

    rendered_template = render_template(
        'changes.mako',
        changes=metric_changes,
        override_classname=override_classname,
    )

    return simplejson.dumps({'body': rendered_template})
Esempio n. 3
0
def data():
    metric_names = set(widget_metrics)
    diff = flask.request.form['diff'].encode('UTF-8')

    metric_config = GenerateOptions.from_yaml(
        yaml.load(io.open('generate_config.yaml').read()), )
    parsers = get_metric_parsers_from_args(
        metric_config.metric_package_names,
        skip_defaults=False,
    )
    metrics = get_metrics(diff, parsers)
    metrics = [
        metric for metric in metrics
        if metric.value and metric.name in metric_names
    ]

    commit_deltas = sorted([
        CommitDeltaPresenter.from_data(
            metric.name,
            DeltaPresenter('javascript:;', metric.value),
        ) for metric in metrics
    ])
    return simplejson.dumps({
        'metrics':
        render_template('widget.mako', commit_deltas=commit_deltas)
    })
Esempio n. 4
0
def data():
    metric_names = set(widget_metrics)
    diff = flask.request.form['diff'].encode('UTF-8')

    metric_config = GenerateOptions.from_yaml(
        yaml.load(io.open('generate_config.yaml').read()),
    )
    parsers = get_metric_parsers_from_args(
        metric_config.metric_package_names, skip_defaults=False,
    )
    metrics = get_metrics(diff, parsers)
    metrics = [
        metric for metric in metrics
        if metric.value and metric.name in metric_names
    ]

    commit_deltas = sorted([
        CommitDeltaPresenter.from_data(
            metric.name, DeltaPresenter('javascript:;', metric.value),
        )
        for metric in metrics
    ])
    return simplejson.dumps({
        'metrics': render_template('widget.mako', commit_deltas=commit_deltas)
    })
Esempio n. 5
0
def test_commit_delta_presenter_with_overrides():
    assert 'ColorOverrideMetric' in metric_config.color_overrides
    presenter = CommitDeltaPresenter.from_data(
        'ColorOverrideMetric',
        mock.sentinel.delta,
    )
    assert presenter == CommitDeltaPresenter(
        'ColorOverrideMetric',
        'color-override',
        mock.sentinel.delta,
    )
Esempio n. 6
0
def test_commit_delta_presenter_not_overriden():
    assert 'MyMetric' not in metric_config.color_overrides
    presenter = CommitDeltaPresenter.from_data(
        'MyMetric',
        mock.sentinel.delta,
    )
    assert presenter == CommitDeltaPresenter(
        'MyMetric',
        '',
        mock.sentinel.delta,
    )
Esempio n. 7
0
def show(sha):
    changes = logic.get_metric_changes(flask.g.db, sha)

    commit_deltas = sorted(
        [
            CommitDeltaPresenter.from_data(metric_name, DeltaPresenter("javascript:;", change))
            for metric_name, change in changes
        ]
    )

    links = [(link_name, link.format(sha=sha)) for link_name, link in metric_config.commit_links]

    return render_template("commit.mako", sha=sha, short_sha=sha[:8], commit_deltas=commit_deltas, links=links)
Esempio n. 8
0
def show(sha):
    changes = logic.get_metric_changes(flask.g.db, sha)

    commit_deltas = sorted([
        CommitDeltaPresenter.from_data(
            metric_name, DeltaPresenter('javascript:;', change),
        )
        for metric_name, change in changes
    ])

    links = [
        (link_name, link.format(sha=sha))
        for link_name, link in metric_config.commit_links
    ]

    return render_template(
        'commit.mako',
        sha=sha,
        short_sha=sha[:8],
        commit_deltas=commit_deltas,
        links=links,
    )
def test_commit_delta_presenter_with_overrides():
    assert "ColorOverrideMetric" in metric_config.color_overrides
    presenter = CommitDeltaPresenter.from_data("ColorOverrideMetric", mock.sentinel.delta)
    assert presenter == CommitDeltaPresenter("ColorOverrideMetric", "color-override", mock.sentinel.delta)
def test_commit_delta_presenter_not_overriden():
    assert "MyMetric" not in metric_config.color_overrides
    presenter = CommitDeltaPresenter.from_data("MyMetric", mock.sentinel.delta)
    assert presenter == CommitDeltaPresenter("MyMetric", "", mock.sentinel.delta)