weighted_list_rank 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 801eb04183d7dec5f99bfbcb76a902a920dcfee105f83f0c0c9a98667b73e6e4
4
- data.tar.gz: c5c5665b7205bc0fd52c4c7d23f34103ba2dfd764579e0a575897f8ce36e95af
3
+ metadata.gz: 02c97cc567dfd099a6f65066c534b3780d1a8ca7f8b6a2148d6410c348ed6db9
4
+ data.tar.gz: 235f31a73f88b44485d5c5a0fae360d6f4fe2a417e380ddaccadfa214af4d5d6
5
5
  SHA512:
6
- metadata.gz: 210d7a10b0978195b26a0fd3cbdfd068b93e09066ac332984e165d011170abb544837fc4aafd6cb410055bd7b412199733ca2d37e1190630aa5bd650f8f5df9a
7
- data.tar.gz: 65adb83584d5b1ec5d2282a0f8411edb147eb700f3030e9ab4c80def5ca8d2d7963166091cda87e8ea8a603a1c7f7168d28b661c2cbf0a4c6807b3617c47551c
6
+ metadata.gz: e908050bff4073ce084cc6b20a30992a52a08d93dc2732ae4e891605d2dc3c761166a79e90093ddb5b345ebe9da344c4ebe430fd9d9e1b780bccced0d4ee97fb
7
+ data.tar.gz: 67fa8168ec949cbdcb3c1dc728d8461ae0a4bf51234cef9d251eaf10b63eb8ca617d55945a719ea297cfe24c42a1ab89c871f8f090af601c97ec21f22b0c2b6f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2024-02-03
4
+
5
+ - added bonus_pool_percentage feature to expoential
6
+
3
7
  ## [0.2.0] - 2024-02-03
4
8
 
5
9
  - refactored the exponential algorithm to only add bonus points out of a pool of 50% of a list's weight
@@ -1,28 +1,52 @@
1
1
  module WeightedListRank
2
2
  module Strategies
3
+ # The Exponential strategy calculates the score of an item within a list using an exponential formula.
4
+ # This strategy emphasizes the significance of an item's rank within the list, where items with higher
5
+ # ranks (closer to 1) are exponentially more valuable than those with lower ranks. The magnitude of the bonus
6
+ # applied to each item's score is determined by the bonus pool percentage of the list's total weight.
7
+ #
8
+ # The exponential nature of the calculation is controlled by the +exponent+ attribute, allowing for
9
+ # flexible adjustment of how steeply the score decreases as rank increases. The +bonus_pool_percentage+
10
+ # attribute determines the size of the bonus pool as a percentage of the list's total weight, allowing
11
+ # customization of the bonus impact on the final scores.
3
12
  class Exponential < WeightedListRank::Strategy
13
+ # The exponent used in the score calculation formula. Higher values increase the rate at which
14
+ # scores decrease as item rank increases.
15
+ #
16
+ # @return [Float] the exponent value
4
17
  attr_reader :exponent
5
18
 
6
- # Initializes a new instance of the Exponential strategy with an optional exponent.
19
+ # The percentage of the list's total weight that constitutes the bonus pool. This value determines
20
+ # how the total bonus pool is calculated as a percentage of the list's weight.
21
+ #
22
+ # @return [Float] the bonus pool percentage, defaulting to 1.0 (100% of the list's weight).
23
+ attr_reader :bonus_pool_percentage
24
+
25
+ # Initializes a new instance of the Exponential strategy with optional parameters for exponent and
26
+ # bonus pool percentage.
7
27
  # @param exponent [Float] the exponent to use in the score calculation formula, defaults to 1.5.
8
- def initialize(exponent: 1.5)
28
+ # @param bonus_pool_percentage [Float] the percentage of the list's weight to be used as the bonus pool,
29
+ # defaults to 1.0 (100%).
30
+ def initialize(exponent: 1.5, bonus_pool_percentage: 1.0)
9
31
  @exponent = exponent
32
+ @bonus_pool_percentage = bonus_pool_percentage
10
33
  end
11
34
 
12
35
  # Calculates the score of an item within a list based on its rank position, the total number of items,
13
- # and the list's weight, using an exponential formula.
14
- # The bonus pool is set to 50% of the list's weight.
36
+ # and the list's weight, using an exponential formula. The bonus pool for score adjustments is determined
37
+ # by the specified bonus pool percentage of the list's total weight.
15
38
  #
16
39
  # @param list [WeightedListRank::List] the list containing the item being scored.
17
40
  # @param item [WeightedListRank::Item] the item for which to calculate the score.
18
41
  #
19
- # @return [Float] the calculated score for the item, adjusted by the list's weight and the specified exponent.
42
+ # @return [Float] the calculated score for the item, adjusted by the list's weight, the specified exponent,
43
+ # and the bonus pool percentage.
20
44
  def calculate_score(list, item)
21
45
  # Return the list weight if there are no positions
22
46
  return list.weight if item.position.nil?
23
47
 
24
48
  num_items = list.items.count
25
- total_bonus_pool = list.weight * 0.5 # Bonus pool is 50% of the list's weight
49
+ total_bonus_pool = list.weight * bonus_pool_percentage
26
50
 
27
51
  # Calculate the exponential factor for the item's rank position
28
52
  exponential_factor = (num_items + 1 - item.position)**exponent
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WeightedListRank
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weighted_list_rank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Sherman