gauge/app/models/conflict_coefficient.rb

34 lines
664 B
Ruby
Raw Normal View History

2015-10-15 02:01:03 +03:00
class ConflictCoefficient
attr_reader :left, :right
2015-10-15 02:01:03 +03:00
def self.all
Talk.find(:all, from: :halfnarp_friendly).map(&:id).combination(2).map do |talks|
ConflictCoefficient.new talks.first, talks.last
end
end
2015-10-15 02:01:03 +03:00
def conflicts
@conflicts ||= talk_preferences.select do |talk_preference|
talk_preference.include_all? [@left, @right]
end.count
end
2015-10-15 02:01:03 +03:00
def total_votes
talk_preferences.count
2015-10-15 02:01:03 +03:00
end
def initialize(left, right)
@left, @right = left, right
2015-10-15 02:01:03 +03:00
end
def per_cent
Rational(100 * conflicts, total_votes).to_f
end
private
def talk_preferences
@talk_preferences ||= TalkPreference.this_years
2015-10-15 02:01:03 +03:00
end
end