Compare commits
	
		
			3 Commits
		
	
	
		
			6942b9042f
			...
			19e88cf520
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 19e88cf520 | ||
| 1c940d1279 | |||
| 726470267d | 
							
								
								
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| source "https://rubygems.org" | ||||
| 
 | ||||
| ruby "3.2.0" | ||||
| ruby "3.3.4" | ||||
| 
 | ||||
| # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" | ||||
| gem "rails", "~> 7.1.3", ">= 7.1.3.2" | ||||
|  | ||||
| @ -283,7 +283,7 @@ DEPENDENCIES | ||||
|   web-console | ||||
| 
 | ||||
| RUBY VERSION | ||||
|    ruby 3.2.0p0 | ||||
|    ruby 3.3.4p94 | ||||
| 
 | ||||
| BUNDLED WITH | ||||
|    2.5.6 | ||||
|  | ||||
							
								
								
									
										27
									
								
								app/services/affinity_groups_hierarchy.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								app/services/affinity_groups_hierarchy.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| 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 | ||||
							
								
								
									
										39
									
								
								config/initializers/affinity_groups.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								config/initializers/affinity_groups.rb
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | ||||
| 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,19 +28,26 @@ Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed') | ||||
| Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed') | ||||
| Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed') | ||||
| 
 | ||||
| 
 | ||||
| samples = { | ||||
|   close_family: 10, | ||||
|   family_1_group_a: 5, | ||||
|   family_1_group_b: 5, | ||||
|   family_2_group_a: 7, | ||||
|   family_2_group_b: 15, | ||||
|   previous_company: 5, | ||||
|   new_company: 20, | ||||
|   college: 10, | ||||
|   high_school: 5, | ||||
|   childhood: 5, | ||||
|   basket_team: 20, | ||||
|   soccer_team: 15, | ||||
|   close_family_a: 10, | ||||
|   close_family_b: 10, | ||||
|   cousins_a: 20, | ||||
|   cousins_b: 15, | ||||
|   relatives_a: 15, | ||||
|   relatives_b: 10, | ||||
|   work_a: 10, | ||||
|   work_b: 10, | ||||
|   besties_work_a: 5, | ||||
|   besties_work_b: 5, | ||||
|   college_friends_a: 10, | ||||
|   college_friends_b: 10, | ||||
|   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 | ||||
| }.each_with_object([]) do |(affinity_group, count), acc| | ||||
|   count.times { acc << affinity_group } | ||||
| @ -56,6 +63,7 @@ end | ||||
|   guest.save! | ||||
| end | ||||
| 
 | ||||
| # Add unbreakable bonds | ||||
| Guest.affinity_group_counts.each do |group| | ||||
|   couples = (group.taggings_count / 4).floor | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user