sorare-rewards 0.1.0.beta11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 77c0cb011e78b240a5708daaef48b59be3bd6919c44fc0a84515314c77e2ee10
4
+ data.tar.gz: d248dd322adda855d1668f9b6cc3424d98c0c0a33dc95f5d7caf2b9b457b3fd7
5
+ SHA512:
6
+ metadata.gz: 921aa2e26ae7271027c6c91887e6a8a4bf975f4084bfce759871ca1a25192e8420c8aa25a5a9ed1e3854d4ec99d756fd267f7b66ee8c3bf5f36c0f7c3f33f49e
7
+ data.tar.gz: fc32cd8862c4de110f9a6d2f101755230a5aaa9c1b0c89bfbbba48b4d8ce5b9ab1d0a09afb2772d3db9f026d1879bee37c6c5ddd11faebb47e4385242a9baf97
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,43 @@
1
+ image: ruby:2.7.1
2
+
3
+ workflow:
4
+ rules:
5
+ - if: $CI_MERGE_REQUEST_ID
6
+ when: never
7
+ - when: always
8
+
9
+ stages:
10
+ - test
11
+
12
+ cache:
13
+ key: sorare-rewards-v1
14
+ paths:
15
+ - vendor/ruby
16
+
17
+ variables:
18
+ BUNDLE_BIN: vendor/bin
19
+
20
+ before_script:
21
+ - export PATH="$BUNDLE_BIN:$PATH"
22
+ - bundle config set path 'vendor'
23
+ - bundle install --jobs $(nproc)
24
+
25
+ rspec:
26
+ stage: test
27
+ cache:
28
+ # it is useless to have both rspec and lint update the cache
29
+ policy: pull
30
+ key: sorare-rewards-v1
31
+ paths:
32
+ - vendor/ruby
33
+ script:
34
+ - rspec
35
+ except:
36
+ - master
37
+
38
+ lint:
39
+ stage: test
40
+ script:
41
+ - rubocop --extra-details --display-style-guide
42
+ except:
43
+ - master
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,87 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-rake
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 2.7.1
8
+ Exclude:
9
+ - "bin/*"
10
+ - "vendor/**/*"
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - "Rakefile"
15
+ - "**/*.rake"
16
+ - "spec/**/*.rb"
17
+
18
+ Metrics/ClassLength:
19
+ Max: 120
20
+
21
+ Metrics/MethodLength:
22
+ Max: 12
23
+
24
+ Style/AsciiComments:
25
+ Enabled: false
26
+
27
+ Style/NonNilCheck:
28
+ Enabled: true
29
+ IncludeSemanticChanges: true
30
+
31
+ Naming/VariableNumber:
32
+ Enabled: false
33
+
34
+ RSpec/ImplicitSubject:
35
+ Enabled: false
36
+
37
+ RSpec/NamedSubject:
38
+ Enabled: false
39
+
40
+ RSpec/MessageSpies:
41
+ Enabled: false
42
+
43
+ RSpec/ExpectInHook:
44
+ Enabled: false
45
+
46
+ RSpec/NestedGroups:
47
+ Enabled: false
48
+
49
+ RSpec/LetSetup:
50
+ Enabled: false
51
+
52
+ RSpec/ExampleLength:
53
+ Enabled: false
54
+
55
+ RSpec/AnyInstance:
56
+ Enabled: false
57
+
58
+ RSpec/MessageChain:
59
+ Enabled: false
60
+
61
+ RSpec/FilePath:
62
+ SpecSuffixOnly: true
63
+
64
+ RSpec/ContextWording:
65
+ Prefixes:
66
+ - when
67
+ - with
68
+ - within
69
+ - without
70
+ - if
71
+ - unless
72
+ - for
73
+ - by
74
+ - in
75
+ - that
76
+ - who
77
+ - from
78
+
79
+ RSpec/MultipleMemoizedHelpers:
80
+ Enabled: false
81
+
82
+ RSpec/StubbedMock:
83
+ Enabled: false
84
+
85
+ Style/ExpandPathArguments:
86
+ Exclude:
87
+ - "*.gemspec"
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in sorare-rewards.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sorare-rewards (0.1.0.beta11)
5
+ activesupport (~> 6.1)
6
+ interactor (~> 3.0)
7
+ json (~> 2)
8
+ net-http (~> 0.1.1)
9
+ yaml (~> 0.1.1)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (6.1.3.2)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ zeitwerk (~> 2.3)
20
+ ast (2.4.2)
21
+ concurrent-ruby (1.1.8)
22
+ diff-lcs (1.4.4)
23
+ i18n (1.8.10)
24
+ concurrent-ruby (~> 1.0)
25
+ interactor (3.1.2)
26
+ json (2.5.1)
27
+ minitest (5.14.4)
28
+ net-http (0.1.1)
29
+ net-protocol
30
+ uri
31
+ net-protocol (0.1.0)
32
+ ostruct (0.2.0)
33
+ parallel (1.20.1)
34
+ parser (3.0.1.0)
35
+ ast (~> 2.4.1)
36
+ rainbow (3.0.0)
37
+ rake (12.3.3)
38
+ regexp_parser (2.1.1)
39
+ rexml (3.2.5)
40
+ rspec (3.10.0)
41
+ rspec-core (~> 3.10.0)
42
+ rspec-expectations (~> 3.10.0)
43
+ rspec-mocks (~> 3.10.0)
44
+ rspec-core (3.10.1)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-expectations (3.10.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-mocks (3.10.2)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-support (3.10.2)
53
+ rubocop (1.12.1)
54
+ parallel (~> 1.10)
55
+ parser (>= 3.0.0.0)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.8, < 3.0)
58
+ rexml
59
+ rubocop-ast (>= 1.2.0, < 2.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (>= 1.4.0, < 3.0)
62
+ rubocop-ast (1.4.1)
63
+ parser (>= 2.7.1.5)
64
+ rubocop-rake (0.5.1)
65
+ rubocop
66
+ rubocop-rspec (2.2.0)
67
+ rubocop (~> 1.0)
68
+ rubocop-ast (>= 1.1.0)
69
+ ruby-progressbar (1.11.0)
70
+ tzinfo (2.0.4)
71
+ concurrent-ruby (~> 1.0)
72
+ unicode-display_width (2.0.0)
73
+ uri (0.10.1)
74
+ yaml (0.1.1)
75
+ zeitwerk (2.4.2)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ ostruct (~> 0.2.0)
82
+ rake (~> 12.0)
83
+ rspec (~> 3.10)
84
+ rubocop (~> 1.12.1)
85
+ rubocop-rake (~> 0.5.1)
86
+ rubocop-rspec (~> 2.2.0)
87
+ sorare-rewards!
88
+
89
+ BUNDLED WITH
90
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 pierre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Sorare::Rewards
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sorare/rewards`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sorare-rewards'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sorare-rewards
22
+
23
+ ## Usage
24
+
25
+ To compute the rewards distribution for a given Game Week :
26
+
27
+ ```ruby
28
+ Sorare::Rewards::build_rewards(slug)
29
+ ```
30
+
31
+ With `slug` being the Fixture slug.
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sorare/rewards"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,165 @@
1
+ rare: &rare
2
+ tier_0:
3
+ - loop: 0
4
+ - loop: 0
5
+ - loop: 2
6
+ - loop: 1
7
+ tier_1:
8
+ - loop: 0
9
+ - loop: 0
10
+ - loop: 2
11
+ - loop: 1
12
+ tier_2:
13
+ - loop: 0
14
+ - loop: 0
15
+ - loop: 0
16
+ - loop: 1
17
+ tier_3:
18
+ - loop: 0
19
+ - loop: 0
20
+ - loop: 0
21
+ - loop: 1
22
+
23
+ super_rare: &super_rare
24
+ tier_0:
25
+ - loop: 2
26
+ - loop: 1
27
+ - loop: 0
28
+ - loop: 0
29
+ tier_1:
30
+ - loop: 1
31
+ - loop: 1
32
+ - loop: 0
33
+ - loop: 0
34
+ tier_2:
35
+ - loop: 0
36
+ - loop: 1
37
+ - loop: 0
38
+ - loop: 0
39
+ tier_3:
40
+ - loop: 0
41
+ - loop: 1
42
+ - loop: 0
43
+ - loop: 0
44
+
45
+ unique: &unique
46
+ tier_0:
47
+ - cards: 0
48
+ - cards: 0
49
+ - cards: 0
50
+ - cards: 0
51
+ tier_1:
52
+ - cards: 0
53
+ - cards: 0
54
+ - cards: 0
55
+ - cards: 0
56
+ tier_2:
57
+ - cards: 0
58
+ - cards: 0
59
+ - cards: 0
60
+ - cards: 0
61
+ tier_3:
62
+ - cards: 0
63
+ - cards: 0
64
+ - cards: 0
65
+ - cards: 0
66
+
67
+ empty: &empty
68
+ tier_0:
69
+ - cards: 0
70
+ - cards: 0
71
+ - cards: 0
72
+ - cards: 0
73
+ tier_1:
74
+ - cards: 0
75
+ - cards: 0
76
+ - cards: 0
77
+ - cards: 0
78
+ tier_2:
79
+ - cards: 0
80
+ - cards: 0
81
+ - cards: 0
82
+ - cards: 0
83
+ tier_3:
84
+ - cards: 0
85
+ - cards: 0
86
+ - cards: 0
87
+ - cards: 0
88
+
89
+ leagues:
90
+ global-all_star:
91
+ rare: *rare
92
+ super_rare: *super_rare
93
+ unique: *unique
94
+ global-under_twenty_one:
95
+ rare: *rare
96
+ super_rare: *super_rare
97
+ unique: *unique
98
+ champion-europe:
99
+ rare: *rare
100
+ super_rare: *super_rare
101
+ unique: *unique
102
+ challenger-europe:
103
+ rare: *rare
104
+ super_rare: *super_rare
105
+ unique: *unique
106
+ champion-asia:
107
+ rare: *rare
108
+ super_rare: *super_rare
109
+ unique: *unique
110
+ champion-america:
111
+ rare: *rare
112
+ super_rare: *super_rare
113
+ unique: *unique
114
+ special-weekly:
115
+ rare:
116
+ tier_0:
117
+ - pct: 1
118
+ tier_1:
119
+ - pct: 1
120
+ tier_2:
121
+ - pct: 1
122
+ tier_3:
123
+ - pct: 1
124
+ super_rare:
125
+ tier_0:
126
+ - pct: 1
127
+ tier_1:
128
+ - pct: 1
129
+ tier_2:
130
+ - pct: 1
131
+ tier_3:
132
+ - pct: 1
133
+ unique: *empty
134
+ starter-rookie:
135
+ unique:
136
+ tier_0:
137
+ - cards: 0
138
+ tier_1:
139
+ - cards: 0
140
+ tier_2:
141
+ - cards: 0
142
+ tier_3:
143
+ - cards: 0
144
+ super_rare:
145
+ tier_0:
146
+ - cards: 0
147
+ tier_1:
148
+ - cards: 0
149
+ tier_2:
150
+ - cards: 0
151
+ tier_3:
152
+ - cards: 0
153
+ rare:
154
+ tier_0:
155
+ - cards: 0
156
+ tier_1:
157
+ - cards: 1
158
+ tier_2:
159
+ - cards: 2
160
+ tier_3:
161
+ - cards: 0
162
+ global-unique_only:
163
+ rare: *empty
164
+ super_rare: *empty
165
+ unique: *empty
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Sorare
6
+ module Rewards
7
+ # Configuration stores the runtime configuration
8
+ class Configuration
9
+ attr_accessor :tiers, :gateway, :transform_tier, :transform_division, :allocation_configuration
10
+
11
+ def initialize
12
+ @tiers = 4
13
+ @gateway = 'https://gateway.pinata.cloud/ipfs/'
14
+ @transform_tier = ->(tier) { "tier_#{tier}" }
15
+ @transform_division = ->(division) { "D#{division}" }
16
+ @allocation_configuration = load_configuration
17
+ end
18
+
19
+ def load_configuration
20
+ YAML.safe_load(File.read("#{File.dirname(__FILE__)}/allocation_configuration.yml"), [], [], true)
21
+ .with_indifferent_access['leagues']
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'active_support/core_ext/enumerable'
5
+ require 'interactor'
6
+
7
+ module Sorare
8
+ module Rewards
9
+ module Allocations
10
+ # ComputeForGameWeek computes the reward allocations for a game week given a supply and seed
11
+ class ComputeForGameWeek
12
+ include Interactor
13
+
14
+ delegate :supply, :randomizer, :public_seed, :salt, to: :context
15
+
16
+ def call
17
+ context.randomizer = Sorare::Rewards::Random.new(public_seed, salt)
18
+ context.game_week_allocations = allocations
19
+ end
20
+
21
+ def allocations
22
+ supply.keys.index_with do |league|
23
+ Allocations::ComputeForLeague.call!(
24
+ **context.to_h, supply: supply[league], config: config[league]
25
+ ).league_allocations
26
+ end
27
+ end
28
+
29
+ def config
30
+ Sorare::Rewards.configuration.allocation_configuration
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'active_support/core_ext/enumerable'
5
+ require 'interactor'
6
+
7
+ module Sorare
8
+ module Rewards
9
+ module Allocations
10
+ # ComputeForLeague computes the reward allocations for a league given a supply and configuration
11
+ class ComputeForLeague
12
+ include Interactor
13
+
14
+ delegate :supply, :config, to: :context
15
+
16
+ def call
17
+ context.league_allocations = allocate_and_format!
18
+ end
19
+
20
+ def allocate_and_format!
21
+ allocations = allocate!
22
+
23
+ allocations.keys.index_with do |rarity|
24
+ allocations[rarity].first.keys.index_with do |division|
25
+ allocations[rarity].each_with_index.map do |qualified_allocations, tier|
26
+ [Sorare::Rewards.configuration.transform_tier.call(tier), qualified_allocations[division]]
27
+ end.to_h
28
+ end
29
+ end
30
+ end
31
+
32
+ def allocate!
33
+ supply.keys.index_with do |rarity|
34
+ ComputeForRarity.call!(**context.to_h, supply: supply[rarity], config: config[rarity]).rarity_allocations
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end