weighted_list_rank 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/weighted_list_rank/strategies/exponential.rb +16 -10
- 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: afae67c4e97dd094fb6de0be3fd5dd0886372ae2edd873f61fdbc12f9c4b9e87
|
4
|
+
data.tar.gz: 8c12da106e959044d21a6889f35c959d91a637ae69ada9113744ce61ceed21fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c3c9b95c5ff8416938a36b8c04d6b066948284e0e2e414f7f037871ae88432441f3f617e32cc50d60d2cd7fad7cb5462735eae1ebacab8a4041c06e4c516b28
|
7
|
+
data.tar.gz: 9449fbe8419cb5a25ad1c1d5bdeae92831a14d95f81a43371755f1f369c59c53cbb01f3aefcd24fed8ad31a6de12b76d4bf81a219bf18d1bde0d7f01510b0950
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.1] - 2024-07-23
|
4
|
+
- 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
|
+
|
3
6
|
## [0.5.0] - 2024-07-23
|
4
7
|
- 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.
|
5
8
|
- 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.
|
@@ -36,32 +36,38 @@ module WeightedListRank
|
|
36
36
|
# Default score to the list's weight
|
37
37
|
score = list.weight
|
38
38
|
|
39
|
-
#
|
39
|
+
# Total number of items in the list
|
40
|
+
total_items = list.items.count
|
41
|
+
|
42
|
+
# Separate ranked and unranked items
|
40
43
|
ranked_items = list.items.select { |i| i.position }
|
41
|
-
unranked_items = list.items.reject { |i| i.position }
|
42
44
|
num_ranked_items = ranked_items.count
|
43
|
-
|
45
|
+
|
46
|
+
if num_ranked_items > 0 && item.position.nil?
|
47
|
+
# If there are ranked items, unranked items get no bonus, only the list's weight
|
48
|
+
return score
|
49
|
+
end
|
44
50
|
|
45
51
|
# Calculate the total bonus pool
|
46
52
|
total_bonus_pool = list.weight * bonus_pool_percentage
|
47
53
|
|
48
54
|
# Adjust the bonus pool based on the average list length
|
49
55
|
adjusted_bonus_pool = if average_list_length && average_list_length > 0
|
50
|
-
total_bonus_pool * (
|
56
|
+
total_bonus_pool * (total_items / average_list_length.to_f)
|
51
57
|
else
|
52
58
|
total_bonus_pool
|
53
59
|
end
|
54
60
|
|
55
61
|
if item.position.nil?
|
56
|
-
#
|
57
|
-
if include_unranked_items &&
|
58
|
-
unranked_bonus = adjusted_bonus_pool /
|
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
|
59
65
|
score += unranked_bonus
|
60
66
|
end
|
61
67
|
else
|
62
|
-
#
|
63
|
-
exponential_factor = (
|
64
|
-
total_exponential_factor = (1..
|
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 }
|
65
71
|
|
66
72
|
# Allocate a portion of the adjusted bonus pool based on the item's exponential factor
|
67
73
|
item_bonus = (exponential_factor / total_exponential_factor) * adjusted_bonus_pool
|