예제 #1
0
def company_activity(company):
    memory_storage_inst = vault.get_memory_storage()
    original_name = memory_storage_inst.get_original_company_name(company)

    memory_storage_inst = vault.get_memory_storage()
    records = memory_storage_inst.get_records(
        memory_storage_inst.get_record_ids_by_companies([original_name]))
    records = sorted(records, key=operator.itemgetter('date'), reverse=True)

    return {
        'company_name': original_name,
        'total_records': len(records),
        'contribution': helpers.get_contribution_summary(records),
        'punch_card_data': _get_punch_card_data(records),
    }
예제 #2
0
def company_activity(company):
    memory_storage_inst = vault.get_memory_storage()
    original_name = memory_storage_inst.get_original_company_name(company)

    memory_storage_inst = vault.get_memory_storage()
    records = memory_storage_inst.get_records(
        memory_storage_inst.get_record_ids_by_companies([original_name]))
    records = sorted(records, key=operator.itemgetter('date'), reverse=True)

    return {
        'company_name': original_name,
        'total_records': len(records),
        'contribution': helpers.get_contribution_summary(records),
        'punch_card_data': _get_punch_card_data(records),
    }
예제 #3
0
def blueprint_summary(module, blueprint_name):
    blueprint_id = utils.get_blueprint_id(module, blueprint_name)
    bpd = vault.get_memory_storage().get_record_by_primary_key(
        'bpd:' + blueprint_id)
    if not bpd:
        flask.abort(404)
        return

    bpd = helpers.extend_record(bpd)
    record_ids = vault.get_memory_storage().get_record_ids_by_blueprint_ids(
        [blueprint_id])
    activity = [helpers.extend_record(record) for record in
                vault.get_memory_storage().get_records(record_ids)]
    activity.sort(key=lambda x: x['date'], reverse=True)

    return {'blueprint': bpd, 'activity': activity}
예제 #4
0
def get_modules_json(record_ids, **kwargs):
    module_id_index = vault.get_vault()['module_id_index']

    tags = parameters.get_parameter({}, 'tag', 'tags')

    # all modules mentioned in records
    module_ids = vault.get_memory_storage().get_index_keys_by_record_ids(
        'module', record_ids)

    add_modules = set([])
    for module in six.itervalues(module_id_index):
        if set(module['modules']) & module_ids:
            add_modules.add(module['id'])
    module_ids |= add_modules

    # keep only modules with specified tags
    if tags:
        module_ids = set(module_id for module_id in module_ids
                         if ((module_id in module_id_index) and
                             (module_id_index[module_id].get('tag') in tags)))

    result = []
    for module_id in module_ids:
        module = module_id_index[module_id]
        result.append({'id': module['id'],
                       'text': module['module_group_name'],
                       'tag': module['tag']})

    return sorted(result, key=operator.itemgetter('text'))
예제 #5
0
def open_reviews(module):
    memory_storage_inst = vault.get_memory_storage()
    time_now = int(time.time())

    module_id_index = vault.get_vault()['module_id_index']
    module = module.lower()
    if module in module_id_index:
        modules = module_id_index[module]['modules']
    else:
        modules = [module]

    review_ids = (memory_storage_inst.get_record_ids_by_modules(modules) &
                  memory_storage_inst.get_record_ids_by_type('review'))

    waiting_on_reviewer = []
    total_open = 0

    for review in memory_storage_inst.get_records(review_ids):
        if review['status'] == 'NEW':
            total_open += 1
            if review['value'] in [1, 2]:
                waiting_on_reviewer.append(review)

    return {
        'module': module,
        'total_open': total_open,
        'waiting_on_reviewer': len(waiting_on_reviewer),
        'waiting_on_submitter': total_open - len(waiting_on_reviewer),
        'latest_revision': _process_stat(
            waiting_on_reviewer, 'updated_on', time_now),
        'first_revision': _process_stat(waiting_on_reviewer, 'date', time_now),
    }
예제 #6
0
파일: web.py 프로젝트: Mingkii/stackalytics
def get_engineers(records, metric_filter, finalize_handler):

    exclude = flask.request.args.get('exclude')
    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = vault.resolve_modules(modules_names)

    def filter_core_users(record):
        user = vault.get_user_from_runtime_storage(record['id'])
        is_core = False
        for (module, branch) in user['core']:
            if module in modules:
                is_core = branch
                if branch == 'master':  # we need master, but stables are ok
                    break

        if exclude:
            if ((exclude == 'non-core' and is_core) or
                    (exclude == 'core' and not is_core)):
                return record
        else:
            record['core'] = is_core
            return record

    return _get_aggregated_stats(records, metric_filter,
                                 vault.get_memory_storage().get_user_ids(),
                                 'user_id', 'author_name',
                                 finalize_handler=finalize_handler,
                                 postprocessing=filter_core_users)
예제 #7
0
def get_single_plus_two_reviews_report(records, **kwargs):
    memory_storage_inst = vault.get_memory_storage()
    plus_twos = collections.defaultdict(list)
    for record in records:
        if record['record_type'] != 'mark':
            continue

        if (record['branch'] == 'master' and
                record['type'] == 'Code-Review' and record['value'] == +2):
            review_id = record['review_id']
            review = memory_storage_inst.get_record_by_primary_key(review_id)
            if review and review['status'] == 'MERGED':
                plus_twos[review_id].append(record)

    response = []
    for review_id in plus_twos.keys():
        if len(plus_twos[review_id]) < 2:
            mark = plus_twos[review_id][0]
            review = memory_storage_inst.get_record_by_primary_key(
                mark['review_id'])
            response.append({'review_by': review['user_id'],
                             'mark_by': mark['user_id'],
                             'subject': review['subject'],
                             'url': review['url'],
                             'project': review['project']})

    return response
예제 #8
0
def blueprint_summary(module, blueprint_name):
    blueprint_id = utils.get_blueprint_id(module, blueprint_name)
    bpd = vault.get_memory_storage().get_record_by_primary_key(
        'bpd:' + blueprint_id)
    if not bpd:
        flask.abort(404)
        return

    bpd = helpers.extend_record(bpd)
    record_ids = vault.get_memory_storage().get_record_ids_by_blueprint_ids(
        [blueprint_id])
    activity = [helpers.extend_record(record) for record in
                vault.get_memory_storage().get_records(record_ids)]
    activity.sort(key=lambda x: x['date'], reverse=True)

    return {'blueprint': bpd, 'activity': activity}
예제 #9
0
파일: web.py 프로젝트: mohzah/spectrometer
def get_modules_json(record_ids, **kwargs):
    module_id_index = vault.get_vault()["module_id_index"]

    tags = parameters.get_parameter({}, "tag", "tags")

    # all modules mentioned in records
    module_ids = vault.get_memory_storage().get_index_keys_by_record_ids("module", record_ids)

    add_modules = set([])
    for module in six.itervalues(module_id_index):
        if set(module["modules"]) & module_ids:
            add_modules.add(module["id"])
    module_ids |= add_modules

    # keep only modules with specified tags
    if tags:
        module_ids = set(
            module_id
            for module_id in module_ids
            if ((module_id in module_id_index) and (module_id_index[module_id].get("tag") in tags))
        )

    result = []
    for module_id in module_ids:
        module = module_id_index[module_id]
        result.append({"id": module["id"], "text": module["module_group_name"], "tag": module["tag"]})

    return sorted(result, key=operator.itemgetter("text"))
예제 #10
0
def open_reviews(module):
    memory_storage_inst = vault.get_memory_storage()
    time_now = int(time.time())

    module_id_index = vault.get_vault()['module_id_index']
    module = module.lower()
    if module in module_id_index:
        modules = module_id_index[module]['modules']
    else:
        modules = [module]

    review_ids = (memory_storage_inst.get_record_ids_by_modules(modules) &
                  memory_storage_inst.get_record_ids_by_type('review'))

    waiting_on_reviewer = []
    total_open = 0

    for review in memory_storage_inst.get_records(review_ids):
        if review['status'] == 'NEW':
            total_open += 1
            if review['value'] in [1, 2]:
                waiting_on_reviewer.append(vault.extend_record(review))

    return {
        'module': module,
        'total_open': total_open,
        'waiting_on_reviewer': len(waiting_on_reviewer),
        'waiting_on_submitter': total_open - len(waiting_on_reviewer),
        'latest_revision': _process_stat(
            waiting_on_reviewer, 'updated_on', time_now),
        'first_revision': _process_stat(waiting_on_reviewer, 'date', time_now),
    }
예제 #11
0
파일: web.py 프로젝트: Mingkii/stackalytics
def get_engineers(records, metric_filter, finalize_handler):

    exclude = flask.request.args.get('exclude')
    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = vault.resolve_modules(modules_names)

    def filter_core_users(record):
        user = vault.get_user_from_runtime_storage(record['id'])
        is_core = False
        for (module, branch) in user['core']:
            if module in modules:
                is_core = branch
                if branch == 'master':  # we need master, but stables are ok
                    break

        if exclude:
            if ((exclude == 'non-core' and is_core)
                    or (exclude == 'core' and not is_core)):
                return record
        else:
            record['core'] = is_core
            return record

    return _get_aggregated_stats(records,
                                 metric_filter,
                                 vault.get_memory_storage().get_user_ids(),
                                 'user_id',
                                 'author_name',
                                 finalize_handler=finalize_handler,
                                 postprocessing=filter_core_users)
예제 #12
0
def get_single_plus_two_reviews_report(records):
    memory_storage_inst = vault.get_memory_storage()
    plus_twos = collections.defaultdict(list)
    for record in records:
        if record['record_type'] != 'mark':
            continue

        if (record['branch'] == 'master' and record['type'] == 'CRVW'
                and record['value'] == +2):
            review_id = record['review_id']
            review = memory_storage_inst.get_record_by_primary_key(review_id)
            if review and review['status'] == 'MERGED':
                plus_twos[review_id].append(record)

    response = []
    for review_id in plus_twos.keys():
        if len(plus_twos[review_id]) < 2:
            mark = plus_twos[review_id][0]
            review = memory_storage_inst.get_record_by_primary_key(
                mark['review_id'])
            response.append({
                'review_by': review['user_id'],
                'mark_by': mark['user_id'],
                'subject': review['subject'],
                'url': review['url'],
                'project': review['project']
            })

    return response
예제 #13
0
파일: web.py 프로젝트: mohzah/spectrometer
def get_companies(records, metric_filter, finalize_handler, **kwargs):
    return _get_aggregated_stats(
        records,
        metric_filter,
        vault.get_memory_storage().get_companies(),
        "company_name",
        finalize_handler=finalize_handler,
    )
예제 #14
0
파일: web.py 프로젝트: mohzah/spectrometer
def get_companies_json(record_ids, **kwargs):
    memory_storage = vault.get_memory_storage()
    companies = memory_storage.get_index_keys_by_record_ids("company_name", record_ids)
    if kwargs["_params"]["company"]:
        companies.add(kwargs["_params"]["company"][0])

    result = [memory_storage.get_original_company_name(company) for company in companies]

    return [{"id": utils.safe_encode(c.lower()), "text": c} for c in sorted(result)]
예제 #15
0
def get_engineers(records, metric_filter, finalize_handler):
    return _get_aggregated_stats(
        records,
        metric_filter,
        vault.get_memory_storage().get_user_ids(),
        "user_id",
        "author_name",
        finalize_handler=finalize_handler,
    )
예제 #16
0
def company_activity(company):
    memory_storage_inst = vault.get_memory_storage()
    original_name = memory_storage_inst.get_original_company_name(company)

    result = _get_activity_summary(
        memory_storage_inst.get_record_ids_by_companies([original_name]))
    result['company_name'] = original_name

    return result
예제 #17
0
def company_activity(company):
    memory_storage_inst = vault.get_memory_storage()
    original_name = memory_storage_inst.get_original_company_name(company)

    result = _get_activity_summary(
        memory_storage_inst.get_record_ids_by_companies([original_name]))
    result['company_name'] = original_name

    return result
예제 #18
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
예제 #19
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
예제 #20
0
def get_company(company_name):
    memory_storage_inst = vault.get_memory_storage()
    for company in memory_storage_inst.get_companies():
        if company.lower() == company_name.lower():
            return {
                'id': company_name,
                'text': memory_storage_inst.get_original_company_name(
                    company_name)
            }
    flask.abort(404)
예제 #21
0
def get_company(company_name):
    memory_storage_inst = vault.get_memory_storage()
    for company in memory_storage_inst.get_companies():
        if company.lower() == company_name.lower():
            return {
                'id': company_name,
                'text': memory_storage_inst.get_original_company_name(
                    company_name)
            }
    flask.abort(404)
예제 #22
0
파일: web.py 프로젝트: mohzah/spectrometer
def get_users_json(record_ids, **kwargs):
    user_ids = vault.get_memory_storage().get_index_keys_by_record_ids("user_id", record_ids)
    if kwargs["_params"]["user_id"]:
        user_ids.add(kwargs["_params"]["user_id"][0])

    result = [
        {"id": user_id, "text": (vault.get_user_from_runtime_storage(user_id)["user_name"])} for user_id in user_ids
    ]

    result.sort(key=lambda x: x["text"])
    return result
예제 #23
0
def user_activity(user_id):
    user = vault.get_user_from_runtime_storage(user_id)
    if not user:
        flask.abort(404)
    user = helpers.extend_user(user)

    memory_storage_inst = vault.get_memory_storage()
    result = _get_activity_summary(
        memory_storage_inst.get_record_ids_by_user_ids([user_id]))
    result['user'] = user

    return result
예제 #24
0
def get_users_json(record_ids, query_filter, **kwargs):
    user_ids = vault.get_memory_storage().get_index_keys_by_record_ids(
        'user_id', record_ids)

    result = []
    for user_id in user_ids:
        user_name = vault.get_user_from_runtime_storage(user_id)['user_name']
        if query_filter(user_name):
            result.append({'id': user_id, 'text': user_name})

    result.sort(key=lambda x: x['text'])
    return result
예제 #25
0
def user_activity(user_id):
    user = vault.get_user_from_runtime_storage(user_id)
    if not user:
        flask.abort(404)
    user = helpers.extend_user(user)

    memory_storage_inst = vault.get_memory_storage()
    result = _get_activity_summary(
        memory_storage_inst.get_record_ids_by_user_ids([user_id]))
    result['user'] = user

    return result
예제 #26
0
def get_companies_json(record_ids, query_filter, **kwargs):
    memory_storage = vault.get_memory_storage()
    companies = memory_storage.get_index_keys_by_record_ids(
        'company_name', record_ids)

    result = []
    for company in companies:
        if query_filter(company):
            result.append(memory_storage.get_original_company_name(company))

    return [{'id': utils.safe_encode(c.lower()), 'text': c}
            for c in sorted(result)]
예제 #27
0
def get_companies_json(record_ids, **kwargs):
    memory_storage = vault.get_memory_storage()
    companies = memory_storage.get_index_keys_by_record_ids(
        'company_name', record_ids)
    if kwargs['_params']['company']:
        companies.add(kwargs['_params']['company'][0])

    result = [memory_storage.get_original_company_name(company)
              for company in companies]

    return [{'id': utils.safe_encode(c.lower()), 'text': c}
            for c in sorted(result)]
예제 #28
0
def get_users_json(record_ids, **kwargs):
    user_ids = vault.get_memory_storage().get_index_keys_by_record_ids(
        'user_id', record_ids)
    if kwargs['_params']['user_id']:
        user_ids.add(kwargs['_params']['user_id'][0])

    result = [{'id': user_id,
               'text': (vault.get_user_from_runtime_storage(user_id)
                        ['user_name'])}
              for user_id in user_ids]

    result.sort(key=lambda x: x['text'])
    return result
예제 #29
0
def extend_record(record):
    record = record.copy()
    _extend_record_common_fields(record)

    if record['record_type'] == 'commit':
        record['branches'] = ','.join(record['branches'])
        if 'correction_comment' not in record:
            record['correction_comment'] = ''
        record['message'] = make_commit_message(record)
        if record['commit_date']:
            record['commit_date_str'] = format_datetime(record['commit_date'])
    elif record['record_type'] == 'mark':
        parent = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        if not parent:
            return None

        _extend_by_parent_info(record, parent)
    elif record['record_type'] == 'patch':
        parent = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        _extend_by_parent_info(record, parent)
    elif record['record_type'] == 'email':
        record['email_link'] = record.get('email_link') or ''
        record['blueprint_links'] = []
        for bp_id in record.get('blueprint_id', []):
            bp_module, bp_name = bp_id.split(':')
            record['blueprint_links'].append(
                make_blueprint_link(bp_module, bp_name))
    elif record['record_type'] in ['bpd', 'bpc']:
        record['summary'] = utils.format_text(record['summary'])
        if record.get('mention_count'):
            record['mention_date_str'] = format_datetime(
                record['mention_date'])
        record['blueprint_link'] = make_blueprint_link(record['module'],
                                                       record['name'])

    return record
예제 #30
0
def extend_record(record):
    record = record.copy()
    _extend_record_common_fields(record)

    if record['record_type'] == 'commit':
        record['branches'] = ','.join(record['branches'])
        if 'correction_comment' not in record:
            record['correction_comment'] = ''
        record['message'] = make_commit_message(record)
        if record['commit_date']:
            record['commit_date_str'] = format_datetime(record['commit_date'])
    elif record['record_type'] == 'mark':
        parent = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        if not parent:
            return None

        _extend_by_parent_info(record, parent)
    elif record['record_type'] == 'patch':
        parent = vault.get_memory_storage().get_record_by_primary_key(
            record['review_id'])
        _extend_by_parent_info(record, parent)
    elif record['record_type'] == 'email':
        record['email_link'] = record.get('email_link') or ''
        record['blueprint_links'] = []
        for bp_id in record.get('blueprint_id', []):
            bp_module, bp_name = bp_id.split(':')
            record['blueprint_links'].append(
                make_blueprint_link(bp_module, bp_name))
    elif record['record_type'] in ['bpd', 'bpc']:
        record['summary'] = utils.format_text(record['summary'])
        if record.get('mention_count'):
            record['mention_date_str'] = format_datetime(
                record['mention_date'])
        record['blueprint_link'] = make_blueprint_link(record['module'],
                                                       record['name'])

    return record
예제 #31
0
def _get_activity_summary(record_ids):
    memory_storage_inst = vault.get_memory_storage()

    types = ['mark', 'patch', 'email', 'bpd', 'bpc']
    record_ids_by_type = set()
    for t in types:
        record_ids_by_type |= memory_storage_inst.get_record_ids_by_type(t)

    record_ids &= record_ids_by_type
    punch_card_data = _get_punch_card_data(
        memory_storage_inst.get_records(record_ids))

    return {
        'punch_card_data': punch_card_data,
    }
예제 #32
0
def _get_activity_summary(record_ids):
    memory_storage_inst = vault.get_memory_storage()

    types = ['mark', 'patch', 'email', 'bpd', 'bpc']
    record_ids_by_type = set()
    for t in types:
        record_ids_by_type |= memory_storage_inst.get_record_ids_by_type(t)

    record_ids &= record_ids_by_type
    punch_card_data = _get_punch_card_data(
        memory_storage_inst.get_records(record_ids))

    return {
        'punch_card_data': punch_card_data,
    }
예제 #33
0
def get_engineers(records, metric_filter, finalize_handler):

    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = vault.resolve_modules(modules_names)

    def postprocessing(record):
        if finalize_handler:
            record = finalize_handler(record)
        user = vault.get_user_from_runtime_storage(record['id'])
        record['core'] = get_core_engineer_branch(user, modules)
        return record

    return _get_aggregated_stats(records, metric_filter,
                                 vault.get_memory_storage().get_user_ids(),
                                 'user_id', 'author_name',
                                 finalize_handler=postprocessing)
예제 #34
0
def get_engineers(records, metric_filter, finalize_handler):

    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = vault.resolve_modules(modules_names)

    def postprocessing(record):
        if finalize_handler:
            record = finalize_handler(record)
        user = vault.get_user_from_runtime_storage(record['id'])
        record['core'] = is_engineer_core_in_modules(user, modules)
        return record

    return _get_aggregated_stats(records, metric_filter,
                                 vault.get_memory_storage().get_user_ids(),
                                 'user_id', 'author_name',
                                 finalize_handler=postprocessing)
예제 #35
0
def user_activity(user_id):
    user = vault.get_user_from_runtime_storage(user_id)
    if not user:
        flask.abort(404)
    user = helpers.extend_user(user)

    memory_storage_inst = vault.get_memory_storage()
    records = memory_storage_inst.get_records(
        memory_storage_inst.get_record_ids_by_user_ids([user_id]))
    records = sorted(records, key=operator.itemgetter('date'), reverse=True)

    return {
        'user': user,
        'total_records': len(records),
        'contribution': helpers.get_contribution_summary(records),
        'punch_card_data': _get_punch_card_data(records),
    }
예제 #36
0
def user_activity(user_id):
    user = vault.get_user_from_runtime_storage(user_id)
    if not user:
        flask.abort(404)
    user = helpers.extend_user(user)

    memory_storage_inst = vault.get_memory_storage()
    records = memory_storage_inst.get_records(
        memory_storage_inst.get_record_ids_by_user_ids([user_id]))
    records = sorted(records, key=operator.itemgetter('date'), reverse=True)

    return {
        'user': user,
        'total_records': len(records),
        'contribution': helpers.get_contribution_summary(records),
        'punch_card_data': _get_punch_card_data(records),
    }
예제 #37
0
def get_engineers_extended(records):
    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = vault.resolve_modules(modules_names)

    def postprocessing(record):
        record = decorators.mark_finalize(record)

        if not (record['mark'] or record['review'] or record['commit'] or
                record['email'] or record['patch_count']):
            return

        user = vault.get_user_from_runtime_storage(record['id'])
        record['company'] = user['companies'][-1]['company_name']
        record['core'] = is_engineer_core_in_modules(user, modules)
        return record

    def record_processing(result, record, param_id):
        result_row = result[record[param_id]]
        record_type = record['record_type']
        result_row[record_type] = result_row.get(record_type, 0) + 1
        if record_type == 'mark':
            decorators.mark_filter(result, record, param_id)
            result_row['metric'] = result_row['mark']
        if record_type == 'review':
            result_row['patch_count'] = (result_row.get('patch_count', 0) +
                                         record['patch_count'])

    result = dict((user_id, {'id': user_id, 'mark': 0, 'review': 0,
                             'commit': 0, 'email': 0, 'patch_count': 0,
                             'metric': 0})
                  for user_id in vault.get_memory_storage().get_user_ids())

    for record in records:
        record_processing(result, record, 'user_id')
        result[record['user_id']]['name'] = record['author_name']

    response = result.values()
    response.sort(key=lambda x: x['mark'], reverse=True)
    response = [item for item in map(postprocessing, response) if item]
    utils.add_index(response)

    return response
예제 #38
0
파일: web.py 프로젝트: mohzah/spectrometer
def get_engineers(records, metric_filter, finalize_handler, **kwargs):

    modules_names = parameters.get_parameter({}, "module", "modules")
    modules = set([m for m, r in vault.resolve_modules(modules_names, [""])])

    def postprocessing(record):
        if finalize_handler:
            record = finalize_handler(record)
        user = vault.get_user_from_runtime_storage(record["id"])
        record["core"] = get_core_engineer_branch(user, modules)
        return record

    return _get_aggregated_stats(
        records,
        metric_filter,
        vault.get_memory_storage().get_user_ids(),
        "user_id",
        "author_name",
        finalize_handler=postprocessing,
    )
예제 #39
0
def get_engineers_extended(records):
    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = vault.resolve_modules(modules_names)

    def postprocessing(record):
        record = decorators.mark_finalize(record)

        if not (record['mark'] or record['review'] or record['commit'] or
                record['email'] or record['patch_count']):
            return

        user = vault.get_user_from_runtime_storage(record['id'])
        record['company'] = user['companies'][-1]['company_name']
        record['core'] = is_engineer_core_in_modules(user, modules)
        return record

    def record_processing(result, record, param_id):
        result_row = result[record[param_id]]
        record_type = record['record_type']
        result_row[record_type] = result_row.get(record_type, 0) + 1
        if record_type == 'mark':
            decorators.mark_filter(result, record, param_id)
        if record_type == 'review':
            result_row['patch_count'] = (result_row.get('patch_count', 0) +
                                         record['patch_count'])

    result = dict((user_id, {'id': user_id, 'mark': 0, 'review': 0,
                             'commit': 0, 'email': 0, 'patch_count': 0,
                             'metric': 0})
                  for user_id in vault.get_memory_storage().get_user_ids())

    for record in records:
        record_processing(result, record, 'user_id')
        result[record['user_id']]['name'] = record['author_name']

    response = result.values()
    response.sort(key=lambda x: x['mark'], reverse=True)
    response = [item for item in map(postprocessing, response) if item]
    utils.add_index(response)

    return response
예제 #40
0
def make_page_title(company, user_id, module, release):
    if company:
        memory_storage = vault.get_memory_storage()
        company = memory_storage.get_original_company_name(company)
    if company or user_id:
        if user_id:
            s = vault.get_user_from_runtime_storage(user_id)['user_name']
            if company:
                s += ' (%s)' % company
        else:
            s = company
    else:
        s = 'OpenStack community'
    s += ' contribution'
    if module:
        s += ' to %s' % module
    if release != 'all':
        s += ' in %s release' % release.capitalize()
    else:
        s += ' in all releases'
    return s
예제 #41
0
def make_page_title(company, user_id, module, release):
    if company:
        memory_storage = vault.get_memory_storage()
        company = memory_storage.get_original_company_name(company)
    if company or user_id:
        if user_id:
            s = vault.get_user_from_runtime_storage(user_id)['user_name']
            if company:
                s += ' (%s)' % company
        else:
            s = company
    else:
        s = 'OpenStack community'
    s += ' contribution'
    if module:
        s += ' to %s' % module
    if release != 'all':
        s += ' in %s release' % release.capitalize()
    else:
        s += ' in all releases'
    return s
예제 #42
0
        def record_filter_decorated_function(*args, **kwargs):

            memory_storage_inst = vault.get_memory_storage()
            record_ids = set(memory_storage_inst.get_record_ids())  # a copy

            params = _prepare_params(kwargs, ignore)

            release = params['release']
            if release:
                if 'all' not in release:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_releases(
                            c.lower() for c in release))

            project_type = params['project_type']
            if project_type:
                record_ids &= _filter_records_by_modules(
                    memory_storage_inst,
                    vault.resolve_project_types(project_type), release)

            module = params['module']
            if module:
                record_ids &= _filter_records_by_modules(
                    memory_storage_inst, module, release)

            user_id = params['user_id']
            user_id = [u for u in user_id
                       if vault.get_user_from_runtime_storage(u)]
            if user_id:
                record_ids &= (
                    memory_storage_inst.get_record_ids_by_user_ids(user_id))

            company = params['company']
            if company:
                record_ids &= (
                    memory_storage_inst.get_record_ids_by_companies(company))

            metric = params['metric']
            if 'all' not in metric:
                for metric in metric:
                    if metric in parameters.METRIC_TO_RECORD_TYPE:
                        record_ids &= (
                            memory_storage_inst.get_record_ids_by_type(
                                parameters.METRIC_TO_RECORD_TYPE[metric]))

            if 'tm_marks' in metric:
                filtered_ids = []
                review_nth = int(parameters.get_parameter(
                    kwargs, 'review_nth')[0])
                for record in memory_storage_inst.get_records(record_ids):
                    parent = memory_storage_inst.get_record_by_primary_key(
                        record['review_id'])
                    if (parent and ('review_number' in parent) and
                            (parent['review_number'] <= review_nth)):
                        filtered_ids.append(record['record_id'])
                record_ids = filtered_ids

            blueprint_id = params['blueprint_id']
            if blueprint_id:
                record_ids &= (
                    memory_storage_inst.get_record_ids_by_blueprint_ids(
                        blueprint_id))

            start_date = params['start_date']
            end_date = params['end_date']

            if start_date or end_date:
                record_ids &= _filter_records_by_days(start_date, end_date,
                                                      memory_storage_inst)

            kwargs['record_ids'] = record_ids
            kwargs['records'] = memory_storage_inst.get_records(record_ids)

            return f(*args, **kwargs)
예제 #43
0
        def record_filter_decorated_function(*args, **kwargs):

            memory_storage_inst = vault.get_memory_storage()
            record_ids = set(memory_storage_inst.get_record_ids())  # a copy

            params = _prepare_params(kwargs, ignore)

            release = params['release']
            if release:
                if 'all' not in release:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_releases(
                            c.lower() for c in release))

            project_type = params['project_type']
            if project_type:
                record_ids &= _filter_records_by_modules(
                    memory_storage_inst,
                    vault.resolve_project_types(project_type), release)

            module = params['module']
            if module:
                record_ids &= _filter_records_by_modules(
                    memory_storage_inst, module, release)

            user_id = params['user_id']
            user_id = [
                u for u in user_id if vault.get_user_from_runtime_storage(u)
            ]
            if user_id:
                record_ids &= (
                    memory_storage_inst.get_record_ids_by_user_ids(user_id))

            company = params['company']
            if company:
                record_ids &= (
                    memory_storage_inst.get_record_ids_by_companies(company))

            metric = params['metric']
            if 'all' not in metric:
                for metric in metric:
                    if metric in parameters.METRIC_TO_RECORD_TYPE:
                        record_ids &= (
                            memory_storage_inst.get_record_ids_by_type(
                                parameters.METRIC_TO_RECORD_TYPE[metric]))

            if 'tm_marks' in metric:
                filtered_ids = []
                review_nth = int(
                    parameters.get_parameter(kwargs, 'review_nth')[0])
                for record in memory_storage_inst.get_records(record_ids):
                    parent = memory_storage_inst.get_record_by_primary_key(
                        record['review_id'])
                    if (parent and ('review_number' in parent)
                            and (parent['review_number'] <= review_nth)):
                        filtered_ids.append(record['record_id'])
                record_ids = filtered_ids

            blueprint_id = params['blueprint_id']
            if blueprint_id:
                record_ids &= (memory_storage_inst.
                               get_record_ids_by_blueprint_ids(blueprint_id))

            start_date = params['start_date']
            end_date = params['end_date']

            if start_date or end_date:
                record_ids &= _filter_records_by_days(start_date, end_date,
                                                      memory_storage_inst)

            kwargs['record_ids'] = record_ids
            kwargs['records'] = memory_storage_inst.get_records(record_ids)

            return f(*args, **kwargs)
예제 #44
0
파일: web.py 프로젝트: mohzah/spectrometer
def get_company(company_name, **kwargs):
    memory_storage_inst = vault.get_memory_storage()
    for company in memory_storage_inst.get_companies():
        if company.lower() == company_name.lower():
            return {"id": company_name, "text": memory_storage_inst.get_original_company_name(company_name)}
    flask.abort(404)
예제 #45
0
def get_modules(records, metric_filter, finalize_handler):
    return _get_aggregated_stats(records, metric_filter,
                                 vault.get_memory_storage().get_modules(),
                                 'module')
예제 #46
0
def get_engineers(records, metric_filter, finalize_handler):
    return _get_aggregated_stats(records, metric_filter,
                                 vault.get_memory_storage().get_user_ids(),
                                 'user_id', 'author_name',
                                 finalize_handler=finalize_handler)
예제 #47
0
def get_companies(records, metric_filter, finalize_handler):
    return _get_aggregated_stats(records, metric_filter,
                                 vault.get_memory_storage().get_companies(),
                                 'company_name')
예제 #48
0
def get_modules(records, metric_filter, finalize_handler):
    return _get_aggregated_stats(records, metric_filter,
                                 vault.get_memory_storage().get_modules(),
                                 'module', finalize_handler=finalize_handler)
예제 #49
0
        def record_filter_decorated_function(*args, **kwargs):

            memory_storage_inst = vault.get_memory_storage()
            record_ids = set(memory_storage_inst.get_record_ids())  # a copy

            releases = []
            if 'release' not in ignore:
                releases = parameters.get_parameter(kwargs, 'release',
                                                    'releases', use_default)
                if releases:
                    if 'all' not in releases:
                        record_ids &= (
                            memory_storage_inst.get_record_ids_by_releases(
                                c.lower() for c in releases))

            modules = parameters.get_parameter(kwargs, 'module', 'modules',
                                               use_default)

            if 'project_type' not in ignore:
                param = parameters.get_parameter(kwargs, 'project_type',
                                                 'project_types', use_default)
                if param:
                    record_ids &= _filter_records_by_modules(
                        memory_storage_inst,
                        vault.resolve_project_types(param),
                        releases)

            if 'module' not in ignore:
                if modules:
                    record_ids &= _filter_records_by_modules(
                        memory_storage_inst, modules, releases)

            if 'user_id' not in ignore:
                param = parameters.get_parameter(kwargs, 'user_id', 'user_ids')
                param = [u for u in param
                         if vault.get_user_from_runtime_storage(u)]
                if param:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_user_ids(param))

            if 'company' not in ignore:
                param = parameters.get_parameter(kwargs, 'company',
                                                 'companies')
                if param:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_companies(param))

            if 'metric' not in ignore:
                metrics = parameters.get_parameter(kwargs, 'metric')
                if 'all' not in metrics:
                    for metric in metrics:
                        if metric in parameters.METRIC_TO_RECORD_TYPE:
                            record_ids &= (
                                memory_storage_inst.get_record_ids_by_type(
                                    parameters.METRIC_TO_RECORD_TYPE[metric]))

                if 'tm_marks' in metrics:
                    filtered_ids = []
                    review_nth = int(parameters.get_parameter(
                        kwargs, 'review_nth')[0])
                    for record in memory_storage_inst.get_records(record_ids):
                        parent = memory_storage_inst.get_record_by_primary_key(
                            record['review_id'])
                        if (parent and ('review_number' in parent) and
                                (parent['review_number'] <= review_nth)):
                            filtered_ids.append(record['record_id'])
                    record_ids = filtered_ids

            if 'blueprint_id' not in ignore:
                param = parameters.get_parameter(kwargs, 'blueprint_id')
                if param:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_blueprint_ids(
                            param))

            time_filter = _get_time_filter(kwargs, ignore)

            kwargs['records'] = time_filter(
                memory_storage_inst.get_records(record_ids))
            return f(*args, **kwargs)
예제 #50
0
        def record_filter_decorated_function(*args, **kwargs):

            vault_inst = vault.get_vault()
            memory_storage_inst = vault.get_memory_storage()
            record_ids = set(memory_storage_inst.get_record_ids())  # a copy

            if 'module' not in ignore:
                param = parameters.get_parameter(kwargs, 'module', 'modules',
                                                 use_default)
                if param:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_modules(
                            vault.resolve_modules(param)))

            if 'project_type' not in ignore:
                param = parameters.get_parameter(kwargs, 'project_type',
                                                 'project_types', use_default)
                if param:
                    ptgi = vault_inst['project_type_group_index']
                    modules = set()
                    for project_type in param:
                        project_type = project_type.lower()
                        if project_type in ptgi:
                            modules |= ptgi[project_type]
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_modules(modules))

            if 'user_id' not in ignore:
                param = parameters.get_parameter(kwargs, 'user_id', 'user_ids')
                param = [
                    u for u in param if vault.get_user_from_runtime_storage(u)
                ]
                if param:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_user_ids(param))

            if 'company' not in ignore:
                param = parameters.get_parameter(kwargs, 'company',
                                                 'companies')
                if param:
                    record_ids &= (
                        memory_storage_inst.get_record_ids_by_companies(param))

            if 'release' not in ignore:
                param = parameters.get_parameter(kwargs, 'release', 'releases',
                                                 use_default)
                if param:
                    if 'all' not in param:
                        record_ids &= (
                            memory_storage_inst.get_record_ids_by_releases(
                                c.lower() for c in param))

            if 'metric' not in ignore:
                metrics = parameters.get_parameter(kwargs, 'metric')
                if 'all' not in metrics:
                    for metric in metrics:
                        record_ids &= (
                            memory_storage_inst.get_record_ids_by_type(
                                parameters.METRIC_TO_RECORD_TYPE[metric]))

                if 'tm_marks' in metrics:
                    filtered_ids = []
                    review_nth = int(
                        parameters.get_parameter(kwargs, 'review_nth')[0])
                    for record in memory_storage_inst.get_records(record_ids):
                        parent = memory_storage_inst.get_record_by_primary_key(
                            record['review_id'])
                        if (parent and ('review_number' in parent)
                                and (parent['review_number'] <= review_nth)):
                            filtered_ids.append(record['record_id'])
                    record_ids = filtered_ids

            if 'blueprint_id' not in ignore:
                param = parameters.get_parameter(kwargs, 'blueprint_id')
                if param:
                    record_ids &= (memory_storage_inst.
                                   get_record_ids_by_blueprint_ids(param))

            kwargs['records'] = memory_storage_inst.get_records(record_ids)
            return f(*args, **kwargs)