Class: Roby::EventLogging::IOEventLogger::TimepointGroupStats

Inherits:
Struct
  • Object
show all
Defined in:
lib/roby/event_logging/io_event_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fifoObject

Returns the value of attribute fifo

Returns:

  • (Object)

    the current value of fifo



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def fifo
  @fifo
end

#last_durationObject

Returns the value of attribute last_duration

Returns:

  • (Object)

    the current value of last_duration



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def last_duration
  @last_duration
end

#max_durationObject

Returns the value of attribute max_duration

Returns:

  • (Object)

    the current value of max_duration



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def max_duration
  @max_duration
end

#meanObject

Returns the value of attribute mean

Returns:

  • (Object)

    the current value of mean



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def mean
  @mean
end

#min_durationObject

Returns the value of attribute min_duration

Returns:

  • (Object)

    the current value of min_duration



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def min_duration
  @min_duration
end

#refObject

Returns the value of attribute ref

Returns:

  • (Object)

    the current value of ref



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def ref
  @ref
end

#sample_countObject

Returns the value of attribute sample_count

Returns:

  • (Object)

    the current value of sample_count



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def sample_count
  @sample_count
end

#sum_squaresObject

Returns the value of attribute sum_squares

Returns:

  • (Object)

    the current value of sum_squares



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def sum_squares
  @sum_squares
end

#totalObject

Returns the value of attribute total

Returns:

  • (Object)

    the current value of total



59
60
61
# File 'lib/roby/event_logging/io_event_logger.rb', line 59

def total
  @total
end

Instance Method Details

#mean_delta(old_mean, duration, new_count) ⇒ Object



88
89
90
# File 'lib/roby/event_logging/io_event_logger.rb', line 88

def mean_delta(old_mean, duration, new_count)
    (duration - old_mean) / new_count
end

#sum_squares_delta(duration, old_mean, new_mean) ⇒ Object



92
93
94
# File 'lib/roby/event_logging/io_event_logger.rb', line 92

def sum_squares_delta(duration, old_mean, new_mean)
    (duration - new_mean) * (duration - old_mean)
end

#to_sObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/roby/event_logging/io_event_logger.rb', line 96

def to_s
    ratio = total / (Time.now - ref)
    sd = Math.sqrt(variance)
    format(
        "max=%<max>.3f min=%<min>.3f total=%<ratio>i%% " \
        "mean=%<mean>.3f sd=%<sd>.3f",
        max: max_duration, min: min_duration, ratio: (ratio * 100).round,
        mean: mean, sd: sd
    )
end

#update(duration) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/roby/event_logging/io_event_logger.rb', line 64

def update(duration)
    self.total += duration
    update_min_max(duration)
    update_statistics(duration, sample_count + 1)
    self.sample_count = sample_count + 1
    self.last_duration = duration
end

#update_min_max(duration) ⇒ Object



76
77
78
79
# File 'lib/roby/event_logging/io_event_logger.rb', line 76

def update_min_max(duration)
    self.min_duration = duration if min_duration > duration
    self.max_duration = duration if max_duration < duration
end

#update_statistics(duration, new_count) ⇒ Object



81
82
83
84
85
86
# File 'lib/roby/event_logging/io_event_logger.rb', line 81

def update_statistics(duration, new_count)
    old_mean = mean
    new_mean = old_mean + mean_delta(old_mean, duration, new_count)
    self.sum_squares += sum_squares_delta(duration, old_mean, new_mean)
    self.mean = new_mean
end

#varianceObject



72
73
74
# File 'lib/roby/event_logging/io_event_logger.rb', line 72

def variance
    sum_squares / sample_count
end