Skip to content

Commit

Permalink
Fixing some key errors, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Tagliamonte committed Aug 10, 2012
1 parent a672168 commit 05fb128
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions experimental/condor/condor.py
Expand Up @@ -2,6 +2,8 @@

from billy import db

state = "oh"


def get_state_breakdown(abbr):
legs = db.legislators.find({"state": abbr})
Expand All @@ -10,6 +12,10 @@ def get_state_breakdown(abbr):
roles = leg['roles']
if len(roles) <= 0:
continue

if not "party" in roles[0]:
continue

parta = roles[0]['party'].strip()
if parta == "Republican":
repub.append(leg)
Expand Down Expand Up @@ -62,6 +68,11 @@ def grok_committee(cid):
if len(roles) <= 0:
missing += 1
continue

if not "party" in roles[0]:
missing += 1
continue

parta = roles[0]['party'].strip()
if parta == "Republican":
rCount += 1
Expand All @@ -72,6 +83,9 @@ def grok_committee(cid):
else:
missing += 1

if total == 0:
return None

rPct = rCount / total
dPct = dCount / total
oPct = oCount / total
Expand All @@ -88,24 +102,34 @@ def grok_committee(cid):

return (rD, dD, oD, pErr)

ctties = db.committees.find({"state": "az"})

raw = []
def digest_state(state):
ctties = db.committees.find({"state": state})

raw = []

for c in ctties:
ctty_stuff = grok_committee(c['_id'])
if ctty_stuff is None:
continue

rD, dD, oD, pE = ctty_stuff
raw.append({
"err": pE,
"repub": rD,
"dem": dD,
"other": oD,
"cid": c['_id']
})

demSkew = sorted(raw, key=lambda x: x['dem'])
repSkew = sorted(raw, key=lambda x: x['repub'])
othSkew = sorted(raw, key=lambda x: x['other'])
allSkew = sorted(raw, key=lambda x: (abs(x['dem']) + abs(x['repub']) + abs(x['other'])))

for c in ctties:
rD, dD, oD, pE = grok_committee(c['_id'])
raw.append({
"err": pE,
"repub": rD,
"dem": dD,
"other": oD,
"cid": c['_id']
})
return (demSkew, repSkew, othSkew, allSkew)

demSkew = sorted(raw, key=lambda x: x['dem'])
repSkew = sorted(raw, key=lambda x: x['repub'])
othSkew = sorted(raw, key=lambda x: x['other'])
allSkew = sorted(raw, key=lambda x: (abs(x['dem']) + abs(x['repub']) + abs(x['other'])))
states = [x['_id'] for x in db.metadata.find()]

print [x['dem'] for x in demSkew]
print allSkew
for state in states:
print digest_state(state)

0 comments on commit 05fb128

Please sign in to comment.