本文整理汇总了Python中stackalytics.processor.utils.add_index函数的典型用法代码示例。如果您正苦于以下问题:Python add_index函数的具体用法?Python add_index怎么用?Python add_index使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_index函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_members
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
开发者ID:tellesnobrega,项目名称:stackalytics,代码行数:12,代码来源:web.py
示例2: _get_aggregated_stats
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
开发者ID:tellesnobrega,项目名称:stackalytics,代码行数:13,代码来源:web.py
示例3: get_engineers_extended
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
开发者ID:tellesnobrega,项目名称:stackalytics,代码行数:42,代码来源:web.py
示例4: _get_aggregated_stats
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
开发者ID:liujunpengwork,项目名称:stackalytics,代码行数:22,代码来源:web.py
示例5: get_engineers_extended
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
开发者ID:gerrive,项目名称:stackalytics,代码行数:39,代码来源:web.py
示例6: get_new_companies
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
开发者ID:dlundquist,项目名称:stackalytics,代码行数:23,代码来源:web.py
示例7: get_bpd
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
开发者ID:tellesnobrega,项目名称:stackalytics,代码行数:23,代码来源:web.py
示例8: test_add_index_with_filter
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'))
开发者ID:Acidburn0zzz,项目名称:stackalytics,代码行数:6,代码来源:test_utils.py
示例9: test_add_index
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))
开发者ID:Acidburn0zzz,项目名称:stackalytics,代码行数:5,代码来源:test_utils.py
注:本文中的stackalytics.processor.utils.add_index函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论