Exemplo n.º 1
0
        def aggregate_filter_decorated_function(*args, **kwargs):

            def incremental_filter(result, record, param_id):
                result[record[param_id]]['metric'] += 1

            def loc_filter(result, record, param_id):
                result[record[param_id]]['metric'] += record['loc']

            def mark_filter(result, record, param_id):
                value = record['value']
                result_by_param = result[record[param_id]]
                result_by_param['metric'] += 1

                if value in result_by_param:
                    result_by_param[value] += 1
                else:
                    result_by_param[value] = 1

            def mark_finalize(record):
                new_record = {}
                for key in ['id', 'metric', 'name']:
                    new_record[key] = record[key]

                positive = 0
                mark_distribution = []
                for key in [-2, -1, 1, 2]:
                    if key in record:
                        if key in [1, 2]:
                            positive += record[key]
                        mark_distribution.append(str(record[key]))
                    else:
                        mark_distribution.append('0')

                new_record['mark_ratio'] = (
                    '|'.join(mark_distribution) +
                    ' (%.1f%%)' % ((positive * 100.0) / record['metric']))
                return new_record

            metric_param = (flask.request.args.get('metric') or
                            parameters.get_default('metric'))
            metric = metric_param.lower()

            metric_to_filters_map = {
                'commits': (incremental_filter, None),
                'loc': (loc_filter, None),
                'marks': (mark_filter, mark_finalize),
                'tm_marks': (mark_filter, mark_finalize),
                'emails': (incremental_filter, None),
                'bpd': (incremental_filter, None),
                'bpc': (incremental_filter, None),
            }
            if metric not in metric_to_filters_map:
                metric = parameters.get_default('metric')

            kwargs['metric_filter'] = metric_to_filters_map[metric][0]
            kwargs['finalize_handler'] = metric_to_filters_map[metric][1]
            return f(*args, **kwargs)
Exemplo n.º 2
0
        def templated_decorated_function(*args, **kwargs):

            vault_inst = vault.get_vault()
            template_name = template
            if template_name is None:
                template_name = (flask.request.endpoint.replace('.', '/') +
                                 '.html')
            ctx = f(*args, **kwargs)
            if ctx is None:
                ctx = {}

            # put parameters into template
            metric = flask.request.args.get('metric')
            if metric not in parameters.METRIC_LABELS:
                metric = None
            ctx['metric'] = metric or parameters.get_default('metric')
            ctx['metric_label'] = parameters.METRIC_LABELS[ctx['metric']]

            project_type = flask.request.args.get('project_type')
            if not vault.is_project_type_valid(project_type):
                project_type = parameters.get_default('project_type')
            ctx['project_type'] = project_type

            release = flask.request.args.get('release')
            releases = vault_inst['releases']
            if release:
                release = release.lower()
                if release != 'all':
                    if release not in releases:
                        release = None
                    else:
                        release = releases[release]['release_name']
            ctx['release'] = (release or
                              parameters.get_default('release')).lower()
            ctx['review_nth'] = (flask.request.args.get('review_nth') or
                                 parameters.get_default('review_nth'))

            ctx['project_type_options'] = vault.get_project_type_options()
            ctx['release_options'] = vault.get_release_options()
            ctx['metric_options'] = sorted(parameters.METRIC_LABELS.items(),
                                           key=lambda x: x[0])

            ctx['company'] = parameters.get_single_parameter(kwargs, 'company')
            ctx['company_original'] = (
                vault.get_memory_storage().get_original_company_name(
                    ctx['company']))
            ctx['module'] = parameters.get_single_parameter(kwargs, 'module')
            ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id')
            ctx['page_title'] = helpers.make_page_title(
                ctx['company'], ctx['user_id'], ctx['module'], ctx['release'])
            ctx['stackalytics_version'] = (
                stackalytics_version.version_info.version_string())
            ctx['stackalytics_release'] = (
                stackalytics_version.version_info.release_string())

            return flask.render_template(template_name, **ctx), return_code
Exemplo n.º 3
0
def get_metrics_json(**kwargs):
    return (
        sorted(
            [{"id": m, "text": t} for m, t in six.iteritems(parameters.METRIC_LABELS)], key=operator.itemgetter("text")
        ),
        parameters.get_default("metric"),
    )
Exemplo n.º 4
0
def get_project_type_json(project_type):
    if project_type != 'all':
        for pt, groups in vault.get_project_type_options().iteritems():
            if (project_type == pt) or (project_type in groups):
                break
        else:
            project_type = parameters.get_default('project_type')

    return {'id': project_type, 'text': project_type}
Exemplo n.º 5
0
def get_project_type_json(project_type):
    if project_type != "all":
        for pt, groups in vault.get_project_type_options().iteritems():
            if (project_type == pt) or (project_type in groups):
                break
        else:
            project_type = parameters.get_default("project_type")

    return {"id": project_type, "text": project_type}
Exemplo n.º 6
0
        def aggregate_filter_decorated_function(*args, **kwargs):

            metric_param = (flask.request.args.get('metric') or
                            parameters.get_default('metric'))
            metric = metric_param.lower()

            metric_to_filters_map = {
                'commits': (incremental_filter, None),
                'loc': (loc_filter, None),
                'marks': (mark_filter, mark_finalize),
                'tm_marks': (mark_filter, mark_finalize),
                'emails': (incremental_filter, None),
                'bpd': (incremental_filter, None),
                'bpc': (incremental_filter, None),
            }
            if metric not in metric_to_filters_map:
                metric = parameters.get_default('metric')

            kwargs['metric_filter'] = metric_to_filters_map[metric][0]
            kwargs['finalize_handler'] = metric_to_filters_map[metric][1]
            return f(*args, **kwargs)
Exemplo n.º 7
0
def get_release_json(release):
    if release != 'all':
        if release not in vault.get_vault()['releases']:
            release = parameters.get_default('release')

    return {'id': release, 'text': release.capitalize()}
Exemplo n.º 8
0
def get_project_types_json(**kwargs):
    return ([{'id': pt['id'], 'text': pt['title'],
             'child': pt.get('child', False)}
             for pt in vault.get_project_types()],
            parameters.get_default('project_type'))
Exemplo n.º 9
0
def get_metrics_json(**kwargs):
    return (sorted([{'id': m, 'text': t} for m, t in
                    six.iteritems(parameters.METRIC_LABELS)],
                   key=operator.itemgetter('text')),
            parameters.get_default('metric'))
Exemplo n.º 10
0
def get_releases_json(**kwargs):
    return ([{'id': r['release_name'], 'text': r['release_name'].capitalize()}
            for r in vault.get_release_options()],
            parameters.get_default('release'))
Exemplo n.º 11
0
def get_metric_json(metric):
    if metric not in parameters.METRIC_LABELS:
        metric = parameters.get_default("metric")
    return {"id": metric, "text": parameters.METRIC_LABELS[metric]}
Exemplo n.º 12
0
def get_project_types_json(**kwargs):
    return (
        [{"id": pt["id"], "text": pt["title"], "child": pt.get("child", False)} for pt in vault.get_project_types()],
        parameters.get_default("project_type"),
    )
Exemplo n.º 13
0
def get_releases_json(**kwargs):
    return (
        [{"id": r["release_name"], "text": r["release_name"].capitalize()} for r in vault.get_release_options()],
        parameters.get_default("release"),
    )
Exemplo n.º 14
0
        def aggregate_filter_decorated_function(*args, **kwargs):

            def incremental_filter(result, record, param_id):
                result[record[param_id]]['metric'] += 1

            def loc_filter(result, record, param_id):
                result[record[param_id]]['metric'] += record['loc']

            def mark_filter(result, record, param_id):
                result_by_param = result[record[param_id]]
                if record['type'] == 'APRV':
                    value = 'A'
                else:
                    value = record['value']
                    result_by_param['metric'] += 1
                result_by_param[value] = result_by_param.get(value, 0) + 1

                if record.get('x'):
                    result_by_param['disagreements'] = (
                        result_by_param.get('disagreements', 0) + 1)

            def mark_finalize(record):
                new_record = record.copy()

                positive = 0
                mark_distribution = []
                for key in [-2, -1, 1, 2, 'A']:
                    if key in record:
                        if key in [1, 2]:
                            positive += record[key]
                        mark_distribution.append(str(record[key]))
                    else:
                        mark_distribution.append('0')
                        new_record[key] = 0

                positive_ratio = ' (%.1f%%)' % (
                    (positive * 100.0) / record['metric'])
                new_record['mark_ratio'] = (
                    '|'.join(mark_distribution) + positive_ratio)
                new_record['positive_ratio'] = positive_ratio
                new_record['disagreements'] = record.get('disagreements', 0)
                new_record['disagreement_ratio'] = '%.1f%%' % (
                    (record.get('disagreements', 0) * 100.0) / record['metric']
                )
                return new_record

            metric_param = (flask.request.args.get('metric') or
                            parameters.get_default('metric'))
            metric = metric_param.lower()

            metric_to_filters_map = {
                'commits': (incremental_filter, None),
                'loc': (loc_filter, None),
                'marks': (mark_filter, mark_finalize),
                'tm_marks': (mark_filter, mark_finalize),
                'emails': (incremental_filter, None),
                'bpd': (incremental_filter, None),
                'bpc': (incremental_filter, None),
            }
            if metric not in metric_to_filters_map:
                metric = parameters.get_default('metric')

            kwargs['metric_filter'] = metric_to_filters_map[metric][0]
            kwargs['finalize_handler'] = metric_to_filters_map[metric][1]
            return f(*args, **kwargs)
Exemplo n.º 15
0
def get_metric_json(metric):
    if metric not in parameters.METRIC_LABELS:
        metric = parameters.get_default('metric')
    return {'id': metric, 'text': parameters.METRIC_LABELS[metric]}
Exemplo n.º 16
0
def get_project_type_json(project_type):
    if not vault.is_project_type_valid(project_type):
        project_type = parameters.get_default('project_type')

    pt = vault.get_project_type(project_type)
    return {'id': pt['id'], 'text': pt['title']}
Exemplo n.º 17
0
def get_release_json(release):
    if release != "all":
        if release not in vault.get_vault()["releases"]:
            release = parameters.get_default("release")

    return {"id": release, "text": release.capitalize()}