weighted_list_rank 0.5.1 → 0.5.2

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: afae67c4e97dd094fb6de0be3fd5dd0886372ae2edd873f61fdbc12f9c4b9e87
4
- data.tar.gz: 8c12da106e959044d21a6889f35c959d91a637ae69ada9113744ce61ceed21fc
3
+ metadata.gz: 9c194a4b55fa9efecf1ad39fd54b8d22c2a9fd6766cb562c265c1f881deb08c4
4
+ data.tar.gz: 50dba99dde929b5bd3feed2709877c48d87bc45f6f9fcd745fd96d1b14749d7d
5
5
  SHA512:
6
- metadata.gz: 1c3c9b95c5ff8416938a36b8c04d6b066948284e0e2e414f7f037871ae88432441f3f617e32cc50d60d2cd7fad7cb5462735eae1ebacab8a4041c06e4c516b28
7
- data.tar.gz: 9449fbe8419cb5a25ad1c1d5bdeae92831a14d95f81a43371755f1f369c59c53cbb01f3aefcd24fed8ad31a6de12b76d4bf81a219bf18d1bde0d7f01510b0950
6
+ metadata.gz: fafab0c49212017e8730cec2b78101e6adea7a85eedc938a0250d76643af7e4dea7fb6d1c49c8ed035675774bc4bf18f2e94eca46546ff8627a02b10d43fb1a7
7
+ data.tar.gz: 15e032d6eb71f6b65a825847e6850a8d4e7b248853d4a4480ab8f4ef7c276998dfd1ac0a3edea8f0a0fd19f788c571d84acac1e3d4fa1e8a1089aadd2e9cbab1
data/CHANGELOG.md CHANGED
@@ -1,15 +1,20 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.5.1] - 2024-07-23
3
+ ## [0.5.2] - 2024-08-21
4
+ - Fixed an issue in the `Exponential` strategy where `score_penalty` was not being applied to unranked items. Now, `score_penalty` is correctly applied to both ranked and unranked items, ensuring consistent scoring behavior.
4
5
  - Updated the `Exponential` strategy to prevent unranked items from receiving bonus points if the list contains both ranked and unranked items. In such cases, unranked items will now only receive the base weight of the list, ensuring ranked items are always prioritized.
5
6
 
6
- ## [0.5.0] - 2024-07-23
7
+ ## [0.5.1] - 2024-08-21
8
+ - Updated the `Exponential` strategy to prevent unranked items from receiving bonus points if the list contains both ranked and unranked items. In such cases, unranked items will now only receive the base weight of the list, ensuring ranked items are always prioritized.
9
+
10
+ ## [0.5.0] - 2024-08-21
7
11
  - Added `average_list_length` feature to the `Exponential` strategy to adjust the bonus pool based on the average number of items across all lists. This helps prevent smaller lists from receiving disproportionately large bonuses.
8
12
  - Introduced a new configuration option `include_unranked_items` in the `Exponential` strategy. When enabled, unranked items will receive an equal share of the bonus pool, while ranked items will receive an exponential bonus.
9
13
  - Updated RDoc documentation to explain the new `average_list_length` and `include_unranked_items` options.
10
14
  - Fixed test cases to correctly calculate expected values when using `average_list_length`.
11
15
  - Updated all dependencies to their latest versions.
12
16
 
17
+
13
18
  ## [0.4.2] - 2024-07-01
14
19
  - Fixed bug where a score could be set to 0. The lowest a score can be now is 1.
15
20
 
@@ -45,36 +45,36 @@ module WeightedListRank
45
45
 
46
46
  if num_ranked_items > 0 && item.position.nil?
47
47
  # If there are ranked items, unranked items get no bonus, only the list's weight
48
- return score
49
- end
50
-
51
- # Calculate the total bonus pool
52
- total_bonus_pool = list.weight * bonus_pool_percentage
53
-
54
- # Adjust the bonus pool based on the average list length
55
- adjusted_bonus_pool = if average_list_length && average_list_length > 0
56
- total_bonus_pool * (total_items / average_list_length.to_f)
48
+ score = list.weight
57
49
  else
58
- total_bonus_pool
59
- end
50
+ # Calculate the total bonus pool
51
+ total_bonus_pool = list.weight * bonus_pool_percentage
60
52
 
61
- if item.position.nil?
62
- # Unranked items get no bonus if there are ranked items
63
- if include_unranked_items && num_ranked_items == 0
64
- unranked_bonus = adjusted_bonus_pool / total_items
65
- score += unranked_bonus
53
+ # Adjust the bonus pool based on the average list length
54
+ adjusted_bonus_pool = if average_list_length && average_list_length > 0
55
+ total_bonus_pool * (total_items / average_list_length.to_f)
56
+ else
57
+ total_bonus_pool
66
58
  end
67
- else
68
- # Ranked items receive a bonus calculated using the exponential formula
69
- exponential_factor = (total_items + 1 - item.position)**exponent
70
- total_exponential_factor = (1..total_items).sum { |pos| (total_items + 1 - pos)**exponent }
71
59
 
72
- # Allocate a portion of the adjusted bonus pool based on the item's exponential factor
73
- item_bonus = (exponential_factor / total_exponential_factor) * adjusted_bonus_pool
74
- score += item_bonus
60
+ if item.position.nil?
61
+ # Unranked items get no bonus if there are ranked items
62
+ if include_unranked_items && num_ranked_items == 0
63
+ unranked_bonus = adjusted_bonus_pool / total_items
64
+ score += unranked_bonus
65
+ end
66
+ else
67
+ # Ranked items receive a bonus calculated using the exponential formula
68
+ exponential_factor = (total_items + 1 - item.position)**exponent
69
+ total_exponential_factor = (1..total_items).sum { |pos| (total_items + 1 - pos)**exponent }
70
+
71
+ # Allocate a portion of the adjusted bonus pool based on the item's exponential factor
72
+ item_bonus = (exponential_factor / total_exponential_factor) * adjusted_bonus_pool
73
+ score += item_bonus
74
+ end
75
75
  end
76
76
 
77
- # Apply score penalty if it exists
77
+ # Apply score penalty if it exists, for both ranked and unranked items
78
78
  score = apply_penalty(score, item.score_penalty)
79
79
 
80
80
  # Ensure the score is not less than 1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WeightedListRank
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Sherman