コード例 #1
0
ファイル: helpers.py プロジェクト: sukantking/stackalytics
def extend_module(module_id, project_type, release):
    module_id_index = vault.get_vault()['module_id_index']
    module_id = module_id.lower()

    if module_id not in module_id_index:
        return None

    repos_index = vault.get_vault()['repos_index']

    module = module_id_index[module_id]
    name = module['module_group_name']
    if name[0].islower():
        name = name.capitalize()

    # (module, release) pairs
    own_sub_modules = set(vault.resolve_modules([module_id], [release]))
    visible_sub_modules = own_sub_modules & set(
        vault.resolve_modules(vault.resolve_project_types([project_type]),
                              [release]))

    child_modules = []
    for m, r in own_sub_modules:
        child = {'module_name': m, 'visible': (m, r) in visible_sub_modules}
        if m in repos_index:
            child['repo_uri'] = repos_index[m]['uri']
        child_modules.append(child)

    child_modules.sort(key=lambda x: x['module_name'])

    return {
        'id': module_id,
        'name': name,
        'tag': module['tag'],
        'modules': child_modules,
    }
コード例 #2
0
ファイル: helpers.py プロジェクト: Mirantis/stackalytics
def extend_module(module_id, project_type, release):
    module_id_index = vault.get_vault()['module_id_index']
    module_id = module_id.lower()

    if module_id not in module_id_index:
        return None

    repos_index = vault.get_vault()['repos_index']

    module = module_id_index[module_id]
    name = module['module_group_name']
    if name[0].islower():
        name = name.capitalize()

    # (module, release) pairs
    own_sub_modules = set(vault.resolve_modules([module_id], [release]))
    visible_sub_modules = own_sub_modules & set(vault.resolve_modules(
        vault.resolve_project_types([project_type]), [release]))

    child_modules = []
    for m, r in own_sub_modules:
        child = {'module_name': m, 'visible': (m, r) in visible_sub_modules}
        if m in repos_index:
            child['repo_uri'] = repos_index[m]['uri']
        child_modules.append(child)

    child_modules.sort(key=lambda x: x['module_name'])

    return {
        'id': module_id,
        'name': name,
        'tag': module['tag'],
        'modules': child_modules,
    }
コード例 #3
0
ファイル: web.py プロジェクト: liujunpengwork/stackalytics
def get_users_json(record_ids, **kwargs):
    core_in = parameters.get_single_parameter(kwargs, 'core_in') or None
    valid_modules = set()
    if core_in:
        core_in = set(core_in.split(','))
        valid_modules = vault.resolve_project_types(
            kwargs['_params']['project_type'])
        valid_modules = set(m[0] for m in vault.resolve_modules(
            valid_modules, kwargs['_params']['release']))

    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 = []
    for user_id in user_ids:
        user = vault.get_user_from_runtime_storage(user_id)
        r = {'id': user_id, 'text': user['user_name']}

        add_flag = not core_in
        if core_in and user.get('core'):
            core_modules = [module_branch[0] for module_branch in user['core']
                            if (module_branch[1] in core_in and
                                module_branch[0] in valid_modules)]
            if core_modules:
                r['core'] = core_modules
                if user['companies']:
                    r['company_name'] = user['companies'][-1]['company_name']
                add_flag = True
        if add_flag:
            result.append(r)

    result.sort(key=lambda x: x['text'])
    return result
コード例 #4
0
def get_users_json(record_ids, **kwargs):
    core_in = parameters.get_single_parameter(kwargs, 'core_in') or None
    valid_modules = set()
    if core_in:
        core_in = set(core_in.split(','))
        valid_modules = vault.resolve_project_types(
            kwargs['_params']['project_type'])
        valid_modules = set(m[0] for m in vault.resolve_modules(
            valid_modules, kwargs['_params']['release']))

    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 = []
    for user_id in user_ids:
        user = vault.get_user_from_runtime_storage(user_id)
        r = {'id': user_id, 'text': user['user_name']}

        add_flag = not core_in
        if core_in and user.get('core'):
            core_modules = [module_branch[0] for module_branch in user['core']
                            if (module_branch[1] in core_in and
                                module_branch[0] in valid_modules)]
            if core_modules:
                r['core'] = core_modules
                if user['companies']:
                    r['company_name'] = user['companies'][-1]['company_name']
                add_flag = True
        if add_flag:
            result.append(r)

    result.sort(key=lambda x: x['text'])
    return result
コード例 #5
0
ファイル: web.py プロジェクト: dlundquist/stackalytics
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)
コード例 #6
0
def get_engineers(records, metric_filter, finalize_handler, **kwargs):
    modules_names = parameters.get_parameter(kwargs, 'module')
    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)
コード例 #7
0
def get_engineers_extended(records, **kwargs):
    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = set([m for m, r in 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']):
            return

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

    def record_processing(result, record, param_id):
        result_row = result[getattr(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 = {}
    for record in records:
        user_id = record.user_id
        if user_id not in result:
            result[user_id] = {
                'id': user_id,
                'mark': 0,
                'review': 0,
                'commit': 0,
                'email': 0,
                'patch': 0,
                'metric': 0
            }
        record_processing(result, record, 'user_id')
        result[user_id]['name'] = record.author_name

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

    return response
コード例 #8
0
ファイル: web.py プロジェクト: dlundquist/stackalytics
def get_engineers_extended(records, **kwargs):
    modules_names = parameters.get_parameter({}, 'module', 'modules')
    modules = set([m for m, r in 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']):
            return

        user = vault.get_user_from_runtime_storage(record['id'])
        record['company'] = user['companies'][-1]['company_name']
        record['core'] = get_core_engineer_branch(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 = {}
    for record in records:
        user_id = record['user_id']
        if user_id not in result:
            result[user_id] = {'id': user_id, 'mark': 0, 'review': 0,
                               'commit': 0, 'email': 0, 'patch': 0,
                               'metric': 0}
        record_processing(result, record, 'user_id')
        result[user_id]['name'] = record['author_name']

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

    return response
コード例 #9
0
ファイル: decorators.py プロジェクト: ypraveen/stackalytics
        def record_filter_decorated_function(*args, **kwargs):

            memory_storage_inst = vault.get_memory_storage()
            record_ids = None

            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']
            mr = None
            if project_type:
                mr = set(
                    vault.resolve_modules(
                        vault.resolve_project_types(project_type), release))

            module = params['module']
            if module:
                mr = _intersect(mr, set(vault.resolve_modules(module,
                                                              release)))

            if mr is not None:
                record_ids = _intersect(
                    record_ids,
                    _filter_records_by_modules(memory_storage_inst, mr))

            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 = _intersect(
                    record_ids,
                    memory_storage_inst.get_record_ids_by_user_ids(user_id))

            company = params['company']
            if company:
                record_ids = _intersect(
                    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 = _intersect(
                            record_ids,
                            memory_storage_inst.get_record_ids_by_types(
                                parameters.METRIC_TO_RECORD_TYPE[metric]))

            if 'tm_marks' in metric:
                filtered_ids = []
                review_nth = int(parameters.get_parameter('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 = _intersect(
                    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 = _intersect(
                    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)
コード例 #10
0
ファイル: decorators.py プロジェクト: dims/stackalytics
        def record_filter_decorated_function(*args, **kwargs):

            memory_storage_inst = vault.get_memory_storage()
            record_ids = None

            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']
            mr = None
            if project_type:
                mr = set(vault.resolve_modules(vault.resolve_project_types(
                    project_type), release))

            module = params['module']
            if module:
                mr = _intersect(mr, set(vault.resolve_modules(
                    module, release)))

            if mr is not None:
                record_ids = _intersect(
                    record_ids, _filter_records_by_modules(
                        memory_storage_inst, mr))

            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 = _intersect(
                    record_ids,
                    memory_storage_inst.get_record_ids_by_user_ids(user_id))

            company = params['company']
            if company:
                record_ids = _intersect(
                    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 = _intersect(
                            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 = _intersect(
                    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 = _intersect(
                    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)
コード例 #11
0
ファイル: decorators.py プロジェクト: dianaclarke/lit
        def record_filter_decorated_function(*args, **kwargs):

            memory_storage_inst = vault.get_memory_storage()
            record_ids = None

            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']
            mr = None
            if project_type:
                mr = set(
                    vault.resolve_modules(
                        vault.resolve_project_types(project_type), release))

            module = params['module']
            if module:
                mr = _intersect(mr, set(vault.resolve_modules(module,
                                                              release)))

            if mr is not None:
                record_ids = _intersect(
                    record_ids,
                    _filter_records_by_modules(memory_storage_inst, mr))

            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 = _intersect(
                    record_ids,
                    memory_storage_inst.get_record_ids_by_user_ids(user_id))

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

            metric = params['metric']
            if 'all' not in metric:
                for m in metric:
                    if m in parameters.METRIC_TO_RECORD_TYPE:
                        record_ids = _intersect(
                            record_ids,
                            memory_storage_inst.get_record_ids_by_types(
                                parameters.METRIC_TO_RECORD_TYPE[m]))

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

            if start_date or end_date:
                record_ids = _intersect(
                    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)