Class: Pwrake::RankStat
- Inherits:
-
Object
- Object
- Pwrake::RankStat
- Defined in:
- lib/pwrake/task/task_rank.rb
Instance Method Summary collapse
- #add_sample(rank, elap) ⇒ Object
-
#initialize ⇒ RankStat
constructor
A new instance of RankStat.
- #rank_weight ⇒ Object
Constructor Details
#initialize ⇒ RankStat
Returns a new instance of RankStat.
5 6 7 8 |
# File 'lib/pwrake/task/task_rank.rb', line 5 def initialize @lock = Mutex.new @stat = [] end |
Instance Method Details
#add_sample(rank, elap) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pwrake/task/task_rank.rb', line 10 def add_sample(rank,elap) @lock.synchronize do stat = @stat[rank] if stat.nil? @stat[rank] = stat = [0,0.0] end stat[0] += 1 stat[1] += elap #Log.debug "add_sample rank=#{rank} stat=#{stat.inspect} weight=#{stat[0]/stat[1]}" end end |
#rank_weight ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pwrake/task/task_rank.rb', line 22 def rank_weight @lock.synchronize do sum = 0.0 count = 0 weight = @stat.map do |stat| if stat w = stat[0]/stat[1] sum += w count += 1 w else nil end end if count == 0 avg = 1.0 else avg = sum/count end [weight, avg] end end |