| @@ -241,7 +241,8 @@ get '/bodies/:body/elections/:date/:districts_name/:district' do | |||||
| @total_candidates = Candidacy.count(:district => @district, :election => @election) | @total_candidates = Candidacy.count(:district => @district, :election => @election) | ||||
| @total_seats = Candidacy.sum(:seats, :district => @district, :election => @election) | @total_seats = Candidacy.sum(:seats, :district => @district, :election => @election) | ||||
| @districts_in_this_election = @election.candidacies.districts | @districts_in_this_election = @election.candidacies.districts | ||||
| @poll = Poll.get(@district.id, @election.id) | |||||
| # Postgres: All the columns selected when using GROUP BY must either be aggregate functions or appear in the GROUP BY clause | # Postgres: All the columns selected when using GROUP BY must either be aggregate functions or appear in the GROUP BY clause | ||||
| @results_by_party = repository(:default).adapter.select(" | @results_by_party = repository(:default).adapter.select(" | ||||
| SELECT | SELECT | ||||
| @@ -149,6 +149,14 @@ class Election | |||||
| self.all(:d.gte => Time.now.to_s, :order => [ :d.desc ]) | self.all(:d.gte => Time.now.to_s, :order => [ :d.desc ]) | ||||
| end | end | ||||
| # electorate and ballot_papers_issued assume there's a Poll object for every district in this election | |||||
| def electorate | |||||
| Poll.sum(:electorate, :election => self) | |||||
| end | |||||
| def ballot_papers_issued | |||||
| Poll.sum(:ballot_papers_issued, :election => self) | |||||
| end | |||||
| end | end | ||||
| class District | class District | ||||
| @@ -39,7 +39,7 @@ | |||||
| - unless @election_held | - unless @election_held | ||||
| .warning | .warning | ||||
| We don't have the results for this election yet. | We don't have the results for this election yet. | ||||
| %p= @election.reason | %p= @election.reason | ||||
| %p | %p | ||||
| @@ -107,6 +107,18 @@ | |||||
| %td | %td | ||||
| %td | %td | ||||
| %td | %td | ||||
| - if @election.ballot_papers_issued | |||||
| %table | |||||
| %tr | |||||
| %td Electorate | |||||
| %td.right= commify(@election.electorate) | |||||
| %tr | |||||
| %td Ballot papers issued | |||||
| %td.right= commify(@election.ballot_papers_issued) | |||||
| %tr | |||||
| %td Turnout | |||||
| %td.right= sprintf("%.0f%%", @election.ballot_papers_issued / @election.electorate.to_f * 100) | |||||
| %h2 | %h2 | ||||
| = @election.body.district_name.capitalize.pluralize(2) | = @election.body.district_name.capitalize.pluralize(2) | ||||
| @@ -39,6 +39,18 @@ | |||||
| .warning | .warning | ||||
| We don't have the results for this election yet. | We don't have the results for this election yet. | ||||
| - if @poll | |||||
| %table | |||||
| %tr | |||||
| %td Ballot papers issued | |||||
| %td.right= commify(@poll.ballot_papers_issued) | |||||
| %tr | |||||
| %td Electorate | |||||
| %td.right= commify(@poll.electorate) | |||||
| %tr | |||||
| %td Turnout | |||||
| %td.right= sprintf("%.0f%%", @poll.turnout_percent) | |||||
| %h2 Votes by party | %h2 Votes by party | ||||
| %table | %table | ||||
| @@ -128,3 +140,4 @@ | |||||
| %td.right= commify(@total_votes) | %td.right= commify(@total_votes) | ||||
| %td | %td | ||||
| %td | %td | ||||