Compare commits
1 Commits
19e88cf520
...
6942b9042f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6942b9042f |
@ -1,27 +0,0 @@
|
|||||||
class AffinityGroupsHierarchy < Array
|
|
||||||
include Singleton
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
super
|
|
||||||
@references = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
def find(name)
|
|
||||||
@references[name]
|
|
||||||
end
|
|
||||||
|
|
||||||
def <<(name)
|
|
||||||
new_node = Tree::TreeNode.new(name)
|
|
||||||
super(new_node).tap { @references[name] = new_node }
|
|
||||||
end
|
|
||||||
|
|
||||||
def register_child(parent_name, child_name)
|
|
||||||
@references[parent_name] << Tree::TreeNode.new(child_name).tap { |child_node| @references[child_name] = child_node }
|
|
||||||
end
|
|
||||||
|
|
||||||
def distance(name_a, name_b)
|
|
||||||
return nil if @references[name_a].nil? || @references[name_b].nil?
|
|
||||||
|
|
||||||
@references[name_a].distance_to_common_ancestor(@references[name_b])
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,39 +0,0 @@
|
|||||||
require_relative '../../app/services/affinity_groups_hierarchy'
|
|
||||||
|
|
||||||
hierarchy = AffinityGroupsHierarchy.instance
|
|
||||||
|
|
||||||
hierarchy << 'guests_a'
|
|
||||||
hierarchy << 'guests_b'
|
|
||||||
hierarchy << 'common_guests'
|
|
||||||
|
|
||||||
hierarchy.register_child('guests_a', 'family_a')
|
|
||||||
hierarchy.register_child('family_a', 'close_family_a')
|
|
||||||
hierarchy.register_child('family_a', 'cousins_a')
|
|
||||||
hierarchy.register_child('family_a', 'relatives_a')
|
|
||||||
|
|
||||||
hierarchy.register_child('guests_a', 'work_a')
|
|
||||||
hierarchy.register_child('work_a', 'besties_work_a')
|
|
||||||
|
|
||||||
hierarchy.register_child('guests_a', 'friends_a')
|
|
||||||
hierarchy.register_child('friends_a', 'college_friends_a')
|
|
||||||
hierarchy.register_child('friends_a', 'high_school_friends_a')
|
|
||||||
hierarchy.register_child('friends_a', 'childhood_friends_a')
|
|
||||||
|
|
||||||
hierarchy.register_child('guests_a', 'sports_a')
|
|
||||||
hierarchy.register_child('sports_a', 'basket_team_a')
|
|
||||||
hierarchy.register_child('sports_a', 'football_team_a')
|
|
||||||
|
|
||||||
hierarchy.register_child('guests_b', 'family_b')
|
|
||||||
hierarchy.register_child('family_b', 'close_family_b')
|
|
||||||
hierarchy.register_child('family_b', 'cousins_b')
|
|
||||||
hierarchy.register_child('family_b', 'relatives_b')
|
|
||||||
|
|
||||||
hierarchy.register_child('guests_b', 'work_b')
|
|
||||||
hierarchy.register_child('work_b', 'besties_work_b')
|
|
||||||
|
|
||||||
hierarchy.register_child('guests_b', 'friends_b')
|
|
||||||
hierarchy.register_child('friends_b', 'college_friends_b')
|
|
||||||
hierarchy.register_child('friends_b', 'high_school_friends_b')
|
|
||||||
hierarchy.register_child('friends_b', 'childhood_friends_b')
|
|
||||||
|
|
||||||
hierarchy.register_child('common_guests', 'dance_club')
|
|
32
db/seeds.rb
32
db/seeds.rb
@ -28,26 +28,19 @@ Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
|
|||||||
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
|
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
|
||||||
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
|
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
|
||||||
|
|
||||||
|
|
||||||
samples = {
|
samples = {
|
||||||
close_family_a: 10,
|
close_family: 10,
|
||||||
close_family_b: 10,
|
family_1_group_a: 5,
|
||||||
cousins_a: 20,
|
family_1_group_b: 5,
|
||||||
cousins_b: 15,
|
family_2_group_a: 7,
|
||||||
relatives_a: 15,
|
family_2_group_b: 15,
|
||||||
relatives_b: 10,
|
previous_company: 5,
|
||||||
work_a: 10,
|
new_company: 20,
|
||||||
work_b: 10,
|
college: 10,
|
||||||
besties_work_a: 5,
|
high_school: 5,
|
||||||
besties_work_b: 5,
|
childhood: 5,
|
||||||
college_friends_a: 10,
|
basket_team: 20,
|
||||||
college_friends_b: 10,
|
soccer_team: 15,
|
||||||
high_school_friends_a: 10,
|
|
||||||
high_school_friends_b: 10,
|
|
||||||
childhood_friends_a: 10,
|
|
||||||
childhood_friends_b: 10,
|
|
||||||
basket_team_a: 10,
|
|
||||||
football_team_a: 15,
|
|
||||||
dance_club: 10
|
dance_club: 10
|
||||||
}.each_with_object([]) do |(affinity_group, count), acc|
|
}.each_with_object([]) do |(affinity_group, count), acc|
|
||||||
count.times { acc << affinity_group }
|
count.times { acc << affinity_group }
|
||||||
@ -63,7 +56,6 @@ end
|
|||||||
guest.save!
|
guest.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add unbreakable bonds
|
|
||||||
Guest.affinity_group_counts.each do |group|
|
Guest.affinity_group_counts.each do |group|
|
||||||
couples = (group.taggings_count / 4).floor
|
couples = (group.taggings_count / 4).floor
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user