Giter Site home page Giter Site logo

elex's People

Contributors

achavez avatar benlk avatar buth avatar cynthiaechen avatar eads avatar giratikanon avatar jeremyjbowers avatar jiveman avatar jjelosua avatar kavyasukumar avatar livlab avatar mattl3w1s avatar mileswwatkins avatar palewire avatar pmlandwehr avatar rshorey avatar ryanpitts avatar stucka avatar syu15 avatar tylerfisher avatar vv-qian avatar wmandrews avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elex's Issues

Denormalization

Enough to do joins in the event someone would want to do that.

  • Denormalize some Election fields into Race.
  • Denormalize some Race and Election fields into ReportingUnit and Candidate

Duplicate race objects; one reporting unit per race?

If I'm using &level=reportingUnit&officeID=G, I should only see a single race that contains many reporting units, and those reporting units should contain many candidates.

Instead, the race object is duplicated and there is only a single reporting unit contained in each race.

screen shot 2015-10-26 at 9 29 20 am

Should parse out ballot positions.

This is going to be tricky; they shouldn't be stored as Candidate objects though the AP does. Would prefer to store them as a separate model before inserting them into the DB.

Tricky: Needs to get a description / common name from race.description and race.seatname. Will have to denormalize that down to the ReportingUnit for it to work.

  • Create model for BallotPosition.
  • Parse BallotPositions out of a ReportingUnit's candidates array.
  • Denormalize race.description and race.seatname down to ReportingUnit.
  • Denormalize reportingunit.description and reportingunit.seatname to a BallotPosition but ignore for Candidate.

Bug: `Election.get_race_objects()` fails with initialization data

ERROR: test_json_shape (tests.test_race.TestRaceInitialization)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jbowers/src/nyt/nyt-ap-elections/tests/test_race.py", line 70, in setUp
    self.race_objs = e.get_race_objects(self.raw_races)
  File "/Users/jbowers/src/nyt/nyt-ap-elections/elex/parser/api.py", line 412, in get_race_objects
    payload.append(Race(**r))
  File "/Users/jbowers/src/nyt/nyt-ap-elections/elex/parser/api.py", line 290, in __init__
    self.set_candidates()
  File "/Users/jbowers/src/nyt/nyt-ap-elections/elex/parser/api.py", line 81, in set_candidates
    candidate_dict['statename'] = STATE_ABBR[getattr(self, 'statepostal')]
AttributeError: 'Race' object has no attribute 'statepostal'

----------------------------------------------------------------------

Follow nextrequest link and load partial updates.

nextrequest features an URL with a timestamp that will return partial results as a diff between this state and the previous state.

  • Get an URL that can be used to test.
  • Load partial models in the DB; with update queries?
  • Run aggregations each time a load finishes.
  • Make assumptions about timing.

Tests

Anywhere we do math.

  • Aggregation: sums.
  • Aggregation: percentages.

Parsing layer.

  • Correct number of races.
  • Correct number of reporting units.
  • Correct number of candidate reporting units.

Anywhere we make data.

  • initialization_data
  • is_ballot_position
  • Unique BallotPosition creation.
  • Unique Candidate creation.

Winners.

  • Detect an AP winner.
  • Ask about edge cases.
  • Default to manual call if necessary.

Ballot position parsing is fragile.

Currently using raceType == "Ballot Issue" but this is probably fragile?

Emailed Tracy about getting a list of possible values for both the raceType and raceTypeID fields.

BUG: failing candidate reporting units test on CLI branch

======================================================================
FAIL: test_initialization_data_number_of_races (tests.test_race.TestRaceInitialization)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/deads/.virtualenvs/nyt-ap-elections/src/nyt-ap-elections/tests/test_race.py", line 87, in test_initialization_data_number_of_races
    self.assertEqual(len(self.candidate_reporting_units), 20)
AssertionError: 6 != 20

----------------------------------------------------------------------

JSON or XML?

XML request is:

  • Smaller
  • Downloads faster

JSON:

  • Slightly faster to parse
XML: 50 loops; 0.0778681230545s per loop.
JSON: 50 loops; 0.0713178396225s per loop.

Should parse out Candidate objects.

And not just what the AP defines as "Candidates" because those are actually more like CandidateResults, e.g., a single candidate's performance in a single reporting area.

  • Parse out only true human candidates, e.g., ignore ballot positions.

Bug: Race missing `national` attribute.

ERROR: test_race_get_units_construction (tests.test_race.TestRaceParsing)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jbowers/src/nyt/nyt-ap-elections/tests/test_race.py", line 59, in test_race_get_units_construction
    self.assertEqual(race.national, True)
AttributeError: 'Race' object has no attribute 'national'

----------------------------------------------------------------------```

Documentation.

Flow

  • Development
  • Production: Pre-election day
  • Production: On election day
  • Production: Once results are coming in
  • Production: When we've finished taking results
  • Production: When AP stops tabulation

Information Architecture

  • What is included?
  • What is missing?
  • Why did we pick our classes?

Customization

  • Recipe book

elex.loader should contain code to load Python objects into a database

  • __init__.py should contain the connection info, pulled from the environment.
  • Initially supports a Postgres database with Peewee.
  • Should drop, create tables.
  • Should (somehow) use attributes on the elex.parser.api classes without duplicating code.
  • Should use bulk inserts. Consider atomic transactions, pyscopg2 copy_from function.

Build out aggregates.

There will be more. But these certainly exist:

  • Race total votes.
  • Reporting unit total votes.
  • Reporting unit percentage of total race votes.
  • Candidate percentage of total race votes.
  • Candidate percentage of total reporting unit votes.

Bug: CandidateReportingUnit missing attribute `incumbent`.

ERROR: test_candidate_reporting_unit_attribute_construction (tests.test_candidate_reporting_unit.TestCandidateReportingUnitParsing)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jbowers/src/nyt/nyt-ap-elections/tests/test_candidate_reporting_unit.py", line 51, in test_candidate_reporting_unit_attribute_construction
    self.assertEqual(cru.incumbent, True)
AttributeError: 'CandidateReportingUnit' object has no attribute 'incumbent'

re-factor main data objects

Some of the logic would be better off abstracted. e.g.:

races, reporting_units, candidate_reporting_units = election.get_units(race_objs)

It would be nice if the magic happened behind the scenes, and you could just do:

races = election.races

Set environment variables to record to flat files or a JSON store.

User API should be something like export ELEX_RECORD=mongodb or export ELEX_RECORD=flat and then matching exports for ELEX_MONGODB_URL or ELEX_RECORD_DIR.

  • Watch environment vars to record JSON.
  • Use environment vars to direct types of recording.
  • Use environment vars to pass config to the recording method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.