Conflict coefficients
This commit is contained in:
parent
cfcde965fe
commit
0fbe3243c4
|
@ -11,4 +11,8 @@ class HomeController < ApplicationController
|
|||
@talks = Talk.all
|
||||
@talk_preferences = TalkPreference.all
|
||||
end
|
||||
|
||||
def conflicts
|
||||
@conflict_coefficients = ConflictCoefficient.all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
class ConflictCoefficient
|
||||
attr_reader :left, :right, :conflicts
|
||||
|
||||
def self.all
|
||||
talk_combinations = Talk.all.map(&:id).combination(2)
|
||||
talk_preferences = TalkPreference.all
|
||||
talk_preferences_count = TalkPreference.count
|
||||
|
||||
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
|
|
@ -9,6 +9,10 @@ class TalkPreference < ActiveRecord::Base
|
|||
talks.include? id.to_s
|
||||
end
|
||||
|
||||
def include_all?(ids)
|
||||
ids.all? { |id| include? id }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assign_new_unique_id
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<%= CSV.generate_line([conflict_coefficient.left, conflict_coefficient.right, conflict_coefficient.conflicts, conflict_coefficient.per_cent]).html_safe -%>
|
|
@ -0,0 +1,3 @@
|
|||
<%- headers = ['left', 'right', 'conflicts', '%'] -%>
|
||||
<%= CSV.generate_line headers -%>
|
||||
<%= render partial: 'conflict_coefficient', collection: @conflict_coefficients %>
|
|
@ -3,4 +3,5 @@ Rails.application.routes.draw do
|
|||
root to: 'home#index'
|
||||
get 'ratings' => 'home#ratings'
|
||||
get 'export' => 'home#export'
|
||||
get 'conflicts' => 'home#conflicts'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue