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 +4 -4
- data/CHANGELOG.md +7 -2
- data/lib/weighted_list_rank/strategies/exponential.rb +24 -24
- data/lib/weighted_list_rank/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c194a4b55fa9efecf1ad39fd54b8d22c2a9fd6766cb562c265c1f881deb08c4
|
4
|
+
data.tar.gz: 50dba99dde929b5bd3feed2709877c48d87bc45f6f9fcd745fd96d1b14749d7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|
-
|
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
|
-
|
59
|
-
|
50
|
+
# Calculate the total bonus pool
|
51
|
+
total_bonus_pool = list.weight * bonus_pool_percentage
|
60
52
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|