Apr. 10th, 2011

Today, I wrote a Perl script to test some election scenarios. I noticed that in my riding, if the Liberals, the NDP and the Green would have run under one ticket in 2008 and assuming no defections, their candidate would have beat the Conservative candidate. So, my script runs that scenario and the scenario of just Liberals and NDP under one ticket. Here are the results for the non-green combined ticket:

Liberal+NDP ticket: 154 seats (exactly half of Parliament seats)
Conservative: 112 seats
Bloc: 42 seats

And the results for the Green-included combined ticket:

Liberal+NDP+Green ticket: 178 seats (clear Parliament majority)
Conservative: 89 seats
Bloc: 41 seats

Compare these hypothetical scenarios with the actual results:

Conservative: 143 seats
Liberal: 77 seats
Bloc: 50 seats
NDP: 38 seats

The raw data from Elections Canada is here(ZIPed .csv files) and this is the script:
#!perl
$file = shift;
$first = 1;
$cp = "\"Conservative\"";
$lp = "\"Liberal\"";
$np = "\"NDP-New Democratic Party\"";
$gp = "\"Green Party\"";
$bp = "\"Bloc Qu\xE9b\xE9cois\"";
$lnp = "Lib+NDP"; $lngp = "Lib+NDP+Green";

while ($file ne "") {
  $district = substr($file,27,5);
  open(FH, $file);
  while(<FH>) { #print $_;
    @line = split /,/; $p = $line[13]; $dv = $line[17];
    if (substr($p,0,1) ne "\"") { $p = "\"$p\""; }
    if ($p =~ /$cp/ || $p =~ /$np/ || $p =~ /$gp/ || $p =~ /$lp/ || $p =~ /$bp/) { $v{$p}+=$dv; }
    if ($p =~ /$lp/ || $p =~ /$np/) { $v{$lnp}+=$dv; }
    if ($p =~ /$lp/ || $p =~ /$np/ || $p =~ /$gp/) { $v{$lngp}+=$dv; }
  }
  close(FH);
  $titles = "District,"; $dv = "$district,";
  foreach $p (sort keys %v) { $titles .= "$p,"; $dv .= $v{$p} . ","; }
  if ($v{$cp} > $v{$np} && $v{$cp} > $v{$lp} && $v{$cp} > $v{$bp}) { $vcp++;  
        if ($v{$cp}>$v{$lnp}) { $vcp2++;} else {$vlnp++;} if ($v{$cp}>$v{$lngp}) { $vcp3++;} else {$vlngp++;}}
  if ($v{$lp} > $v{$np} && $v{$lp} > $v{$cp} && $v{$lp} > $v{$bp}) { $vlp++; $vlnp++; $vlngp++;}
  if ($v{$cp} < $v{$np} && $v{$np} > $v{$lp} && $v{$np} > $v{$bp}) { $vnp++; $vlnp++; $vlngp++;}
  if ($v{$cp} < $v{$bp} && $v{$bp} > $v{$lp} && $v{$np} < $v{$bp}) { $vbp++;  
        if ($v{$bp}>$v{$lnp}) { $vbp2++;} else {$vlnp++;} if ($v{$bp}>$v{$lngp}) { $vbp3++;} else {$vlngp++;}}
  #if ($first) { print "$titles\n"; $first=0; } print "$dv\n"; 
  $file = shift;
  $v{$lp}=$v{$cp}=$v{$gp}=$v{$np}=$v{$lnp}=$v{$lngp}=$v{$bp}=0;
}
$tot = $vcp+$vlp+$vnp+$vbp; $tot2 = $vcp2+$vlnp+$vbp2; $tot3 = $vcp3+$vlngp+$vbp3;
print "$cp: $vcp\tBQ: $vbp\tLiberal Party: $vlp\tNDP: $vnp\n";
print "$cp: $vcp2\tBQ: $vbp2\tLib+NDP(one ticket): $vlnp\n"; 
print "$cp: $vcp3\tBQ: $vbp3\tLib+NDP+Green(one ticket): $vlngp\n"; 
 

Profile

JMA-PSOS

December 2025

S M T W T F S
 1 234 56
78 9 1011 12 13
14 151617 181920
21 222324 252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 27th, 2025 08:26 pm
Powered by Dreamwidth Studios