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
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
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
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
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
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
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))
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
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
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
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'))
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'))
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))