@@ -0,0 +1,1679 @@
+from collections import defaultdict%0A%0Afrom pandas import DataFrame%0Afrom rpy2.robjects.packages import importr%0A%0Afrom billy.core import db%0Afrom pscl import Rollcall, wnominate%0A%0A%0Apscl = importr('pscl')%0A%0A%0Aif __name__ == '__main__':%0A%0A    import sys%0A    state = sys.argv%5B1%5D%0A    session = sys.argv%5B2%5D%0A    chamber = sys.argv%5B3%5D%0A%0A    MISSING = 3%0A%0A    spec = dict(state=state, session=session, chamber=chamber)%0A    # spec = dict(state=state, session='2013-2014', chamber=chamber)%0A    chamber = spec%5B'chamber'%5D%0A    bill_ids = db.bills.find(spec).distinct('_id')%0A    votes = db.votes.find(%0A        %7B'bill_id': %7B'$in': bill_ids%7D,%0A         'chamber': chamber%7D)#.limit(50)%0A%0A    votedata = defaultdict(dict)%0A    vote_vals = dict(yes_votes=1, no_votes=2, other_votes=3)%0A    leg_ids = set()%0A%0A    for vote in votes:%0A        for k in 'yes_votes, no_votes, other_votes'.split(', '):%0A            for voter in vote%5Bk%5D:%0A                leg_id = voter%5B'leg_id'%5D%0A                if leg_id is None:%0A                    continue%0A                leg_ids.add(leg_id)%0A                votedata%5Bvote%5B'_id'%5D%5D%5Bleg_id%5D = vote_vals%5Bk%5D%0A    leg_ids = list(filter(None, leg_ids))%0A%0A    for vote_id, votes in votedata.items():%0A        votedata%5Bvote_id%5D = map(lambda leg_id: votes.get(leg_id, MISSING), leg_ids)%0A%0A    # Convert the dict into a pandas DataFrame.%0A    dataframe = DataFrame(votedata, index=leg_ids)%0A%0A    # Create a rollcall object similar to pscl's.%0A    rollcall = Rollcall.from_dataframe(dataframe,%0A        yea=%5B1%5D,%0A        nay=%5B2%5D,%0A        missing=%5B3%5D,%0A        not_in_legis=0.0,%0A        legis_names=leg_ids)%0A%0A    wn = wnominate(rollcall, polarity=%5B'NYL000161', 'NYL000134'%5D)%0A%0A    import pdb; pdb.set_trace()%0A

add wnominate test script