예제 #1
0
def _get_aggregated_stats(records,
                          metric_filter,
                          keys,
                          param_id,
                          param_title=None,
                          finalize_handler=None):
    param_title = param_title or param_id
    result = dict((c, {'metric': 0, 'id': c}) for c in keys)
    context = {'vault': vault.get_vault()}
    if metric_filter:
        for record in records:
            metric_filter(result, record, param_id, context)
            result[getattr(record,
                           param_id)]['name'] = (getattr(record, param_title))
    else:
        for record in records:
            record_param_id = getattr(record, param_id)
            result[record_param_id]['metric'] += 1
            result[record_param_id]['name'] = getattr(record, param_title)

    response = [r for r in result.values() if r['metric']]
    if finalize_handler:
        response = [item for item in map(finalize_handler, response) if item]
    response.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(response, item_filter=lambda x: x['id'] != '*independent')
    return response
예제 #2
0
def get_translations(records,**kwargs):
    print ('what records %s' %records)
    for item in records:
        print ('####Here print the details on by one ###############')
        print ('record details %s ' %str(item))
    result = []
    for record in records:
        if record.record_type in ['bpd', 'bpc']:
            record = vault.extend_record(record)
            mention_date = record.get('mention_date')
            if mention_date:
                date = helpers.format_date(mention_date)
            else:
                date = 'never'
            result.append({
                'date': date,
                'status': record['lifecycle_status'],
                'metric': record.get('mention_count') or 0,
                'id': record['name'],
                'name': record['name'],
                'link': helpers.make_blueprint_link(record['module'],
                                                    record['name'])
            })

    result.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(result)

    return result
예제 #3
0
def get_bpd(records, **kwargs):
    result = []
    for record in records:
        if record['record_type'] in ['bpd', 'bpc']:
            record = vault.extend_record(record)
            mention_date = record.get('mention_date')
            if mention_date:
                date = helpers.format_date(mention_date)
            else:
                date = 'never'
            result.append({
                'date':
                date,
                'status':
                record['lifecycle_status'],
                'metric':
                record.get('mention_count') or 0,
                'id':
                record['name'],
                'name':
                record['name'],
                'link':
                helpers.make_blueprint_link(record['module'], record['name'])
            })

    result.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(result)

    return result
예제 #4
0
def get_members(records):
    response = []
    for record in records:
        nr = dict([(k, record[k]) for k in
                   ['author_name', 'date', 'company_name', 'member_uri']])
        nr['date_str'] = helpers.format_date(nr['date'])
        response.append(nr)

    response.sort(key=lambda x: x['date'], reverse=True)
    utils.add_index(response)

    return response
예제 #5
0
def get_members(records, **kwargs):
    response = []
    for record in records:
        record = vault.extend_record(record)
        nr = dict([(k, record[k]) for k in
                   ['author_name', 'date', 'company_name', 'member_uri']])
        nr['date_str'] = helpers.format_date(nr['date'])
        response.append(nr)

    response.sort(key=lambda x: x['date'], reverse=True)
    utils.add_index(response)

    return response
예제 #6
0
def _get_aggregated_stats(records, metric_filter, keys, param_id,
                          param_title=None, finalize_handler=None):
    param_title = param_title or param_id
    result = dict((c, {'metric': 0, 'id': c}) for c in keys)
    for record in records:
        metric_filter(result, record, param_id)
        result[record[param_id]]['name'] = record[param_title]

    response = [r for r in result.values() if r['metric']]
    response.sort(key=lambda x: x['metric'], reverse=True)
    response = [item for item in map(finalize_handler, response) if item]
    utils.add_index(response, item_filter=lambda x: x['id'] != '*independent')
    return response
예제 #7
0
def _get_aggregated_stats(records, metric_filter, keys, param_id,
                          param_title=None, finalize_handler=None):
    param_title = param_title or param_id
    result = dict((c, {'metric': 0, 'id': c}) for c in keys)
    for record in records:
        metric_filter(result, record, param_id)
        result[record[param_id]]['name'] = record[param_title]

    response = [r for r in result.values() if r['metric']]
    response = [item for item in map(finalize_handler, response) if item]
    response.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(response, item_filter=lambda x: x['id'] != '*independent')
    return response
예제 #8
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
예제 #9
0
def get_engineers_extended(records, **kwargs):
    modules_names = parameters.get_parameter(kwargs, 'module')
    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'] = helpers.get_current_company(user)
        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
예제 #10
0
def get_languages(records, **kwargs):
    result = []
    languages = collections.defaultdict(int)
    for record in records:
        if record.record_type in ['tr']:
            languages[record.value] += record.loc

    for lang, val in six.iteritems(languages):
        result.append({
            'id': lang,
            'name': lang,
            'metric': val,
        })

    result.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(result)

    return result
예제 #11
0
def get_languages(records, **kwargs):
    result = []
    languages = collections.defaultdict(int)
    for record in records:
        if record.record_type in ['tr']:
            languages[record.value] += record.loc

    for lang, val in six.iteritems(languages):
        result.append({
            'id': lang,
            'name': lang,
            'metric': val,
        })

    result.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(result)

    return result
예제 #12
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
예제 #13
0
 def test_add_index(self):
     sequence = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}]
     expected = [{
         'index': 1,
         'name': 'A'
     }, {
         'index': 2,
         'name': 'B'
     }, {
         'index': 3,
         'name': 'C'
     }]
     self.assertEqual(expected, utils.add_index(sequence))
예제 #14
0
def _get_aggregated_stats(records, metric_filter, keys, param_id,
                          param_title=None, finalize_handler=None):
    param_title = param_title or param_id
    result = dict((c, {'metric': 0, 'id': c}) for c in keys)
    context = {'vault': vault.get_vault()}
    if metric_filter:
        for record in records:
            metric_filter(result, record, param_id, context)
            result[getattr(record, param_id)]['name'] = (
                getattr(record, param_title))
    else:
        for record in records:
            record_param_id = getattr(record, param_id)
            result[record_param_id]['metric'] += 1
            result[record_param_id]['name'] = getattr(record, param_title)

    response = [r for r in result.values() if r['metric']]
    if finalize_handler:
        response = [item for item in map(finalize_handler, response) if item]
    response.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(response, item_filter=lambda x: x['id'] != '*independent')
    return response
예제 #15
0
파일: web.py 프로젝트: gerrive/stackalytics
def get_engineers_extended(records, **kwargs):
    modules_names = parameters.get_parameter(kwargs, 'module')
    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'] = helpers.get_current_company(user)
        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
예제 #16
0
def get_bpd(records):
    result = []
    for record in records:
        if record['record_type'] in ['bpd', 'bpc']:
            mention_date = record.get('mention_date')
            if mention_date:
                date = helpers.format_date(mention_date)
            else:
                date = 'never'
            result.append({
                'date': date,
                'status': record['lifecycle_status'],
                'metric': record.get('mention_count') or 0,
                'id': record['name'],
                'name': record['name'],
                'link': helpers.make_blueprint_link(record['module'],
                                                    record['name'])
            })

    result.sort(key=lambda x: x['metric'], reverse=True)
    utils.add_index(result)

    return result
예제 #17
0
def get_new_companies(records, **kwargs):

    days = int(flask.request.args.get('days') or reports.DEFAULT_DAYS_COUNT)
    start_date = int(time.time()) - days * 24 * 60 * 60

    result = {}
    for record in records:
        company_name = record.company_name
        date = record.date

        if company_name not in result or result[company_name] > date:
            result[company_name] = date

    response = list(({
        'name': company_name,
        'date': result[company_name],
        'date_str': helpers.format_date(result[company_name])
    }) for company_name in result if result[company_name] >= start_date)

    response.sort(key=lambda x: x['date'], reverse=True)
    utils.add_index(response)

    return response
예제 #18
0
def get_new_companies(records, **kwargs):

    days = int(flask.request.args.get('days') or reports.DEFAULT_DAYS_COUNT)
    start_date = int(time.time()) - days * 24 * 60 * 60

    result = {}
    for record in records:
        company_name = record['company_name']
        date = record['date']

        if company_name not in result or result[company_name] > date:
            result[company_name] = date

    response = list(({'name': company_name,
                      'date': result[company_name],
                      'date_str': helpers.format_date(result[company_name])})
                    for company_name in result
                    if result[company_name] >= start_date)

    response.sort(key=lambda x: x['date'], reverse=True)
    utils.add_index(response)

    return response
예제 #19
0
 def test_add_index_with_filter(self):
     sequence = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}]
     expected = [{
         'index': 0,
         'name': 'A'
     }, {
         'index': '',
         'name': 'B'
     }, {
         'index': 1,
         'name': 'C'
     }]
     self.assertEqual(
         expected,
         utils.add_index(sequence,
                         start=0,
                         item_filter=lambda x: x['name'] != 'B'))
예제 #20
0
 def test_add_index(self):
     sequence = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}]
     expected = [{'index': 1, 'name': 'A'}, {'index': 2, 'name': 'B'},
                 {'index': 3, 'name': 'C'}]
     self.assertEqual(expected, utils.add_index(sequence))
예제 #21
0
 def test_add_index_with_filter(self):
     sequence = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}]
     expected = [{'index': 0, 'name': 'A'}, {'index': '', 'name': 'B'},
                 {'index': 1, 'name': 'C'}]
     self.assertEqual(expected, utils.add_index(
         sequence, start=0, item_filter=lambda x: x['name'] != 'B'))