sorare-rewards 0.1.0.beta11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.gitlab-ci.yml +43 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +87 -0
  6. data/Gemfile +8 -0
  7. data/Gemfile.lock +90 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +42 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/lib/sorare/rewards/allocation_configuration.yml +165 -0
  14. data/lib/sorare/rewards/configuration.rb +25 -0
  15. data/lib/sorare/rewards/interactors/allocations/compute_for_game_week.rb +35 -0
  16. data/lib/sorare/rewards/interactors/allocations/compute_for_league.rb +40 -0
  17. data/lib/sorare/rewards/interactors/allocations/compute_for_quality.rb +96 -0
  18. data/lib/sorare/rewards/interactors/allocations/compute_for_rarity.rb +34 -0
  19. data/lib/sorare/rewards/interactors/build.rb +33 -0
  20. data/lib/sorare/rewards/interactors/cards/pick_for_division.rb +44 -0
  21. data/lib/sorare/rewards/interactors/cards/pick_for_division_and_rarity.rb +37 -0
  22. data/lib/sorare/rewards/interactors/cards/pick_for_division_rarity_and_quality.rb +49 -0
  23. data/lib/sorare/rewards/interactors/cards/pick_for_game_week.rb +40 -0
  24. data/lib/sorare/rewards/interactors/cards/pick_for_league.rb +64 -0
  25. data/lib/sorare/rewards/interactors/pick.rb +34 -0
  26. data/lib/sorare/rewards/interactors/supply/compute_for_game_week.rb +28 -0
  27. data/lib/sorare/rewards/interactors/supply/compute_for_league.rb +24 -0
  28. data/lib/sorare/rewards/interactors/supply/compute_for_quality.rb +37 -0
  29. data/lib/sorare/rewards/interactors/supply/compute_for_rarity.rb +73 -0
  30. data/lib/sorare/rewards/interactors/tiers/qualify_players.rb +69 -0
  31. data/lib/sorare/rewards/interactors/tiers/qualify_supply.rb +40 -0
  32. data/lib/sorare/rewards/random.rb +14 -0
  33. data/lib/sorare/rewards/transposer.rb +28 -0
  34. data/lib/sorare/rewards/version.rb +7 -0
  35. data/lib/sorare/rewards.rb +38 -0
  36. data/sorare-rewards.gemspec +44 -0
  37. metadata +220 -0
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'interactor'
5
+
6
+ module Sorare
7
+ module Rewards
8
+ module Tiers
9
+ # QualifySupply qualifies a supply sorted by rank in tiers
10
+ # Returns an array of supply per tier
11
+ class QualifySupply
12
+ include Interactor
13
+
14
+ delegate :sorted_supply, to: :context
15
+
16
+ def call
17
+ context.count = sorted_supply.values.sum { |p| p['supply'] }
18
+ context.supply = qualified_supply
19
+ end
20
+
21
+ def qualified_supply
22
+ return qualify! unless sorted_supply.values.first&.dig('tier')
23
+
24
+ tiers = Array.new(Sorare::Rewards.configuration.tiers, 0)
25
+ sorted_supply.each_value do |data|
26
+ tiers[data['tier'].to_i] += data['supply']
27
+ end
28
+
29
+ tiers
30
+ end
31
+
32
+ def qualify!
33
+ QualifyPlayers.call!(sorted_supply: sorted_supply).players.map do |tier_players|
34
+ tier_players.sum { |p| sorted_supply[p]['supply'] }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/enumerable'
4
+
5
+ module Sorare
6
+ module Rewards
7
+ # Random serves as an extension of the default Random class to work with the salt and seed
8
+ class Random < ::Random
9
+ def initialize(seed, salt)
10
+ super Digest::SHA256.hexdigest("#{seed}#{salt}").to_i(16)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/enumerable'
4
+
5
+ module Sorare
6
+ module Rewards
7
+ # TransposeAllocations transposes the computed allocations
8
+ # { 'league' => { 'rarity' => { 'division' => ... } } }
9
+ # to a division based allocations
10
+ # { 'league' => { 'division' => { 'rarity' => ... } } }
11
+ module Transposer
12
+ def self.transpose_allocations(allocations)
13
+ allocations.keys.index_with do |league|
14
+ transpose_league(allocations[league])
15
+ end
16
+ end
17
+
18
+ def self.transpose_league(allocations)
19
+ allocations.each_with_object({}) do |(rarity, league_allocations), hash|
20
+ league_allocations.each do |division, supply|
21
+ hash[division] = {} unless hash[division]
22
+ hash[division][rarity] = supply
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sorare
4
+ module Rewards
5
+ VERSION = '0.1.0.beta11'
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'digest'
6
+
7
+ Dir["#{File.dirname(__FILE__)}/rewards/**/*.rb"].sort.each do |file|
8
+ require file
9
+ end
10
+
11
+ module Sorare
12
+ # Rewards gem root
13
+ module Rewards
14
+ class << self
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
23
+
24
+ def self.game_week_data(hash)
25
+ uri = URI("#{configuration.gateway}#{hash}")
26
+ JSON.parse(::Net::HTTP.get(uri))
27
+ end
28
+
29
+ def self.build_rewards(salt:, hash: nil, data: nil)
30
+ Sorare::Rewards::Build.call!(data: data || game_week_data(hash), salt: salt).allocations
31
+ end
32
+
33
+ def self.pick(salt:, hash: nil, data: nil)
34
+ allocation_ctx = Sorare::Rewards::Build.call!(data: data || game_week_data(hash), salt: salt)
35
+ Sorare::Rewards::Pick.call!(allocation_ctx.to_h).picks
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/sorare/rewards/version'
4
+
5
+ # rubocop:disable Metrics/BlockLength
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sorare-rewards'
8
+ spec.version = Sorare::Rewards::VERSION
9
+ spec.authors = ['pierre']
10
+ spec.email = ['pierre@sorare.com']
11
+
12
+ spec.summary = %w[Sorare reward allocation algorithm]
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = 'https://gitlab.com/sorare/sorare-rewards'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.1')
17
+
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://gitlab.com/sorare/sorare-rewards'
22
+ # spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'activesupport', '~> 6.1'
34
+ spec.add_dependency 'interactor', '~> 3.0'
35
+ spec.add_dependency 'json', '~> 2'
36
+ spec.add_dependency 'net-http', '~> 0.1.1'
37
+ spec.add_dependency 'yaml', '~> 0.1.1'
38
+ spec.add_development_dependency 'ostruct', '~> 0.2.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.10'
40
+ spec.add_development_dependency 'rubocop', '~> 1.12.1'
41
+ spec.add_development_dependency 'rubocop-rake', '~> 0.5.1'
42
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.2.0'
43
+ end
44
+ # rubocop:enable Metrics/BlockLength
metadata ADDED
@@ -0,0 +1,220 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sorare-rewards
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta11
5
+ platform: ruby
6
+ authors:
7
+ - pierre
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: interactor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: yaml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: ostruct
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.12.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.12.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.5.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.5.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.2.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.2.0
153
+ description:
154
+ email:
155
+ - pierre@sorare.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".gitlab-ci.yml"
162
+ - ".rspec"
163
+ - ".rubocop.yml"
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - bin/console
170
+ - bin/setup
171
+ - lib/sorare/rewards.rb
172
+ - lib/sorare/rewards/allocation_configuration.yml
173
+ - lib/sorare/rewards/configuration.rb
174
+ - lib/sorare/rewards/interactors/allocations/compute_for_game_week.rb
175
+ - lib/sorare/rewards/interactors/allocations/compute_for_league.rb
176
+ - lib/sorare/rewards/interactors/allocations/compute_for_quality.rb
177
+ - lib/sorare/rewards/interactors/allocations/compute_for_rarity.rb
178
+ - lib/sorare/rewards/interactors/build.rb
179
+ - lib/sorare/rewards/interactors/cards/pick_for_division.rb
180
+ - lib/sorare/rewards/interactors/cards/pick_for_division_and_rarity.rb
181
+ - lib/sorare/rewards/interactors/cards/pick_for_division_rarity_and_quality.rb
182
+ - lib/sorare/rewards/interactors/cards/pick_for_game_week.rb
183
+ - lib/sorare/rewards/interactors/cards/pick_for_league.rb
184
+ - lib/sorare/rewards/interactors/pick.rb
185
+ - lib/sorare/rewards/interactors/supply/compute_for_game_week.rb
186
+ - lib/sorare/rewards/interactors/supply/compute_for_league.rb
187
+ - lib/sorare/rewards/interactors/supply/compute_for_quality.rb
188
+ - lib/sorare/rewards/interactors/supply/compute_for_rarity.rb
189
+ - lib/sorare/rewards/interactors/tiers/qualify_players.rb
190
+ - lib/sorare/rewards/interactors/tiers/qualify_supply.rb
191
+ - lib/sorare/rewards/random.rb
192
+ - lib/sorare/rewards/transposer.rb
193
+ - lib/sorare/rewards/version.rb
194
+ - sorare-rewards.gemspec
195
+ homepage: https://gitlab.com/sorare/sorare-rewards
196
+ licenses:
197
+ - MIT
198
+ metadata:
199
+ homepage_uri: https://gitlab.com/sorare/sorare-rewards
200
+ source_code_uri: https://gitlab.com/sorare/sorare-rewards
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: 2.7.1
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">"
213
+ - !ruby/object:Gem::Version
214
+ version: 1.3.1
215
+ requirements: []
216
+ rubygems_version: 3.1.6
217
+ signing_key:
218
+ specification_version: 4
219
+ summary: '["Sorare", "reward", "allocation", "algorithm"]'
220
+ test_files: []