Election results in the London Borough of Sutton.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Rakefile 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require './models'
  2. task default: :elections
  3. desc "List elections"
  4. task :elections do
  5. puts "%3s %-10s %-20s %6s" % %w( ID Date Body Candidacies)
  6. #puts "ID Date Body Candidacies"
  7. Election.each do |e|
  8. puts "%3d %s %-20s %6d" % [ e.id, e.d, e.body.name, e.candidacies.size ]
  9. end
  10. end
  11. desc "Set the candidate positions for an election (will prompt you for election ID)."
  12. task :set_positions do
  13. Election.all.each do |e|
  14. puts "%d %s %s" % [ e.id, e.d, e.body.name ]
  15. end
  16. puts "Which election ID?"
  17. STDOUT.flush
  18. id = STDIN.gets.chomp.to_i
  19. if e = Election.get(id)
  20. puts "%d %s %s" % [ e.id, e.d,e.body.name ]
  21. e.polls.each do |poll|
  22. poll.set_positions
  23. separator = '-' * poll.district.name.size
  24. puts
  25. puts separator
  26. puts poll.district.name
  27. puts separator
  28. ccys = Candidacy.all(:conditions => { :district_id => poll.district_id, :election_id => e.id }, :order => [:votes.desc])
  29. ccys.each do |cand|
  30. puts "%-25s %-25s %-40s %5d %2d %s" % [ cand.candidate.surname, cand.candidate.forenames, cand.party.name, cand.votes, cand.position, cand.seats == 1 ? 'elected' : '' ]
  31. end
  32. end
  33. else
  34. puts "Election ID #{id} not found."
  35. return 1
  36. end
  37. end