Explorar el Código

Add turnouts to election summaries and district results

tags/last-sinatra-version
Adrian Short hace 10 años
padre
commit
daab5c189a
Se han modificado 4 ficheros con 36 adiciones y 2 borrados
  1. +2
    -1
      app.rb
  2. +8
    -0
      models.rb
  3. +13
    -1
      views/electionsummary.haml
  4. +13
    -0
      views/resultsdistrict.haml

+ 2
- 1
app.rb Ver fichero

@@ -241,7 +241,8 @@ get '/bodies/:body/elections/:date/:districts_name/:district' do
@total_candidates = Candidacy.count(:district => @district, :election => @election)
@total_seats = Candidacy.sum(:seats, :district => @district, :election => @election)
@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
@results_by_party = repository(:default).adapter.select("
SELECT


+ 8
- 0
models.rb Ver fichero

@@ -149,6 +149,14 @@ class Election
self.all(:d.gte => Time.now.to_s, :order => [ :d.desc ])
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

class District


+ 13
- 1
views/electionsummary.haml Ver fichero

@@ -39,7 +39,7 @@
- unless @election_held
.warning
We don't have the results for this election yet.
%p= @election.reason

%p
@@ -107,6 +107,18 @@
%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
= @election.body.district_name.capitalize.pluralize(2)


+ 13
- 0
views/resultsdistrict.haml Ver fichero

@@ -39,6 +39,18 @@
.warning
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

%table
@@ -128,3 +140,4 @@
%td.right= commify(@total_votes)
%td  
%td  


Cargando…
Cancelar
Guardar