weighted_list_rank 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -0
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +25 -23
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/lib/weighted_list_rank/context.rb +0 -0
- data/lib/weighted_list_rank/item.rb +0 -0
- data/lib/weighted_list_rank/list.rb +0 -0
- data/lib/weighted_list_rank/strategies/exponential.rb +31 -7
- data/lib/weighted_list_rank/strategy.rb +0 -0
- data/lib/weighted_list_rank/version.rb +1 -1
- data/lib/weighted_list_rank.rb +0 -0
- data/sig/weighted_list_rank.rbs +0 -0
- metadata +2 -3
- data/weighted_list_rank.gemspec +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf34a6c62fda7d3038b31da0d7c8d9ec0b9a86a1b0204308e44d950e599f95b7
|
4
|
+
data.tar.gz: 3ed6316fa225185f79afa58899f2b0d29c0abb072c7835492be8dc14b1151b39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff08f7f218c00bd592e6c54a8862df527fb8c75cbfdf28ec4ccad44221c73b3fb699f590b0e8cb82c7b9e023e42f0fd285dab907a766864b88360cfb622dcdc2
|
7
|
+
data.tar.gz: 760b3d89d47fce1c4fa48899bdd9f58ee925bbe90937988028b1162f19b6afb4f157b37a7ff68b4964d6581f288834e9a065c372f68ca22bf0d31f572cda9806
|
data/.rubocop.yml
CHANGED
File without changes
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.3.1] - 2024-05-026
|
4
|
+
|
5
|
+
- Fixed issue with lists with only a single item getting bonus points
|
6
|
+
|
7
|
+
## [0.3.0] - 2024-02-03
|
8
|
+
|
9
|
+
- added bonus_pool_percentage feature to expoential
|
10
|
+
|
3
11
|
## [0.2.0] - 2024-02-03
|
4
12
|
|
5
13
|
- refactored the exponential algorithm to only add bonus points out of a pool of 50% of a list's weight
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
@@ -1,59 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
weighted_list_rank (0.
|
4
|
+
weighted_list_rank (0.3.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
|
-
json (2.7.
|
10
|
+
json (2.7.2)
|
11
11
|
language_server-protocol (3.17.0.3)
|
12
12
|
lint_roller (1.1.0)
|
13
|
-
minitest (5.
|
13
|
+
minitest (5.23.1)
|
14
14
|
parallel (1.24.0)
|
15
|
-
parser (3.3.0
|
15
|
+
parser (3.3.1.0)
|
16
16
|
ast (~> 2.4.1)
|
17
17
|
racc
|
18
|
-
racc (1.
|
18
|
+
racc (1.8.0)
|
19
19
|
rainbow (3.1.1)
|
20
|
-
rake (13.1
|
21
|
-
regexp_parser (2.9.
|
22
|
-
rexml (3.2.
|
23
|
-
|
20
|
+
rake (13.2.1)
|
21
|
+
regexp_parser (2.9.2)
|
22
|
+
rexml (3.2.8)
|
23
|
+
strscan (>= 3.0.9)
|
24
|
+
rubocop (1.63.5)
|
24
25
|
json (~> 2.3)
|
25
26
|
language_server-protocol (>= 3.17.0)
|
26
27
|
parallel (~> 1.10)
|
27
|
-
parser (>= 3.
|
28
|
+
parser (>= 3.3.0.2)
|
28
29
|
rainbow (>= 2.2.2, < 4.0)
|
29
30
|
regexp_parser (>= 1.8, < 3.0)
|
30
31
|
rexml (>= 3.2.5, < 4.0)
|
31
|
-
rubocop-ast (>= 1.
|
32
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
32
33
|
ruby-progressbar (~> 1.7)
|
33
34
|
unicode-display_width (>= 2.4.0, < 3.0)
|
34
|
-
rubocop-ast (1.
|
35
|
-
parser (>= 3.
|
36
|
-
rubocop-minitest (0.
|
37
|
-
rubocop (>= 1.
|
38
|
-
rubocop-ast (>= 1.
|
39
|
-
rubocop-performance (1.
|
35
|
+
rubocop-ast (1.31.3)
|
36
|
+
parser (>= 3.3.1.0)
|
37
|
+
rubocop-minitest (0.35.0)
|
38
|
+
rubocop (>= 1.61, < 2.0)
|
39
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
40
|
+
rubocop-performance (1.21.0)
|
40
41
|
rubocop (>= 1.48.1, < 2.0)
|
41
|
-
rubocop-ast (>= 1.
|
42
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
42
43
|
rubocop-rake (0.6.0)
|
43
44
|
rubocop (~> 1.0)
|
44
45
|
ruby-progressbar (1.13.0)
|
45
|
-
standard (1.
|
46
|
+
standard (1.36.0)
|
46
47
|
language_server-protocol (~> 3.17.0.2)
|
47
48
|
lint_roller (~> 1.0)
|
48
|
-
rubocop (~> 1.
|
49
|
+
rubocop (~> 1.63.0)
|
49
50
|
standard-custom (~> 1.0.0)
|
50
|
-
standard-performance (~> 1.
|
51
|
+
standard-performance (~> 1.4)
|
51
52
|
standard-custom (1.0.2)
|
52
53
|
lint_roller (~> 1.0)
|
53
54
|
rubocop (~> 1.50)
|
54
|
-
standard-performance (1.
|
55
|
+
standard-performance (1.4.0)
|
55
56
|
lint_roller (~> 1.1)
|
56
|
-
rubocop-performance (~> 1.
|
57
|
+
rubocop-performance (~> 1.21.0)
|
58
|
+
strscan (3.1.0)
|
57
59
|
unicode-display_width (2.5.0)
|
58
60
|
|
59
61
|
PLATFORMS
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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
|
-
#
|
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
|
-
|
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
|
-
#
|
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
|
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
|
-
return list.weight if item.position.nil?
|
46
|
+
return list.weight if item.position.nil? || list.items.count == 1
|
23
47
|
|
24
48
|
num_items = list.items.count
|
25
|
-
total_bonus_pool = list.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
|
File without changes
|
data/lib/weighted_list_rank.rb
CHANGED
File without changes
|
data/sig/weighted_list_rank.rbs
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weighted_list_rank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Sherman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -89,7 +89,6 @@ files:
|
|
89
89
|
- lib/weighted_list_rank/strategy.rb
|
90
90
|
- lib/weighted_list_rank/version.rb
|
91
91
|
- sig/weighted_list_rank.rbs
|
92
|
-
- weighted_list_rank.gemspec
|
93
92
|
homepage: https://github.com/ssherman/weighted_list_rank
|
94
93
|
licenses:
|
95
94
|
- MIT
|
data/weighted_list_rank.gemspec
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/weighted_list_rank/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "weighted_list_rank"
|
7
|
-
spec.version = WeightedListRank::VERSION
|
8
|
-
spec.authors = ["Shane Sherman"]
|
9
|
-
spec.email = ["shane.sherman@gmail.com"]
|
10
|
-
|
11
|
-
spec.summary = "generate ranks of items from weighted lists"
|
12
|
-
spec.description = "generate ranks of items from weighted lists"
|
13
|
-
spec.homepage = "https://github.com/ssherman/weighted_list_rank"
|
14
|
-
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.6.0"
|
16
|
-
|
17
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
|
-
|
19
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
-
spec.metadata["source_code_uri"] = "https://github.com/ssherman/weighted_list_rank"
|
21
|
-
spec.metadata["changelog_uri"] = "https://github.com/ssherman/weighted_list_rank/CHANGELOG.md"
|
22
|
-
|
23
|
-
# Specify which files should be added to the gem when it is released.
|
24
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
-
spec.files = Dir.chdir(__dir__) do
|
26
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
spec.bindir = "exe"
|
31
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
-
spec.require_paths = ["lib"]
|
33
|
-
|
34
|
-
# Uncomment to register a new dependency of your gem
|
35
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
-
spec.add_development_dependency "rubocop", "~> 1.0"
|
37
|
-
spec.add_development_dependency "standard", "~> 1.0"
|
38
|
-
spec.add_development_dependency "rubocop-minitest", "~> 0.3"
|
39
|
-
spec.add_development_dependency "rubocop-rake", "~> 0.6"
|
40
|
-
# For more information and examples about making a new gem, check out our
|
41
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
42
|
-
end
|