Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Refactored _init_reporting_units to use the elex data model. For #98.
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Jan 26, 2016
1 parent bd1516c commit 2ba880a
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions elections/ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,32 +468,34 @@ def _init_reporting_units(self):
# Create ReportingUnit objects for each race
for race in races:
ru = ReportingUnit(
name=r['ru_name'],
ap_number=r['ru_number'],
fips=r['ru_fip'],
abbrev=r['ru_abbrv'],
precincts_total=int(r['ru_precincts']),
num_reg_voters=None,
electiondate=race.electiondate,
statePostal=r['st_postal'],
stateName=race.statename,
level=r['rut_name'].lower(),
reportingunitName=r['ru_name'],
reportingunitID=r['ru_number'],
fipsCode=r['ru_fip'],
lastUpdated=None,
precinctsReporting=0,
precinctsTotal=int(r['ru_precincts']),
precinctsReportingPct=0.0,
uncontested=race.uncontested,
test=race.uncontested,
raceid=race.raceid,
racetype=race.racetype,
racetypeid=race.racetypeid,
officeid=race.officeid,
officename=race.officename,
seatname=race.seatname,
description=race.description,
seatnum=race.seatnum,
initialization_data=True,
national=race.national,
candidates=[],
votecount=0,
)
# This one is not always there, so we opt in.
if r.get('ru_reg_voters', None):
ru.num_reg_voters = int(r['ru_reg_voters'])
# And add them to the global store
race.reportingunits.append(ru)
# We add a set of reportingunits for the State object
# so you can get county and state voter info from the
# State object itself.
ru = ReportingUnit(
name=r['ru_name'],
ap_number=r['ru_number'],
fips=r['ru_fip'],
abbrev=r['ru_abbrv'],
precincts_total=int(r['ru_precincts']),
num_reg_voters=None,
)
if r.get('ru_reg_voters', None):
ru.num_reg_voters = int(r['ru_reg_voters'])
self._reporting_units.update({ru.key: ru})

def _get_flat_delegates(self):
"""
Expand Down

0 comments on commit 2ba880a

Please sign in to comment.