Skip to content

Commit

Permalink
Tweak openstates example
Browse files Browse the repository at this point in the history
  • Loading branch information
twneale committed Apr 29, 2014
1 parent 9b4c139 commit 3a42124
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pscl/ext/openstates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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()

0 comments on commit 3a42124

Please sign in to comment.