Skip to content
This repository
tree: 3bc677667c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 62 lines (45 sloc) 1.692 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/usr/bin/env ruby

if __FILE__ == $0
  require File.dirname(__FILE__) + '/../../config/environment'
else
  puts "Running from #{$0}"
end

people = Person.all_voting
i = 0
people.each do |p|
  i += 1
  
  PersonStats.transaction {
    puts "Calculating voting similarites for #{p.name} (#{i}/#{people.size})"

    top_votes_with, top_votes_apart = p.most_and_least_voting_similarities
  
    #puts "Top With:\n"
    #top_votes_with.each { |w| puts "#{w[0].name}\t\t#{w[1]}" }
    #puts "\n\nTop Apart:\n"
    #top_votes_apart.each { |w| puts "#{w[0].name}\t\t#{w[1]}" }
    
    if p.person_stats.nil?
      stats = PersonStats.new
      stats.person = p
      stats.save
    end
  
    if top_votes_with && top_votes_with[0]
      p.person_stats.votes_most_often_with = top_votes_with[0]
      puts "#{p.name} votes most often with #{top_votes_with[0].name}"
    end
  
    if top_votes_apart && top_votes_apart[0]
      p.person_stats.votes_least_often_with = top_votes_apart[0]
      puts "#{p.name} votes least often with #{top_votes_apart[0].name}"
    end
  
    if p.belongs_to_major_party?
      top_other_with = (top_votes_with.select { |a| a.party == p.opposing_party})[0]
      top_same_apart = (top_votes_apart.select { |a| a.party == p.party})[0]

      if top_other_with
        p.person_stats.opposing_party_votes_most_often_with = top_other_with
        puts "#{p.name} opposite votes most often with #{top_other_with.name}"
      end
    
      if top_same_apart
        p.person_stats.same_party_votes_least_often_with = top_same_apart
        puts "#{p.name} same votes least often with #{top_same_apart.name}"
      end
    end
  
    p.person_stats.save
  }
end



  
  
Something went wrong with that request. Please try again.