def export_policy(): policy_slugs = [p['slug'] for p in dal.get_policy_list()] cols = ['nume'] for policy_slug in policy_slugs: cols.extend([ policy_slug + '-procent', policy_slug + '-propuneri', policy_slug + '-intrebari', ]) ZERO = {'proposal_count': 0, 'question_count': 0, 'interest': 0} def policy_row(mandate_info): rv = {'nume': mandate_info['name']} person = dal.get_person(mandate_info['person_slug']) policy_map = {p['slug']: p for p in person.get_top_policies()} for policy_slug in policy_slugs: p = policy_map.get(policy_slug, ZERO) rv.update({ policy_slug + '-procent': p['interest'], policy_slug + '-propuneri': p['proposal_count'], policy_slug + '-intrebari': p['question_count'], }) return rv def mandates(): mandates_by_county = dal.get_2016_mandates_by_county() for county_list in mandates_by_county.values(): for mandate_info in county_list: yield mandate_info rows = (policy_row(m) for m in mandates()) data = buffer_on_disk(csv_lines(cols, rows)) return csv_response(data)
def export_proposals(year): if not perm.admin.can(): flask.abort(403) cols = [ 'nr-cdep', 'nr-senat', 'nr-bpi', 'data-propunere', 'data-actualizare', 'status', 'titlu', 'url-cdep', 'url-senat', 'initiatori-cdep', 'initiatori-senat', ] rows = ( { 'nr-cdep': row['number_cdep'], 'nr-senat': row['number_senate'], 'nr-bpi': row['number_bpi'], 'data-propunere': row['date'].isoformat(), 'data-actualizare': row['modification_date'].isoformat(), 'status': PROPOSAL_STATUS_LABEL[row['status']], 'titlu': row['title'], 'url-cdep': row['url_cdep'], 'url-senat': row['url_senate'], 'initiatori-cdep': row['namelist_cdep'], 'initiatori-senat': row['namelist_senate'], } for row in dal.get_all_proposals(year=year) ) data = buffer_on_disk(csv_lines(cols, rows)) return csv_response(data)
def export_activity(year): if not perm.admin.can(): flask.abort(403) cols = [ 'nume', 'propuneri-total', 'propuneri-inlucru', 'propuneri-acceptate', 'propuneri-respinse', 'luari-de-cuvant', 'intrebari', 'intrebari-locale', ] rows = ( { 'nume': row['name'], 'propuneri-total': row['proposals_total'], 'propuneri-inlucru': row['proposals_inprogress'], 'propuneri-acceptate': row['proposals_approved'], 'propuneri-respinse': row['proposals_rejected'], 'luari-de-cuvant': row['transcripts'], 'intrebari': row['questions'], 'intrebari-locale': row['questions-local'], } for row in dal.get_mandate_activity(year=year) ) data = buffer_on_disk(csv_lines(cols, rows)) return csv_response(data)
def export_bounded_mandates(rq): out_list = [ { 'nume': row['name'], 'partid': row['group'], 'inceput': row['start'].isoformat(), 'sfarsit': row['end'].isoformat(), } for row in dal.get_bounded_mandates(rq) ] cols = ['nume', 'partid', 'inceput', 'sfarsit'] return csv_response(csv_lines(cols, out_list))
def export_votes(year): cols = ['data', 'cod cdep', 'nume', 'vot', 'vot grup'] rows = ( { 'data': row['date'].isoformat(), 'cod cdep': row['cdeppk'], 'nume': row['name'], 'vot': VOTE_LABEL.get(row['choice'], ''), 'vot grup': VOTE_LABEL.get(row['group_choice'], ''), } for row in dal.get_all_votes(year=year) ) data = buffer_on_disk(csv_lines(cols, rows)) return csv_response(data)
def export_questions(year): cols = ['data', 'numar', 'tip', 'titlu', 'nume', 'destinatar', 'scor'] rows = ( { 'data': row['date'].isoformat(), 'numar': row['number'], 'tip': QUESTION_TYPE_LABEL[row['type']], 'titlu': row['title'], 'nume': row['name'], 'destinatar': row['addressee'], 'scor': int(row['local_score']), } for row in dal.get_all_questions(year=year) ) data = buffer_on_disk(csv_lines(cols, rows)) return csv_response(data)
def export_migrations(): results = dal.get_group_migrations( start=parse_date(flask.request.args['start']), end=parse_date(flask.request.args.get('end', '9999-12-31')), ) membership_list = [ { 'nume': row['name'], 'data': row['date'].isoformat(), 'partid_vechi': row['group_old'], 'partid_nou': row['group_new'], } for row in results ] cols = ['nume', 'data', 'partid_vechi', 'partid_nou'] return csv_response(csv_lines(cols, membership_list))
def export_group_membership(): results = dal.get_group_membership( day=parse_date(flask.request.args.get('date')) or date.today() ) membership_list = [ { 'nume': row['name'], 'inceput': row['start'].isoformat(), 'sfarsit': '' if row['end'] is None else row['end'].isoformat(), 'partid': row['group'], } for row in results ] return csv_response( csv_lines(['nume', 'inceput', 'sfarsit', 'partid'], membership_list), )