Class: PayoutSystem::MinimumToFraction

Inherits:
Base
  • Object
show all
Defined in:
lib/payout_system/minimum_to_fraction.rb

Instance Attribute Summary

Attributes inherited from Base

#entries, #logger, #options, #order, #pot

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PayoutSystem::Base

Instance Method Details

#fraction_to_awardObject

Terminology:

  • top: entries that would have been awarded with the original

    method, usually top 3 if there are no split-places
    
  • awardable: the top 25% or other configured percentage

  • remaining: awardable minus top



10
11
12
# File 'lib/payout_system/minimum_to_fraction.rb', line 10

def fraction_to_award
  0.25
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/payout_system/minimum_to_fraction.rb', line 14

def run
  # Distribute evenly among all awardable entries: the amount of
  # stake or less, if there's not enough
  logger.debug "Pot: #{pot.inspect}  Top: #{top_count}  Awardable: #{awardable_count}"
  if awardable_count > top_count
    logger.debug "Using modified algorythm"
    total_evenly_distributed_amount = [pot, awardable_count * stake].min
    single_evenly_distributed_amount = total_evenly_distributed_amount / awardable_count

    logger.debug "Evenly distributed:  Total: #{total_evenly_distributed_amount}  Per entry: #{single_evenly_distributed_amount}"
    awards = [single_evenly_distributed_amount] * awardable_count

    logger.debug "Awards after even distribution: #{awards.inspect}"

    # The amount available for the top entries (the remaining after
    # even distribution + the amount they got through even
    # distribution)
    amount_for_top = pot - total_evenly_distributed_amount + ([top_count, awardable_count].min * single_evenly_distributed_amount)
    logger.debug "Amount to be distributed among top: #{amount_for_top} calculated as #{pot} - #{total_evenly_distributed_amount} + (#{[top_count, awardable_count].min} * #{single_evenly_distributed_amount})"

    # Preliminary awards for the top
    top_awards = top_ratios.map{|r| r * amount_for_top}
    logger.debug "Top awards: #{top_awards.inspect}  Ratios: #{top_ratios.inspect}"

    # Make sure the top don't get less than the remaining awarded people
    logger.debug "Top awards before ensuring minumum: #{top_awards.inspect}, minimum: #{single_evenly_distributed_amount}"
    ensure_minimum(top_awards, :minimum => single_evenly_distributed_amount)
    logger.debug "Top awards after ensuring minumum: #{top_awards.inspect}"

    top_awards.each_with_index{|a,i| awards[i] = a}
  else
    logger.debug "Using traditional algorythm"
    logger.debug "Top ratios: #{top_ratios.inspect}  Sum: #{top_ratios.sum}"
    awards = top_ratios.map{|r| r * pot}
  end

  make_them_integers(awards)

  awards.to_enum.with_index.map {|a,i| [sorted_entries[i], a] }
end