diff --git a/app.rb b/app.rb index 744970e..67ae1ed 100644 --- a/app.rb +++ b/app.rb @@ -175,13 +175,17 @@ get '/bodies/:body/elections/:date/:districts_name/:district' do @election = Election.first(:body => @body, :d => params[:date]) @candidacies = Candidacy.all(:district => @district, :election => @election, :order => [:votes.desc]) @total_votes = Candidacy.sum(:votes, :district => @district, :election => @election) + @total_candidates = Candidacy.count(:district => @district, :election => @election) + @total_seats = Candidacy.sum(:seats, :district => @district, :election => @election) @districts_in_this_election = @election.candidacies.districts + # 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 p.name AS party_name, p.colour AS party_colour, COUNT(c.id) AS num_candidates, + SUM(c.seats) AS num_seats, SUM(c.votes) AS total_votes FROM candidacies c @@ -192,7 +196,7 @@ get '/bodies/:body/elections/:date/:districts_name/:district' do WHERE c.district_id = #{@district.id} AND c.election_id = #{@election.id} - GROUP BY p.name + GROUP BY p.name, p.colour ORDER BY total_votes DESC ") diff --git a/views/resultsdistrict.haml b/views/resultsdistrict.haml index f1c814c..68c418c 100644 --- a/views/resultsdistrict.haml +++ b/views/resultsdistrict.haml @@ -40,6 +40,7 @@ %th %th %th + %th.right.highlight seats won %th candidates %th.right votes %th.right % votes @@ -52,6 +53,7 @@ %td.right= count %td{ :style => "background-color: #{row['party_colour'] }" }   %td= row['party_name'] + %td.right.highlight= row['num_seats'] %td.right= row['num_candidates'] %td.right= commify(row['total_votes']) %td.right= format_percent(row['total_votes'].to_f / @total_votes * 100) @@ -60,7 +62,8 @@ %td %td %td - %td + %td.right.highlight= @total_seats + %td.right= @total_candidates %td.right= commify(@total_votes) %td