Class: Sorare::Rewards::Supply::ComputeForRarity

Inherits:
Object
  • Object
show all
Includes:
Interactor
Defined in:
lib/sorare/rewards/interactors/supply/compute_for_rarity.rb

Overview

ComputeForRarity computes the rewardable supply for a given rarity

Instance Method Summary collapse

Instance Method Details

#callObject



17
18
19
20
21
22
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 17

def call
  context.rarity_supply = []

  context.rewardable = rewardable_supply
  distribute_in_tiers!
end

#capped_tier_supply(total_supply, tier_supply, rewardable, tier_players) ⇒ Object

Cap with the actual pickable supply for the tier



41
42
43
44
45
46
47
48
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 41

def capped_tier_supply(total_supply, tier_supply, rewardable, tier_players)
  target = ComputeForQuality.call!(
    randomizer: randomizer, total_supply: total_supply,
    tier_supply: tier_supply, rewardable: rewardable, rewarded: rarity_supply
  ).quality_supply

  [target, tier_players.sum { |player| player_pickable_supply(player) }].min
end

#distribute_in_tiers!Object



30
31
32
33
34
35
36
37
38
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 30

def distribute_in_tiers!
  ctx = Tiers::QualifySupply.call!(sorted_supply: supply)
  qualified_players = Tiers::QualifyPlayers.call!(sorted_supply: supply).players
  ctx.supply.each_with_index do |tier_supply, index|
    rarity_supply.push(
      capped_tier_supply(ctx.count, tier_supply, rewardable, qualified_players[index])
    )
  end
end

#player_contribution(slug) ⇒ Object



57
58
59
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 57

def player_contribution(slug)
  game_week.player(slug).supply_for(league, rarity).pool_contribution
end

#player_pickable_supply(slug) ⇒ Object



61
62
63
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 61

def player_pickable_supply(slug)
  game_week.player(slug).supply_for(league, rarity).available
end

#remaining_supply(reward_probability) ⇒ Object



65
66
67
68
69
70
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 65

def remaining_supply(reward_probability)
  probability = randomizer.rand
  return 0 unless probability < reward_probability

  1
end

#rewardable_supplyObject



24
25
26
27
28
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 24

def rewardable_supply
  total_float_supply = supply.keys.sum { |player| player_contribution(player) }

  round_and_cap_league_supply(total_float_supply)
end

#round_and_cap_league_supply(float_supply) ⇒ Object



50
51
52
53
54
55
# File 'lib/sorare/rewards/interactors/supply/compute_for_rarity.rb', line 50

def round_and_cap_league_supply(float_supply)
  [
    float_supply.floor + remaining_supply(float_supply.modulo(1)), # Supply limit
    league.cards_in_circulation_limit(rarity) # Circulation limit
  ].compact.min
end