Преглед на файлове

Add seats won and total number of candidates; Fix SQL incompatibility with Postgres

tags/last-sinatra-version
Adrian Short преди 12 години
родител
ревизия
e5db0c4520
променени са 2 файла, в които са добавени 9 реда и са изтрити 2 реда
  1. +5
    -1
      app.rb
  2. +4
    -1
      views/resultsdistrict.haml

+ 5
- 1
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
")


+ 4
- 1
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



Зареждане…
Отказ
Запис