weighted_list_rank 0.1.0 → 0.1.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 +8 -0
- data/Gemfile.lock +1 -1
- data/lib/weighted_list_rank/context.rb +1 -1
- data/lib/weighted_list_rank/strategies/exponential.rb +4 -0
- 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: 1f50527ee43cba5bd55144f8c76bc4b702cd2e84a797008aa4bed9cfa9b055a9
|
4
|
+
data.tar.gz: 0427e71591900a28fadcc5e68dae0bfbd71c7b97b00896953b5ecaec80ccbad7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2da62414b58dafb3ac4e49cbc18e0cb1b24c09edb78e0888365a3ac68e16e764974a83be8379dabe3a4291673170d7d1e80429a1a1c97189aa7ee3f1edbae597
|
7
|
+
data.tar.gz: 545f22a6c95c3713698c743e7f5fb1f2495034fc57ee81b4a745a8d064594cc9fa818fd5481d6443152a51e1fdaa5a7f1f362e17297f72a345a6e59a36255d12
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.2] - 2024-02-03
|
4
|
+
|
5
|
+
- Added list weight to rank result
|
6
|
+
-
|
7
|
+
## [0.1.1] - 2024-02-03
|
8
|
+
|
9
|
+
- Fixed Exponential strategy to just return the list weight if the item has a nil position
|
10
|
+
|
3
11
|
## [0.1.0] - 2024-02-01
|
4
12
|
|
5
13
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -22,7 +22,7 @@ module WeightedListRank
|
|
22
22
|
items[item.id] ||= {}
|
23
23
|
# Ensure the list_details array exists, then append the new score detail
|
24
24
|
items[item.id][:list_details] ||= []
|
25
|
-
items[item.id][:list_details] << {list_id: list.id, score: score}
|
25
|
+
items[item.id][:list_details] << {list_id: list.id, score: score, weight: list.weight}
|
26
26
|
|
27
27
|
# Ensure the total_score is initialized, then add the score
|
28
28
|
items[item.id][:total_score] ||= 0
|
@@ -29,6 +29,10 @@ module WeightedListRank
|
|
29
29
|
# @return [Float] the calculated score for the item, adjusted by the list's weight and the specified exponent.
|
30
30
|
def calculate_score(list, item)
|
31
31
|
rank_position = item.position
|
32
|
+
|
33
|
+
# if there are no positions, then just return the list weight
|
34
|
+
return list.weight if rank_position.nil?
|
35
|
+
|
32
36
|
num_items = list.items.count
|
33
37
|
|
34
38
|
contribution = ((num_items + 1 - rank_position)**exponent) / num_items.to_f
|