From f0bd3f36b45d2445c050299403b0565152a510b0 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Fri, 7 May 2010 15:44:15 +0100 Subject: [PATCH] Added council main stats to homepage --- app.rb | 16 ++++++++++++++++ views/home.haml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/app.rb b/app.rb index d9bd293..7659342 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/views/home.haml b/views/home.haml index 3818967..c0740f0 100644 --- a/views/home.haml +++ b/views/home.haml @@ -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