예제 #1
0
 def __init__(self, cache, api_cache=None):
     self.cache = cache
     if api_cache:
         response_cache.enable(api_cache)
예제 #2
0
        dataframe = dataframe.fillna(value=self.NA)

        # Create a rollcall object similar to pscl's.
        rollcall = Rollcall.from_dataframe(dataframe,
                                           yea=[self.YES],
                                           nay=[self.NO],
                                           missing=[self.OTHER],
                                           not_in_legis=0.0,
                                           legis_names=tuple(self.leg_ids))

        return rollcall


if __name__ == '__main__':
    from sunlight import openstates, response_cache
    response_cache.enable('mongo')
    response_cache.logger.setLevel(10)

    # Wrangle the API data into a Rollcall object.
    spec = dict(state='al', chamber='lower', search_window='term:2011-2014')
    valid_ids = [leg['id'] for leg in openstates.legislators(**spec)]
    builder = RollcallBuilder(valid_ids)
    bills = openstates.bills(**spec)
    for bill in bills:
        bill = openstates.bill(bill['id'])
        for vote in bill['votes']:
            if vote['chamber'] != bill['chamber']:
                continue
            builder.add_vote(vote)

    rollcall = builder.get_rollcall()
예제 #3
0
파일: scores.py 프로젝트: twneale/bubs
import socket
from itertools import product, combinations
from collections import Counter, defaultdict
from operator import itemgetter

import rpy2
import networkx
import numpy as np
from pandas import DataFrame
from sunlight import response_cache, openstates
from pscl import Rollcall

from core import mongo, IterBills, IterLegislators, TooFewBillsError, DictSetDefault


response_cache.enable("mongo")
response_cache.logger.setLevel(100)


class DataQualityError(Exception):
    """Raised if calculation is aborted due to data quality issues.
    """


class ScoreCalculator(object):
    """Given a state, chamber, and term or session, calculate
    the cosponsorship pagerank, effectiveness, and ideal point
    scores for each legislator.
    """

    def __init__(self, abbr, chamber, meta, term=None, session=None):
예제 #4
0
 def __init__(self, cache, api_cache=None):
     self.cache = cache
     if api_cache:
         response_cache.enable(api_cache)
예제 #5
0
        dataframe = dataframe.fillna(value=self.NA)

        # Create a rollcall object similar to pscl's.
        rollcall = Rollcall.from_dataframe(dataframe,
            yea=[self.YES],
            nay=[self.NO],
            missing=[self.OTHER],
            not_in_legis=0.0,
            legis_names=tuple(self.leg_ids))

        return rollcall


if __name__ == '__main__':
    from sunlight import openstates, response_cache
    response_cache.enable('mongo')
    response_cache.logger.setLevel(10)

    # Wrangle the API data into a Rollcall object.
    spec = dict(state='al', chamber='lower', search_window='term:2011-2014')
    valid_ids = [leg['id'] for leg in openstates.legislators(**spec)]
    builder = RollcallBuilder(valid_ids)
    bills = openstates.bills(**spec)
    for bill in bills:
        bill = openstates.bill(bill['id'])
        for vote in bill['votes']:
            if vote['chamber'] != bill['chamber']:
                continue
            builder.add_vote(vote)

    rollcall = builder.get_rollcall()