gauge/app/models/summary.rb

24 lines
667 B
Ruby
Raw Normal View History

2016-10-10 00:20:20 +03:00
class Summary
def initialize(params = {})
@talk_id, @other_talk_ids = params[:talk_id], params[:other_talk_ids]
@votes_count = SelectedTalk.where(talk_id: @talk_id).count
2016-10-10 00:33:09 +03:00
@all_votes_count = TalkPreference.joins(:selected_talks).where(selected_talks: {talk_id: @other_talk_ids << @talk_id}).uniq.count
2016-10-10 00:20:20 +03:00
end
def summary
{
talk_id: @talk_id,
votes: @votes_count,
all_votes: @all_votes_count,
per_cent: Rational(@votes_count, @all_votes_count).to_f,
conflicts: conflicts
}
end
def conflicts
@other_talk_ids.map do |right|
[right, ConflictCoefficient.new(@talk_id, right).conflicts]
end.to_h
end
end