class Sorare::Rewards::Player
Player
stores the reward data of a player for a game week
Attributes
slug[R]
Public Class Methods
new(slug, reward_data)
click to toggle source
# File lib/sorare/rewards/player.rb, line 12 def initialize(slug, reward_data) @slug = slug @supply = Hash.new { |h, k| h[k] = {} } @config = reward_data.config @game_data = reward_data.playing_players[slug] load_supply(reward_data) end
Public Instance Methods
available_during_cooldown(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 57 def available_during_cooldown(league, rarity) [@config.cooldown_limit(rarity) - rewarded_during_cooldown(league, rarity), 0].max end
overall_supply(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 49 def overall_supply(league, rarity) @supply.dig(league.name, rarity, 'supply') || 0 end
pickable_supply(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 37 def pickable_supply(league, rarity) [ overall_supply(league, rarity), # Remaining supply available_during_cooldown(league, rarity), # Cooldown limit @config.distribution_limit(rarity) # Hard limit ].min end
playing?()
click to toggle source
# File lib/sorare/rewards/player.rb, line 24 def playing? @game_data.present? end
rank(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 45 def rank(league, rarity) @supply.dig(league.name, rarity, 'rank') end
reward_pool_supply_contribution(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 28 def reward_pool_supply_contribution(league, rarity) return 0 unless playing? && remaining_games_for_supply.positive? [ uncapped_supply_for_game_week(league, rarity), pickable_supply(league, rarity) ].min end
rewardable?(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 20 def rewardable?(league, rarity) !@config.cooldown?(rarity, @game_data.dig(league, rarity) || []) end
rewarded_during_cooldown(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 61 def rewarded_during_cooldown(league, rarity) (@game_data&.dig(league.name, rarity) || []).count do |at| (Time.parse(at) + @config.cooldown_since(rarity)) > Time.now end end
uncapped_supply_for_game_week(league, rarity)
click to toggle source
# File lib/sorare/rewards/player.rb, line 53 def uncapped_supply_for_game_week(league, rarity) overall_supply(league, rarity) / remaining_games_for_supply.to_f end
Private Instance Methods
load_supply(reward_data)
click to toggle source
# File lib/sorare/rewards/player.rb, line 75 def load_supply(reward_data) reward_data.each_league do |league| league.each_rarity_supply do |rarity, supply| next unless supply[slug] @supply[league.name][rarity] = supply[slug] end end end