Skip to content

Commit

Permalink
Added 2011 voter turnout to riding info page.
Browse files Browse the repository at this point in the history
  • Loading branch information
j3camero committed Sep 23, 2015
1 parent 96a4e8f commit 6bf78ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions riding.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$projected_winner = strtoupper($row['projected_winner']);
$strategic_vote = strtoupper($row['strategic_vote']);
$confidence = intval(round(100 * $row['confidence']));
$turnout_2011 = intval(round(100 * $row['turnout_2011']));
$data['con'] = intval(round(100 * $row['con']));
$data['lib'] = intval(round(100 * $row['lib']));
$data['ndp'] = intval(round(100 * $row['ndp']));
Expand Down Expand Up @@ -54,6 +55,9 @@
<span class="<?php echo $strategic_vote; ?>"
style="font-weight:bold"><?php echo $strategic_vote; ?></span>
</p>
<p>
Voter turnout in the last election &mdash; <?php echo $turnout_2011 ?>%
</p>
<p>If the election were held today, this is the projected popular vote in
the riding of <?php echo $riding_name; ?>, based on the latest polls.</p>
<?php
Expand Down
14 changes: 11 additions & 3 deletions riding_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,27 @@ def KeyWithHighestValue(d, forbidden_keys=[]):
population_transferred = float(
row['Population transferred to 2013 FED'])
population_percent = population_transferred / population_2013
all_votes = row['All votes']
electors = row['Electors on lists']
if new_riding_number not in new_ridings:
new_ridings[new_riding_number] = {
'name': new_riding_name,
'number': new_riding_number,
'province': province,
'feeders': {}}
'feeders': {},
'total_votes_2011': 0,
'total_electors_2011': 0,
'population': int(population_2013)}
r = new_ridings[new_riding_number]
r['feeders'][old_riding_number] = population_percent
r['total_votes_2011'] += int(all_votes)
r['total_electors_2011'] += int(electors)

# Output final stats for each riding.
party_order = ['CON', 'NDP', 'LIB', 'GRN', 'BQ']
print ('province,name,number,' +
','.join(p.lower() for p in party_order) +
',projected_winner,strategic_vote,confidence')
',projected_winner,strategic_vote,confidence,turnout_2011')
for r in new_ridings.values():
projections = {}
for feeder_number, weight in r['feeders'].items():
Expand All @@ -225,6 +232,7 @@ def KeyWithHighestValue(d, forbidden_keys=[]):
strategic_vote = KeyWithHighestValue(projections, ['CON'])
gap = projections[projected_winner] - projections[runner_up]
confidence = norm.cdf(gap / 0.25)
turnout = float(r['total_votes_2011']) / r['total_electors_2011']
row = ([r['province'], r['name'], r['number']] + ordered_projections +
[projected_winner, strategic_vote, confidence])
[projected_winner, strategic_vote, confidence, turnout])
print ','.join([str(x) for x in row])

0 comments on commit 6bf78ac

Please sign in to comment.