Class: Qfill::Strategy::Sample

Inherits:
Base
  • Object
show all
Defined in:
lib/qfill/strategy/sample.rb

Direct Known Subclasses

TimeSlice

Constant Summary collapse

NAME =
:sample

Instance Attribute Summary

Attributes inherited from Base

#added, #ratio_modifier, #tally

Instance Method Summary collapse

Methods inherited from Base

#bump!, #default_pusher, #fill_to_ratio!, #initialize, #name, #remaining

Constructor Details

This class inherits a constructor from Qfill::Strategy::Base

Instance Method Details

#fill_according_to_list_ratios!Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/qfill/strategy/sample.rb', line 28

def fill_according_to_list_ratios!
  # puts "#{!is_full?} && #{result.fill_count} >= #{result.max} && #{!self.popper.totally_empty?} && #{(list_ratio_tuple = result.current_list_ratio)}"
  while !is_full? && !result.is_full? && !popper.totally_empty? && (list_ratio_tuple = result.current_list_ratio)
    max_from_list = Qfill::Result.get_limit_from_max_and_ratio(result.max, list_ratio_tuple[1], remaining)
    array_to_push = popper.next_objects!(list_ratio_tuple[0], max_from_list)
    self.added = result.push(array_to_push, list_ratio_tuple[0])
    bump!
    puts "[fill_according_to_list_ratios!]#{self}[#{list_ratio_tuple[0]}][added:#{added}]" if Qfill::VERBOSE
    result.set_next_as_current!
    break if is_full?
  end
end

#fill_up_to_ratio!Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/qfill/strategy/sample.rb', line 16

def fill_up_to_ratio!
  ratio = 1.0 / popper.primary.length # 1 divided by the number of queues
  max_from_list = Qfill::Result.get_limit_from_max_and_ratio(result.max, ratio, remaining)
  while !is_full? && !result.is_full? && !popper.totally_empty? && (origin_list = popper.current_list)
    array_to_push = popper.next_objects!(origin_list.name, [max_from_list, remaining].min)
    self.added = result.push(array_to_push, origin_list.name)
    bump!
    puts "[fill_up_to_ratio!]#{self}[Added:#{added}][Max List:#{max_from_list}][ratio:#{ratio}][added:#{added}]" if Qfill::VERBOSE
    popper.set_next_as_current!
  end
end

#on_fill!Object



8
9
10
# File 'lib/qfill/strategy/sample.rb', line 8

def on_fill!
  # NOOP
end

#result_max!Object



12
13
14
# File 'lib/qfill/strategy/sample.rb', line 12

def result_max!
  result.max = Qfill::Result.get_limit_from_max_and_ratio(primary_list_total, result.ratio, remaining)
end