datadesk / python-elections

A Python wrapper for the Associated Press' U.S. election data service.
python-elections.rtfd.org
176 stars 46 forks source link

How are we going to get balance of power top-level numbers for House and Senate? #59

Closed palewire closed 12 years ago

schwanksta commented 12 years ago

We do have some code lying around to process their 'trends' xml file https://github.com/datadesk/projects.latimes.com/blob/master/projects/elections_20101102/fetch.py#L324

palewire commented 12 years ago
For the General Election, the APEO system provides continuously updated XML files containing national trend information for Governor, US Senate, US House, and States’ Legislative national trends. There is one XML file for each. The individual national trend tables provide a party breakdown if the present trends in the vote count continue for races for Governors, US Senate, US House, and State Legislatures. The parties are Dem (for Democrat), Rep (for Republican), and Oth for third-party and independent candidates. National States’ Legislative trends are broken down further by divisions – by state senate, state house, and states. They also contain a “split” party category for designating states that have a split-control or non-partisan legislature.
palewire commented 12 years ago

House headers

Won
Leading
Holdovers
Trend
Current
Net Change
palewire commented 12 years ago

Locations

/trend/xml/g.xml
/trend/xml/s.xml
/trend/xml/h.xml
/trend/xml/l.xml
palewire commented 12 years ago

There's also a more intense "Analytical" file for just house incumbents that has the following XML groups

Current
Incumbents Running
Incumbent Winners
Incumbent Leaders
Incumbent Trailers
Incumbent Losers
Challenger Winners
Challengers Losers
LOSERS
TRAILERS
schwanksta commented 12 years ago

Started a CongressionalTrends object that currently just has dem/gop net changes.

palewire commented 12 years ago

Excellent. We're moving here. We should do another example blog post when we get this thing ready.

schwanksta commented 12 years ago

Do we want governors?

palewire commented 12 years ago

I say let's lock down the essentials but make a ticket for it and come back if we have time. Unless @anthonyjpesce already has it in his sketches.

anthonyjpesce commented 12 years ago

Kinda depends on what we want the fan charts to do, no? If we want a raw +/- with no interactivity, then the change is enough. We could even do a toggle that fades in the current balance for comparison. If you want to be able to roll over a seat and get a name, district, and results we'll need more.

Unless the net change is what you had in mind for the homepage/widgets, in which case we'll need that too. And now that I think about it, I think we'll want that. Was that even helpful?

schwanksta commented 12 years ago

Since they decided to change the trends xml files without updating the info, here is the new info.

Current - The total number of seats for the office for each party, before the current election. Won - The number of seats for each party that have been declared winners by The AP in the current election. Leading - The number of seats for each party that are currently leading but have not been declared winners by The AP in the current election. Holdovers - The number of Governor or Senate seats for each party that are not up for election in the current election. (For example, only one-third of the Senate is up for election each year, so two-thirds of the senators are holdovers.) Note: For 2012, all US House seats are up for election, so Holdovers will be 0 for the US House. Winning Trend - Party breakdown if present trend continues (Won, Leading & Holdovers combined). Insufficient Vote – The number of seats for each party where the race is ignored in trend calculations. Races with fewer than 5% of precincts reporting, with less than 5% of registered voters having voted so far, and with no declared winner are considered to have insufficient votes. Uncalled, uncontested races are included as part of the Insufficient Vote.
Net Change - Net change is broken down into two subcategories - Winners and Leaders.

Net Change Winners – the number of seats that each party has won or lost in races where a winner has been declared. Any races where a winner has not been declared are ignored in this calculation. Examples: · If two races have been called and both for Democrats, and the incumbents in both of these races are Republicans, then the net change winners would be +2 for DEMs and -2 for GOP. · If a third race is then called with a GOP winner and a GOP incumbent, the net change would remain +2 DEM and =2 GOP. · If a fourth race is called for a GOP winner where the incumbent is a DEM, then the net change winners would be +1 DEM and -1 GOP.

Note: In 2012, there will be new districts where there is no incumbent. If a DEM wins in a new district +1 will be added to the DEM count. Also, there will also be districts with more than one incumbent. If there is a district with a DEM and GOP incumbent and the GOP wins, there will be 1 subtracted from the net change winners for DEMs and no change to the net change winner for GOP.

Net Change Leaders – the number of seats that each party would win or lose in races where the winner has not been declared. Races with insufficient votes are not included in Net Change Leaders. Net Change Winners and Net Change Leaders may be added together to get net change trends, assuming that the leaders will become winners.

Insufficient Vote section - Races with insufficient votes are broken down into categories based on the incumbent parties. Dem Open, GOP Open, and Oth Open – Races with one non-running Dem, GOP, or minor party incumbent Dem incumbent, GOP incumbent, Oth incumbent – Races with one Dem, GOP, or minor party incumbent who is running for re-election

Total – the total number of races with insufficient votes

anthonyjpesce commented 12 years ago

Can we get total numbers in addition to +/-? cc @Schwanksta

eads commented 12 years ago

+1 to total numbers from this end.

schwanksta commented 12 years ago

Ask and ye shall receive, @eads @anthonyjpesce https://github.com/datadesk/python-elections/commit/df96a02775c3eddb2ef15123554b3d69abccd19c

schwanksta commented 12 years ago

I'm trying to figure out if AP is just fucking with us or I don't understand, though:

also, misnomer, current_total means pre-election total for dems in the house, in this instance. won_total == the current number taking into account the winners so far. Should I call curent_total something else, or keep it in line with AP?

>>> t.house.dem_current_total - t.house.dem_won_total
13
>>> t.house.dem_net_change
-7
anthonyjpesce commented 12 years ago

@Schwanksta Can we also get the "insufficient vote" numbers? I would imagine that works well for a "not yet called" number?

Also, if I understand the documentation, to get a total for, say, senate democrats I would need t.senate.dem_won_total + t.senate.dem_holdovers?

schwanksta commented 12 years ago

I believe so, yes.

-Ken Schwencke

On Thu, Oct 18, 2012 at 4:58 PM, Anthony Pesce notifications@github.comwrote:

@Schwanksta https://github.com/Schwanksta Can we also get the "insufficient vote" numbers? I would imagine that works well for a "not yet called" number?

Also, if I understand the documentation, to get a total for, say, senate democrats I would need t.senate.dem_won_total + t.senate.dem_holdovers?

— Reply to this email directly or view it on GitHubhttps://github.com/datadesk/python-elections/issues/59#issuecomment-9585639.

palewire commented 12 years ago

@Schwanksta Is this done? I'm ig'nant.