Class: DecisionMaker
- Inherits:
-
Object
- Object
- DecisionMaker
- Defined in:
- lib/wingify/packages/decision_maker/decision_maker.rb
Constant Summary collapse
- SEED_VALUE =
Seed value for the hash function
1
Instance Method Summary collapse
-
#calculate_bucket_value(str, multiplier = 1, max_value = 10000) ⇒ Integer
Calculates the bucket value for a given string with an optional multiplier and maximum value.
-
#generate_bucket_value(hash_value, max_value, multiplier = 1) ⇒ Integer
Generates a bucket value based on the hash value, maximum value, and an optional multiplier.
-
#generate_hash_value(hash_key) ⇒ Integer
Generates the hash value for a given hash key using MurmurHash v3.
-
#get_bucket_value_for_user(hash_key, max_value = 100) ⇒ Integer
Gets the bucket value for a user based on the hash key and maximum value.
Instance Method Details
#calculate_bucket_value(str, multiplier = 1, max_value = 10000) ⇒ Integer
Calculates the bucket value for a given string with an optional multiplier and maximum value.
48 49 50 51 |
# File 'lib/wingify/packages/decision_maker/decision_maker.rb', line 48 def calculate_bucket_value(str, multiplier = 1, max_value = 10000) hash_value = generate_hash_value(str) generate_bucket_value(hash_value, max_value, multiplier) end |
#generate_bucket_value(hash_value, max_value, multiplier = 1) ⇒ Integer
Generates a bucket value based on the hash value, maximum value, and an optional multiplier.
26 27 28 29 30 |
# File 'lib/wingify/packages/decision_maker/decision_maker.rb', line 26 def generate_bucket_value(hash_value, max_value, multiplier = 1) ratio = hash_value.to_f / (2**32) multiplied_value = ((max_value * ratio) + 1) * multiplier multiplied_value.floor end |
#generate_hash_value(hash_key) ⇒ Integer
Generates the hash value for a given hash key using MurmurHash v3.
57 58 59 |
# File 'lib/wingify/packages/decision_maker/decision_maker.rb', line 57 def generate_hash_value(hash_key) MurmurHash3::V32.str_hash(hash_key, SEED_VALUE) end |
#get_bucket_value_for_user(hash_key, max_value = 100) ⇒ Integer
Gets the bucket value for a user based on the hash key and maximum value.
37 38 39 40 |
# File 'lib/wingify/packages/decision_maker/decision_maker.rb', line 37 def get_bucket_value_for_user(hash_key, max_value = 100) hash_value = MurmurHash3::V32.str_hash(hash_key, SEED_VALUE) generate_bucket_value(hash_value, max_value) end |