Пример #1
0
def get_modules_json(records):
    module_group_index = vault.get_vault()['module_group_index']
    module_id_index = vault.get_vault()['module_id_index']

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

    # all modules mentioned in records
    module_ids = set(record['module'] for record in records)
    # plus all module groups that hold these modules
    module_ids |= set(itertools.chain.from_iterable(
        module_group_index.get(module, []) for module in module_ids))
    # keep only modules with specified tags
    if tags:
        module_ids = set(module_id for module_id in module_ids
                         if module_id_index[module_id].get('tag') in tags)
    # keep only modules that are in project type completely
    pts = parameters.get_parameter({}, 'project_type', 'project_types')
    if pts:
        m = set(vault.resolve_project_types(pts))
        module_ids = set(module_id for module_id in module_ids
                         if module_id_index[module_id]['modules'] <= m)

    query = (flask.request.args.get('query') or '').lower()
    matched = []

    for module_id in module_ids:
        if module_id.find(query) >= 0:
            module = dict([(k, v) for k, v in
                           six.iteritems(module_id_index[module_id])
                           if k not in ['modules']])
            matched.append(module)

    return sorted(matched, key=operator.itemgetter('text'))
Пример #2
0
def get_modules_json(records):
    module_group_index = vault.get_vault()['module_group_index']
    module_id_index = vault.get_vault()['module_id_index']

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

    # all modules mentioned in records
    module_ids = set(record['module'] for record in records)
    # plus all module groups that hold these modules
    module_ids |= set(itertools.chain.from_iterable(
        module_group_index.get(module, []) for module in module_ids))
    # keep only modules with specified tags
    if tags:
        module_ids = set(module_id for module_id in module_ids
                         if module_id_index[module_id].get('tag') in tags)
    # keep only modules that are in project type completely
    pts = parameters.get_parameter({}, 'project_type', 'project_types')
    if pts:
        m = set(vault.resolve_project_types(pts))
        module_ids = set(module_id for module_id in module_ids
                         if module_id_index[module_id]['modules'] <= m)

    query = (flask.request.args.get('query') or '').lower()
    matched = []

    for module_id in module_ids:
        if module_id.find(query) >= 0:
            module = dict([(k, v) for k, v in
                           six.iteritems(module_id_index[module_id])
                           if k not in ['modules']])
            matched.append(module)

    return sorted(matched, key=operator.itemgetter('text'))
Пример #3
0
def timeline(records, **kwargs):
    # find start and end dates
    release_names = parameters.get_parameter(kwargs, "release", "releases")
    releases = vault.get_vault()["releases"]
    if not release_names:
        flask.abort(404)

    if "all" in release_names:
        start_date = release_start_date = utils.timestamp_to_week(vault.get_vault()["start_date"])
        end_date = release_end_date = utils.timestamp_to_week(vault.get_vault()["end_date"])
    else:
        release = releases[release_names[0]]
        start_date = release_start_date = utils.timestamp_to_week(release["start_date"])
        end_date = release_end_date = utils.timestamp_to_week(release["end_date"])

    now = utils.timestamp_to_week(int(time.time())) + 1

    # expand start-end to year if needed
    if release_end_date - release_start_date < 52:
        expansion = (52 - (release_end_date - release_start_date)) // 2
        if release_end_date + expansion < now:
            end_date += expansion
        else:
            end_date = now
        start_date = end_date - 52

    # empty stats for all weeks in range
    weeks = range(start_date, end_date)
    week_stat_loc = dict((c, 0) for c in weeks)
    week_stat_commits = dict((c, 0) for c in weeks)
    week_stat_commits_hl = dict((c, 0) for c in weeks)

    param = parameters.get_parameter(kwargs, "metric")
    if ("commits" in param) or ("loc" in param):
        handler = lambda record: record["loc"]
    else:
        handler = lambda record: 0

    # fill stats with the data
    for record in records:
        week = record["week"]
        if week in weeks:
            week_stat_loc[week] += handler(record)
            week_stat_commits[week] += 1
            if "all" in release_names or record["release"] in release_names:
                week_stat_commits_hl[week] += 1

    # form arrays in format acceptable to timeline plugin
    array_loc = []
    array_commits = []
    array_commits_hl = []

    for week in weeks:
        week_str = utils.week_to_date(week)
        array_loc.append([week_str, week_stat_loc[week]])
        array_commits.append([week_str, week_stat_commits[week]])
        array_commits_hl.append([week_str, week_stat_commits_hl[week]])

    return [array_commits, array_commits_hl, array_loc]
Пример #4
0
def get_modules_json(records):
    module_id_index = vault.get_vault()['module_id_index']

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

    # all modules mentioned in records
    module_ids = set(record['module'] for record in records
                     if record['module'] in module_id_index)

    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_index[module_id].get('tag') in tags)

    query = (flask.request.args.get('query') or '').lower()
    matched = []

    for module_id in module_ids:
        if module_id.find(query) >= 0:
            module = dict([(k, v) for k, v in
                           six.iteritems(module_id_index[module_id])
                           if k not in ['modules']])
            module['text'] = module['module_group_name']
            del module['module_group_name']
            matched.append(module)

    return sorted(matched, key=operator.itemgetter('text'))
Пример #5
0
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)
Пример #6
0
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_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"))
Пример #8
0
def get_modules_json(records):
    module_id_index = vault.get_vault()['module_id_index']

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

    # all modules mentioned in records
    module_ids = set(record['module'] for record in records
                     if record['module'] in module_id_index)

    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_index[module_id].get('tag') in tags)

    query = (flask.request.args.get('query') or '').lower()
    matched = []

    for module_id in module_ids:
        if module_id.find(query) >= 0:
            module = dict([
                (k, v) for k, v in six.iteritems(module_id_index[module_id])
                if k not in ['modules']
            ])
            module['text'] = module['module_group_name']
            del module['module_group_name']
            matched.append(module)

    return sorted(matched, key=operator.itemgetter('text'))
Пример #9
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'))
Пример #10
0
def timeline(records, **kwargs):
    # find start and end dates
    release_name = parameters.get_single_parameter(kwargs, 'release') or 'all'
    releases = vault.get_vault()['releases']

    if 'all' in release_name:
        start_date = release_start_date = _get_date(kwargs, 'start_date')
        end_date = release_end_date = _get_date(kwargs, 'end_date')
    else:
        release = releases[release_name]
        start_date = release_start_date = utils.timestamp_to_week(
            release['start_date'])
        end_date = release_end_date = utils.timestamp_to_week(
            release['end_date'])

    now = utils.timestamp_to_week(int(time.time())) + 1

    # expand start-end to year if needed
    if release_end_date - release_start_date < 52:
        expansion = (52 - (release_end_date - release_start_date)) // 2
        if release_end_date + expansion < now:
            end_date += expansion
        else:
            end_date = now
        start_date = end_date - 52

    # empty stats for all weeks in range
    weeks = range(start_date, end_date)
    week_stat_loc = dict((c, 0) for c in weeks)
    week_stat_commits = dict((c, 0) for c in weeks)
    week_stat_commits_hl = dict((c, 0) for c in weeks)

    param = parameters.get_parameter(kwargs, 'metric')
    if ('commits' in param) or ('loc' in param):
        handler = lambda record: record['loc']
    else:
        handler = lambda record: 0

    # fill stats with the data
    for record in records:
        week = record['week']
        if week in weeks:
            week_stat_loc[week] += handler(record)
            week_stat_commits[week] += 1
            if 'all' == release_name or record['release'] == release_name:
                week_stat_commits_hl[week] += 1

    # form arrays in format acceptable to timeline plugin
    array_loc = []
    array_commits = []
    array_commits_hl = []

    for week in weeks:
        week_str = utils.week_to_date(week)
        array_loc.append([week_str, week_stat_loc[week]])
        array_commits.append([week_str, week_stat_commits[week]])
        array_commits_hl.append([week_str, week_stat_commits_hl[week]])

    return [array_commits, array_commits_hl, array_loc]
Пример #11
0
    def test_parameters_get_parameter(self, get_default, flask_request):

        flask_request.args = mock.Mock()
        flask_request.args.get = mock.Mock(side_effect=lambda x: x)

        def make(values=None):
            def f(arg):
                return values.get(arg, None) if values else None

            return f

        get_default.side_effect = make()
        flask_request.args.get.side_effect = make({"param": "foo"})
        self.assertEqual(["foo"], parameters.get_parameter({"param": "foo"}, "param"))

        flask_request.args.get.side_effect = make({"param": "foo"})
        self.assertEqual(["foo"], parameters.get_parameter({}, "param"))

        flask_request.args.get.side_effect = make({"param": "foo"})
        self.assertEqual([], parameters.get_parameter({}, "other", use_default=False))

        flask_request.args.get.side_effect = make({"params": "foo"})
        self.assertEqual(["foo"], parameters.get_parameter({}, "param", plural_name="params"))

        flask_request.args.get.side_effect = make({})
        get_default.side_effect = make({"param": "foo"})
        self.assertEqual(["foo"], parameters.get_parameter({}, "param"))
        self.assertEqual([], parameters.get_parameter({}, "other"))
Пример #12
0
    def test_parameters_get_parameter(self, get_default, flask_request):

        flask_request.args = mock.Mock()
        flask_request.args.get = mock.Mock(side_effect=lambda x: x)

        def make(values=None):
            def f(arg):
                return values.get(arg, None) if values else None
            return f

        get_default.side_effect = make()
        flask_request.args.get.side_effect = make({'param': 'foo'})
        self.assertEqual(['foo'], parameters.get_parameter(
            {'param': 'foo'}, 'param'))

        flask_request.args.get.side_effect = make({'param': 'foo'})
        self.assertEqual(['foo'], parameters.get_parameter({}, 'param'))

        flask_request.args.get.side_effect = make({'param': 'foo'})
        self.assertEqual([], parameters.get_parameter(
            {}, 'other', use_default=False))

        flask_request.args.get.side_effect = make({'params': 'foo'})
        self.assertEqual(['foo'], parameters.get_parameter(
            {}, 'param', plural_name='params'))

        flask_request.args.get.side_effect = make({})
        get_default.side_effect = make({'param': 'foo'})
        self.assertEqual(['foo'], parameters.get_parameter({}, 'param'))
        self.assertEqual([], parameters.get_parameter({}, 'other'))
Пример #13
0
def make_link(title, uri=None, options=None):
    param_names = ('release', 'project_type', 'module', 'company', 'user_id',
                   'metric')
    param_values = {}
    for param_name in param_names:
        v = parameters.get_parameter({}, param_name, param_name)
        if v:
            param_values[param_name] = ','.join(v)
    if options:
        param_values.update(options)
    if param_values:
        uri += '?' + '&'.join(['%s=%s' % (n, utils.safe_encode(v))
                               for n, v in six.iteritems(param_values)])
    return '<a href="%(uri)s">%(title)s</a>' % {'uri': uri, 'title': title}
Пример #14
0
def make_link(title, uri=None, options=None):
    param_names = ('release', 'project_type', 'module', 'company', 'user_id',
                   'metric')
    param_values = {}
    for param_name in param_names:
        v = parameters.get_parameter({}, param_name, param_name)
        if v:
            param_values[param_name] = ','.join(v)
    if options:
        param_values.update(options)
    if param_values:
        uri += '?' + '&'.join(['%s=%s' % (n, safe_encode(v))
                               for n, v in param_values.iteritems()])
    return '<a href="%(uri)s">%(title)s</a>' % {'uri': uri, 'title': title}
Пример #15
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'] = 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)
        if record_type == 'review':
            result_row['patch_count'] = (result_row.get('patch_count', 0) +
                                         record['patch_count'])

    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_count': 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
Пример #16
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)
Пример #17
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)
Пример #18
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'] = 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)
        if record_type == 'review':
            result_row['patch_count'] = (result_row.get('patch_count', 0) +
                                         record['patch_count'])

    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_count': 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
Пример #19
0
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,
    )
Пример #20
0
def _prepare_params(kwargs, ignore):
    params = kwargs.get('_params')

    if not params:
        params = {'action': flask.request.path}
        for key in parameters.FILTER_PARAMETERS:
            params[key] = parameters.get_parameter(kwargs, key, key)

        if params['start_date']:
            params['start_date'] = [utils.round_timestamp_to_day(
                params['start_date'][0])]
        if params['end_date']:
            params['end_date'] = [utils.round_timestamp_to_day(
                params['end_date'][0])]

        kwargs['_params'] = params

    if ignore:
        return dict([(k, v if k not in ignore else [])
                     for k, v in six.iteritems(params)])
    else:
        return params
Пример #21
0
def _prepare_params(kwargs, ignore):
    params = kwargs.get('_params')

    if not params:
        params = {'action': flask.request.path}
        for key in parameters.FILTER_PARAMETERS:
            params[key] = parameters.get_parameter(kwargs, key, key)

        if params['start_date']:
            params['start_date'] = [
                utils.round_timestamp_to_day(params['start_date'][0])
            ]
        if params['end_date']:
            params['end_date'] = [
                utils.round_timestamp_to_day(params['end_date'][0])
            ]

        kwargs['_params'] = params

    if ignore:
        return dict([(k, v if k not in ignore else [])
                     for k, v in six.iteritems(params)])
    else:
        return params
Пример #22
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[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
Пример #23
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)
Пример #24
0
def timeline(records, **kwargs):
    # find start and end dates
    metric = parameters.get_parameter(kwargs, 'metric')
    start_date = int(parameters.get_single_parameter(kwargs, 'start_date')
                     or 0)
    release_name = parameters.get_single_parameter(kwargs, 'release') or 'all'
    releases = vault.get_vault()['releases']

    if 'all' in release_name:
        start_week = release_start_week = _get_week(kwargs, 'start_date')
        end_week = release_end_week = _get_week(kwargs, 'end_date')
    else:
        release = releases[release_name]
        start_week = release_start_week = utils.timestamp_to_week(
            release['start_date'])
        end_week = release_end_week = utils.timestamp_to_week(
            release['end_date'])

    now = utils.timestamp_to_week(int(time.time())) + 1

    # expand start-end to year if needed
    if release_end_week - release_start_week < 52:
        expansion = (52 - (release_end_week - release_start_week)) // 2
        if release_end_week + expansion < now:
            end_week += expansion
        else:
            end_week = now
        start_week = end_week - 52

    # empty stats for all weeks in range
    weeks = range(start_week, end_week)
    week_stat_loc = dict((c, 0) for c in weeks)
    week_stat_commits = dict((c, 0) for c in weeks)
    week_stat_commits_hl = dict((c, 0) for c in weeks)

    if ('commits' in metric) or ('loc' in metric):
        handler = lambda record: record['loc']
    else:
        handler = lambda record: 0

    # fill stats with the data
    if 'man-days' in metric:
        # special case for man-day effort metric
        release_stat = collections.defaultdict(set)
        all_stat = collections.defaultdict(set)
        for record in records:
            if ((record['record_type'] == 'commit') or
                    (record['week'] not in weeks)):
                continue

            day = utils.timestamp_to_day(record['date'])
            user = vault.get_user_from_runtime_storage(record['user_id'])
            if record['release'] == release_name:
                release_stat[day] |= set([user['seq']])
            all_stat[day] |= set([user['seq']])
        for day, users in six.iteritems(release_stat):
            week = utils.timestamp_to_week(day * 24 * 3600)
            week_stat_commits_hl[week] += len(users)
        for day, users in six.iteritems(all_stat):
            week = utils.timestamp_to_week(day * 24 * 3600)
            week_stat_commits[week] += len(users)
    else:
        for record in records:
            week = record['week']
            if week in weeks:
                week_stat_loc[week] += handler(record)
                week_stat_commits[week] += 1
                if 'members' in metric:
                    if record['date'] >= start_date:
                        week_stat_commits_hl[week] += 1
                else:
                    if record['release'] == release_name:
                        week_stat_commits_hl[week] += 1

    if 'all' == release_name and 'members' not in metric:
        week_stat_commits_hl = week_stat_commits

    # form arrays in format acceptable to timeline plugin
    array_loc = []
    array_commits = []
    array_commits_hl = []

    for week in weeks:
        week_str = utils.week_to_date(week)
        array_loc.append([week_str, week_stat_loc[week]])
        array_commits.append([week_str, week_stat_commits[week]])
        array_commits_hl.append([week_str, week_stat_commits_hl[week]])

    return [array_commits, array_commits_hl, array_loc]
Пример #25
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)
Пример #26
0
def timeline(records, **kwargs):
    # find start and end dates
    metric = parameters.get_parameter(kwargs, 'metric')
    start_date = int(parameters.get_single_parameter(kwargs, 'start_date')
                     or 0)
    release_name = parameters.get_single_parameter(kwargs, 'release') or 'all'
    releases = vault.get_vault()['releases']

    if 'all' in release_name:
        start_week = release_start_week = _get_week(kwargs, 'start_date')
        end_week = release_end_week = _get_week(kwargs, 'end_date')
    else:
        release = releases[release_name]
        start_week = release_start_week = utils.timestamp_to_week(
            release['start_date'])
        end_week = release_end_week = utils.timestamp_to_week(
            release['end_date'])

    now = utils.timestamp_to_week(int(time.time())) + 1

    # expand start-end to year if needed
    if release_end_week - release_start_week < 52:
        expansion = (52 - (release_end_week - release_start_week)) // 2
        if release_end_week + expansion < now:
            end_week += expansion
        else:
            end_week = now
        start_week = end_week - 52

    # empty stats for all weeks in range
    weeks = range(start_week, end_week)
    week_stat_loc = dict((c, 0) for c in weeks)
    week_stat_commits = dict((c, 0) for c in weeks)
    week_stat_commits_hl = dict((c, 0) for c in weeks)

    if ('commits' in metric) or ('loc' in metric):
        handler = lambda record: record['loc']
    else:
        handler = lambda record: 0

    # fill stats with the data
    if 'man-days' in metric:
        # special case for man-day effort metric
        release_stat = collections.defaultdict(set)
        all_stat = collections.defaultdict(set)
        for record in records:
            if ((record['record_type'] == 'commit') or
                    (record['week'] not in weeks)):
                continue

            day = record['date'] // (24 * 3600)
            user = vault.get_user_from_runtime_storage(record['user_id'])
            if record['release'] == release_name:
                release_stat[day] |= set([user['seq']])
            all_stat[day] |= set([user['seq']])
        for day, users in six.iteritems(release_stat):
            week = utils.timestamp_to_week(day * 24 * 3600)
            week_stat_commits_hl[week] += len(users)
        for day, users in six.iteritems(all_stat):
            week = utils.timestamp_to_week(day * 24 * 3600)
            week_stat_commits[week] += len(users)
    else:
        for record in records:
            week = record['week']
            if week in weeks:
                week_stat_loc[week] += handler(record)
                week_stat_commits[week] += 1
                if 'members' in metric:
                    if record['date'] >= start_date:
                        week_stat_commits_hl[week] += 1
                else:
                    if record['release'] == release_name:
                        week_stat_commits_hl[week] += 1

    if 'all' == release_name and 'members' not in metric:
        week_stat_commits_hl = week_stat_commits

    # form arrays in format acceptable to timeline plugin
    array_loc = []
    array_commits = []
    array_commits_hl = []

    for week in weeks:
        week_str = utils.week_to_date(week)
        array_loc.append([week_str, week_stat_loc[week]])
        array_commits.append([week_str, week_stat_commits[week]])
        array_commits_hl.append([week_str, week_stat_commits_hl[week]])

    return [array_commits, array_commits_hl, array_loc]
Пример #27
0
def timeline(records, **kwargs):
    # find start and end dates
    metric = parameters.get_parameter(kwargs, "metric")
    start_date = int(parameters.get_single_parameter(kwargs, "start_date") or 0)
    release_name = parameters.get_single_parameter(kwargs, "release") or "all"
    releases = vault.get_vault()["releases"]

    if "all" in release_name:
        start_week = release_start_week = _get_week(kwargs, "start_date")
        end_week = release_end_week = _get_week(kwargs, "end_date")
    else:
        release = releases[release_name]
        start_week = release_start_week = utils.timestamp_to_week(release["start_date"])
        end_week = release_end_week = utils.timestamp_to_week(release["end_date"])

    now = utils.timestamp_to_week(int(time.time())) + 1

    # expand start-end to year if needed
    if release_end_week - release_start_week < 52:
        expansion = (52 - (release_end_week - release_start_week)) // 2
        if release_end_week + expansion < now:
            end_week += expansion
        else:
            end_week = now
        start_week = end_week - 52

    # empty stats for all weeks in range
    weeks = range(start_week, end_week)
    week_stat_loc = dict((c, 0) for c in weeks)
    week_stat_commits = dict((c, 0) for c in weeks)
    week_stat_commits_hl = dict((c, 0) for c in weeks)

    if ("commits" in metric) or ("loc" in metric):
        handler = lambda record: record["loc"]
    else:
        handler = lambda record: 0

    # fill stats with the data
    if "man-days" in metric:
        # special case for man-day effort metric
        release_stat = collections.defaultdict(set)
        all_stat = collections.defaultdict(set)
        for record in records:
            if (record["record_type"] == "commit") or (record["week"] not in weeks):
                continue

            day = utils.timestamp_to_day(record["date"])
            user = vault.get_user_from_runtime_storage(record["user_id"])
            if record["release"] == release_name:
                release_stat[day] |= set([user["seq"]])
            all_stat[day] |= set([user["seq"]])
        for day, users in six.iteritems(release_stat):
            week = utils.timestamp_to_week(day * 24 * 3600)
            week_stat_commits_hl[week] += len(users)
        for day, users in six.iteritems(all_stat):
            week = utils.timestamp_to_week(day * 24 * 3600)
            week_stat_commits[week] += len(users)
    else:
        for record in records:
            week = record["week"]
            if week in weeks:
                week_stat_loc[week] += handler(record)
                week_stat_commits[week] += 1
                if "members" in metric:
                    if record["date"] >= start_date:
                        week_stat_commits_hl[week] += 1
                else:
                    if record["release"] == release_name:
                        week_stat_commits_hl[week] += 1

    if "all" == release_name and "members" not in metric:
        week_stat_commits_hl = week_stat_commits

    # form arrays in format acceptable to timeline plugin
    array_loc = []
    array_commits = []
    array_commits_hl = []

    for week in weeks:
        week_str = utils.week_to_date(week)
        array_loc.append([week_str, week_stat_loc[week]])
        array_commits.append([week_str, week_stat_commits[week]])
        array_commits_hl.append([week_str, week_stat_commits_hl[week]])

    return [array_commits, array_commits_hl, array_loc]
Пример #28
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)
Пример #29
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)