Example #1
0
def get_module(module_id, **kwargs):
    project_type = parameters.get_single_parameter(kwargs, 'project_type')
    release = parameters.get_single_parameter(kwargs, 'release')
    module = helpers.extend_module(module_id, project_type, release)
    if not module:
        flask.abort(404)
    return module
Example #2
0
def get_module(module_id, **kwargs):
    project_type = parameters.get_single_parameter(kwargs, 'project_type')
    release = parameters.get_single_parameter(kwargs, 'release')
    module = helpers.extend_module(module_id, project_type, release)
    if not module:
        flask.abort(404)
    return module
Example #3
0
def _get_week(kwargs, param_name):
    date_param = parameters.get_single_parameter(kwargs, param_name)
    if date_param:
        ts = utils.date_to_timestamp_ext(date_param)
    else:
        ts = vault.get_vault()[param_name]
    return utils.timestamp_to_week(ts)
Example #4
0
def _get_week(kwargs, param_name):
    date_param = parameters.get_single_parameter(kwargs, param_name)
    if date_param:
        ts = utils.date_to_timestamp_ext(date_param)
    else:
        ts = vault.get_vault()[param_name]
    return utils.timestamp_to_week(ts)
Example #5
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
Example #6
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
Example #7
0
def cores():
    project_type = parameters.get_single_parameter({}, 'project_type')
    return {
        'project_type': project_type,
    }
Example #8
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 'person-day' in metric:
        # special case for man-day effort metric
        release_stat = collections.defaultdict(set)
        all_stat = collections.defaultdict(set)
        for record in records:
            if start_week <= record.week < end_week:
                day = utils.timestamp_to_day(record.date)
                user_id = record.user_id
                if record.release == release_name:
                    release_stat[day].add(user_id)
                all_stat[day].add(user_id)
        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 start_week <= week < end_week:
                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]
Example #9
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 'person-day' 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'] in ['commit', 'member']) 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]
Example #10
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 = {}

            try:
                _prepare_params(kwargs, [])
            except Exception:
                if return_code == 200:
                    raise  # do not re-raise on error page

            # put parameters into template
            ctx['metric'] = parameters.get_single_parameter(kwargs,
                                                            'metric',
                                                            use_default=True)
            ctx['metric_label'] = parameters.METRIC_LABELS.get(ctx['metric'])

            project_type = parameters.get_single_parameter(kwargs,
                                                           'project_type',
                                                           use_default=True)
            ctx['project_type'] = project_type

            ctx['release'] = parameters.get_single_parameter(kwargs,
                                                             'release',
                                                             use_default=True)

            company = parameters.get_single_parameter(kwargs, 'company')
            ctx['company'] = company
            if company:
                ctx['company_original'] = (
                    vault.get_memory_storage().get_original_company_name(
                        ctx['company']))

            module = parameters.get_single_parameter(kwargs, 'module')
            ctx['module'] = module
            if module and module in vault_inst['module_id_index']:
                ctx['module_inst'] = vault_inst['module_id_index'][module]

            ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id')
            if ctx['user_id']:
                ctx['user_inst'] = vault.get_user_from_runtime_storage(
                    ctx['user_id'])

            ctx['page_title'] = helpers.make_page_title(
                ctx.get('release'), ctx.get('module_inst'),
                ctx.get('company_original'), ctx.get('user_inst'))

            ctx['stackalytics_version'] = (
                stackalytics_version.version_info.version_string())
            ctx['stackalytics_release'] = (
                stackalytics_version.version_info.release_string())
            ctx['runtime_storage_update_time'] = (
                vault_inst['runtime_storage_update_time'])

            # deprecated -- top mentor report
            ctx['review_nth'] = parameters.get_single_parameter(
                kwargs, 'review_nth')

            return flask.render_template(template_name, **ctx), return_code
Example #11
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['company'] = parameters.get_single_parameter(kwargs, 'company')
            ctx['company_original'] = (
                vault.get_memory_storage().get_original_company_name(
                    ctx['company']))

            module = parameters.get_single_parameter(kwargs, 'module')
            ctx['module'] = module
            module_name = None
            if module and module in vault_inst['module_id_index']:
                ctx['module_inst'] = vault_inst['module_id_index'][module]
                module_name = ctx['module_inst']['module_group_name']

            ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id')
            if ctx['user_id']:
                ctx['user_inst'] = vault.get_user_from_runtime_storage(
                    ctx['user_id'])
            ctx['page_title'] = helpers.make_page_title(
                ctx['company'], ctx['user_id'], module_name, ctx['release'])
            ctx['stackalytics_version'] = (
                stackalytics_version.version_info.version_string())
            ctx['stackalytics_release'] = (
                stackalytics_version.version_info.release_string())
            ctx['runtime_storage_update_time'] = (
                vault_inst['runtime_storage_update_time'])

            return flask.render_template(template_name, **ctx), return_code
Example #12
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 = {}

            try:
                _prepare_params(kwargs, [])
            except Exception:
                if return_code == 200:
                    raise  # do not re-raise on error page

            # put parameters into template
            ctx['metric'] = parameters.get_single_parameter(
                kwargs, 'metric', use_default=True)
            ctx['metric_label'] = parameters.METRIC_LABELS.get(ctx['metric'])

            project_type = parameters.get_single_parameter(
                kwargs, 'project_type', use_default=True)
            ctx['project_type'] = project_type
            ctx['project_type_inst'] = vault.get_project_type(project_type)

            ctx['release'] = parameters.get_single_parameter(
                kwargs, 'release', use_default=True)

            company = parameters.get_single_parameter(kwargs, 'company')
            ctx['company'] = company
            if company:
                ctx['company_original'] = (
                    vault.get_memory_storage().get_original_company_name(
                        ctx['company']))

            module = parameters.get_single_parameter(kwargs, 'module')
            ctx['module'] = module
            if module and module in vault_inst['module_id_index']:
                ctx['module_inst'] = vault_inst['module_id_index'][module]

            ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id')
            if ctx['user_id']:
                ctx['user_inst'] = vault.get_user_from_runtime_storage(
                    ctx['user_id'])

            ctx['page_title'] = helpers.make_page_title(
                ctx['project_type_inst'],
                ctx.get('release'), ctx.get('module_inst'),
                ctx.get('company_original'), ctx.get('user_inst'))

            ctx['stackalytics_version'] = (
                stackalytics_version.version_info.version_string())
            ctx['stackalytics_release'] = (
                stackalytics_version.version_info.release_string())
            update_time = vault_inst['runtime_storage_update_time']
            ctx['runtime_storage_update_time'] = update_time
            ctx['runtime_storage_update_time_str'] = helpers.format_datetime(
                update_time) if update_time else None

            # deprecated -- top mentor report
            ctx['review_nth'] = parameters.get_single_parameter(
                kwargs, 'review_nth')

            return flask.render_template(template_name, **ctx), return_code
Example #13
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['company'] = parameters.get_single_parameter(kwargs, 'company')
            ctx['company_original'] = (
                vault.get_memory_storage().get_original_company_name(
                    ctx['company']))

            module = parameters.get_single_parameter(kwargs, 'module')
            ctx['module'] = module
            module_name = None
            if module and module in vault_inst['module_id_index']:
                ctx['module_inst'] = vault_inst['module_id_index'][module]
                module_name = ctx['module_inst']['module_group_name']

            ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id')
            if ctx['user_id']:
                ctx['user_inst'] = vault.get_user_from_runtime_storage(
                    ctx['user_id'])
            ctx['page_title'] = helpers.make_page_title(
                ctx['company'], ctx['user_id'], module_name, ctx['release'])
            ctx['stackalytics_version'] = (
                stackalytics_version.version_info.version_string())
            ctx['stackalytics_release'] = (
                stackalytics_version.version_info.release_string())
            ctx['runtime_storage_update_time'] = (
                vault_inst['runtime_storage_update_time'])

            return flask.render_template(template_name, **ctx), return_code
Example #14
0
def cores():
    project_type = parameters.get_single_parameter({}, 'project_type')
    return {
        'project_type': project_type,
    }