wedding-planner/app/services/tables/discomfort_calculator.rb

26 lines
510 B
Ruby
Raw Normal View History

2024-07-31 22:53:19 +02:00
module Tables
class DiscomfortCalculator
private attr_reader :table
def initialize(table)
@table = table
end
def calculate
cohesion_penalty
2024-07-31 22:53:19 +02:00
end
private
def cohesion_penalty
table.map { |guest| guest.affinity_group_list.first }.combination(2).sum do |a, b|
distance = AffinityGroupsHierarchy.instance.distance(a, b)
next 1 if distance.nil?
next 0 if distance.zero?
2024-07-31 22:53:19 +02:00
Rational(distance, distance + 1)
end
2024-07-31 22:53:19 +02:00
end
end
end