Browse Source

Show turnout for each election on body detail page

tags/last-sinatra-version
Adrian Short 8 years ago
parent
commit
28e03c45af
2 changed files with 27 additions and 1 deletions
  1. +19
    -1
      app.rb
  2. +8
    -0
      views/body.haml

+ 19
- 1
app.rb View File

@@ -189,8 +189,26 @@ end

get '/bodies/:body/?' do
@body = Body.first(:slug => params[:body])
@elections = Election.all(:body => @body, :order => [:d.desc])
@districts = District.all(:body => @body, :order => [:name])
@elections = repository(:default).adapter.select("
SELECT
e.id,
e.kind,
e.d,
SUM(p.ballot_papers_issued)::float / SUM(p.electorate) * 100 AS turnout_percent
FROM elections e
LEFT JOIN polls p
ON e.id = p.election_id

WHERE e.body_id = ?

GROUP BY p.election_id, e.id
ORDER BY e.d DESC
", @body.id)
haml :body
end



+ 8
- 0
views/body.haml View File

@@ -7,6 +7,11 @@
%h2 Elections

%table
%thead
%tr
%th
%th
%th turnout
- @elections.each do |election|
%tr
%td
@@ -14,6 +19,9 @@
= short_date(election.d)
%td
= election.kind
%td.right
- if election.turnout_percent
= format_percent(election.turnout_percent)
%h2
= @body.districts_name.capitalize


Loading…
Cancel
Save