gauge/app/models/summary.rb

42 lines
966 B
Ruby
Raw Normal View History

2016-10-10 21:28:23 +03:00
class Summary
include ActiveModel::Model
attr_accessor :talk_ids
def number_of_ballots
@number_of_ballots ||= TalkPreference.joins(:selected_talks)
.where(selected_talks: {talk_id: @talk_ids})
.uniq.count
end
def most_conflicts
2020-10-16 00:15:35 +03:00
Conflicts.where(left: talk_ids, right: talk_ids).most&.conflicts || 0
end
def least_conflicts
2016-10-13 06:10:56 +03:00
if least_conflicts_for_single_talk == 0
0
else
least_conflicts_between_two_talks
end
end
2016-10-10 21:28:23 +03:00
def ranking
@ranking ||= Ranking.new(talk_ids: talk_ids).ranking
end
2016-10-13 06:10:56 +03:00
def conflicts
@conflicts ||= ConflictsSummary.new(talk_ids: talk_ids).conflicts
end
2016-10-13 06:10:56 +03:00
private
def least_conflicts_for_single_talk
2020-10-16 00:15:35 +03:00
ConflictsForTalk.where(talk_id: talk_ids).least&.conflicts || 0
2016-10-13 06:10:56 +03:00
end
def least_conflicts_between_two_talks
2020-10-16 00:15:35 +03:00
Conflicts.where(left: talk_ids, right: talk_ids).least&.conflicts || 0
2016-10-13 06:10:56 +03:00
end
2016-10-10 21:28:23 +03:00
end