Election results in the London Borough of Sutton.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

43 Zeilen
1.4 KiB

  1. require_relative '../models'
  2. require 'pp'
  3. # Set position and elected for each candidacy
  4. # WARNING - This will only work in full council elections not byelections (as the number of seats being elected in that eleciton is probably less than the total number of seats in the ward)
  5. # This will break all the byelection data currently in the database
  6. election = Election.first(:d => ARGV.shift)
  7. unless election
  8. puts "Election not found. Usage example: $ %s 2006-05-04" % __FILE__
  9. exit 1
  10. end
  11. puts "Setting candidacy positions for %s %s %s" % [ election.body.name, election.kind, election.d.to_s ]
  12. if election.candidacies.size < 30
  13. puts "This script only works for full council elections. Your election looks like a byelection, so quitting."
  14. exit 1
  15. end
  16. puts "%d candidacies in this election" % election.candidacies.size
  17. election.body.districts.each do |district|
  18. cands = Candidacy.all(:conditions => { :district_id => district.id, :election_id => election.id }, :order => [:votes.desc])
  19. # pp cands
  20. puts
  21. pos = 1
  22. cands.each do |cand|
  23. if pos == 1
  24. puts "-" * 62
  25. puts district.name
  26. puts "-" * 62
  27. end
  28. # If this candidate's position was in the top district.seats positions, they won a seat
  29. pos <= district.seats ? seats = 1 : seats = 0
  30. puts "%-25s %-25s %5d %2d %d" % [ cand.candidate.surname, cand.candidate.forenames, cand.votes, pos, seats ]
  31. cand.position = pos
  32. cand.seats = seats
  33. cand.save
  34. pos += 1
  35. end
  36. end