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