sorare-rewards 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 503bd2bc5d9b16f6c2ba4e9209c14920dc000730dc3466eea88534abe97187c2
4
- data.tar.gz: c03342737d6af15c514932029928fb26acd255700811e8bd9de53f62f7a5a91e
3
+ metadata.gz: dd12e11f5b4eb146655a6944d6ffd4b541a3cfe926e38b5bb77e7235d4cc92fd
4
+ data.tar.gz: 12acbcb47c3d6f366855278b96d75ab787414f802cbbfe9c597f98a96867c8ae
5
5
  SHA512:
6
- metadata.gz: 496c0f02f3c3735895c314d5f680a36fd3a2965a63d196f209efdd6cefcb6c9eaf5a8f5995c90a27ad36963cd68eb071f5467abf998738b856ca1a389dba87c6
7
- data.tar.gz: 5386e7e1e7f95c9b703882e5623c0aeec9ce71b4d9d46e85f807601e2f918b76c095dbac01f26ccfacd2262a0384d4f83ec22857810629e5b29ff274bc6a2d66
6
+ metadata.gz: 858689cacfc5e20404a485c5500266c613c47ec4838fbf909b7975594a6e1eb59cc96d0e3fa14cdc3cfdf4cea2b0f1ad9cd01adc215d02c0369d3ef02a3a7351
7
+ data.tar.gz: ba9f2aa66b4332ba1611f38a9b7fad80582bc1d03f67530bb356d203d4a71f9405ac353461ea4f6383775a03145adb923ade0762b9f1d89041299f7aa2b27e74
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorare-rewards (1.0.2)
4
+ sorare-rewards (1.1.0)
5
5
  activesupport (~> 6.1)
6
6
  interactor (~> 3.0)
7
7
  json (~> 2)
@@ -12,7 +12,7 @@ module Sorare
12
12
  @config = config
13
13
  end
14
14
 
15
- %w[cooldown limits prize_pool_currency].each do |key|
15
+ %w[cooldown limits prize_pool_currency rewards_ratio_per_cards_in_circulation].each do |key|
16
16
  define_method(key) do
17
17
  config[key]
18
18
  end
@@ -16,16 +16,14 @@ module Sorare
16
16
  def call
17
17
  context.rarity_supply = []
18
18
 
19
- context.rewardable = compute_rewardable_supply!
19
+ context.rewardable = rewardable_supply
20
20
  distribute_in_tiers!
21
21
  end
22
22
 
23
- def compute_rewardable_supply!
24
- total_supply = supply.keys.sum do |player|
25
- player_supply(player)
26
- end
23
+ def rewardable_supply
24
+ total_float_supply = supply.keys.sum { |player| player_supply(player) }
27
25
 
28
- rounded_supply(total_supply)
26
+ round_and_cap_supply(total_float_supply)
29
27
  end
30
28
 
31
29
  def distribute_in_tiers!
@@ -43,12 +41,15 @@ module Sorare
43
41
  end
44
42
  end
45
43
 
46
- def player_supply(slug)
47
- game_week.player(slug).reward_pool_supply_contribution(league, rarity)
44
+ def round_and_cap_supply(float_supply)
45
+ [
46
+ float_supply.floor + remaining_supply(float_supply.modulo(1)), # Supply limit
47
+ league.cards_in_circulation_limit(rarity) # Circulation limit
48
+ ].compact.min
48
49
  end
49
50
 
50
- def rounded_supply(float_supply)
51
- float_supply.floor + remaining_supply(float_supply.modulo(1))
51
+ def player_supply(slug)
52
+ game_week.player(slug).reward_pool_supply_contribution(league, rarity)
52
53
  end
53
54
 
54
55
  def remaining_supply(reward_probability)
@@ -17,12 +17,18 @@ module Sorare
17
17
  @game_week = game_week
18
18
  end
19
19
 
20
- %w[playing_rate prize_pools].each do |key|
20
+ %w[playing_rate prize_pools cards_in_circulation].each do |key|
21
21
  define_method(key) do
22
22
  config[key]
23
23
  end
24
24
  end
25
25
 
26
+ def cards_in_circulation_limit(rarity)
27
+ return unless cards_in_circulation&.dig(rarity) && game_week.config.rewards_ratio_per_cards_in_circulation
28
+
29
+ (cards_in_circulation[rarity] * game_week.config.rewards_ratio_per_cards_in_circulation).floor
30
+ end
31
+
26
32
  def each_division_prize_pools
27
33
  prize_pools.each_with_index do |prize_pool, index|
28
34
  return to_enum(:each_division_prize_pools) unless block_given?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sorare
4
4
  module Rewards
5
- VERSION = '1.0.2'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorare-rewards
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pierre