From 3a421249b952696d3a57f3cfbc2892e65fe43038 Mon Sep 17 00:00:00 2001 From: twneale Date: Tue, 29 Apr 2014 12:44:44 -0400 Subject: [PATCH] Tweak openstates example --- pscl/ext/openstates.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pscl/ext/openstates.py b/pscl/ext/openstates.py index 17feb04..b2afc9c 100644 --- a/pscl/ext/openstates.py +++ b/pscl/ext/openstates.py @@ -9,7 +9,7 @@ class RollcallBuilder(object): '''Provides an easy(ish) way to build a rollcall object from the Open States API. ''' - def __init__(self, valid_ids, YES=1, NO=2, OTHER=3, NA=9): + def __init__(self, valid_ids, YES=1, NO=2, OTHER=3, NA=0): self.votedata = defaultdict(dict) self.YES = float(YES) self.NO = float(NO) @@ -40,7 +40,7 @@ def add_vote(self, vote): def get_rollcall(self): # Convert the dict into a pandas DataFrame. dataframe = DataFrame(self.votedata, index=self.leg_ids) - dataframe.fillna(value=self.NA) + dataframe = dataframe.fillna(value=self.NA) # Create a rollcall object similar to pscl's. rollcall = Rollcall.from_dataframe(dataframe, @@ -54,10 +54,11 @@ def get_rollcall(self): if __name__ == '__main__': - from sunlight import openstates, cache - cache.enable('mongo') - cache.logger.setLevel(10) + 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) @@ -70,4 +71,10 @@ def get_rollcall(self): builder.add_vote(vote) rollcall = builder.get_rollcall() + + wnominate = rollcall.wnominate(polarity=('ALL000086', 'ALL000085')) + wnom_values = wnominate.legislators.coord1D + + ideal = rollcall.ideal() + ideal_values = ideal.xbar import pdb; pdb.set_trace()