Browse Source

Added council main stats to homepage

tags/last-sinatra-version
Adrian Short 16 years ago
parent
commit
f0bd3f36b4
2 changed files with 49 additions and 0 deletions
  1. +16
    -0
      app.rb
  2. +33
    -0
      views/home.haml

+ 16
- 0
app.rb View File

@@ -25,6 +25,22 @@ get '/' do
@wards = Ward.all
@results = repository(:default).adapter.query("
SELECT p.name,
sum(c.votes_2010) AS votes
FROM parties p,
councilcandidates c
WHERE p.id = c.party_id
GROUP BY p.id
ORDER BY votes desc
;")
@total_votes = Councilcandidate.sum(:votes_2010)
haml :home
end



+ 33
- 0
views/home.haml View File

@@ -10,6 +10,39 @@
%h2 Sutton Council Election Results
%table
%tr
%th
%th Votes
%th % Votes
%th Seats
%th % Seats
- for result in @results
%tr
%td= result[0]
%td.right= result[1]
%td.right= sprintf("%0.1f", result[1].to_f / @total_votes * 100)
%td.right
- if result[0] == 'Conservative Party'
11
- elsif result[0] == 'Liberal Democrats'
43
- else
0
%td.right
- if result[0] == 'Conservative Party'
20%
- elsif result[0] == 'Liberal Democrats'
80%
- else
0%
%p
Total votes:
= @total_votes
%p All ward results are now available below.
- for ward in @wards


Loading…
Cancel
Save