Class: TcpsnitchAnalyzer::DescriptiveStat

Inherits:
Object
  • Object
show all
Defined in:
lib/tcpsnitch_analyzer/descriptive_stat.rb

Constant Summary collapse

@@data =
[]

Class Method Summary collapse

Class Method Details

.add_val(val) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tcpsnitch_analyzer/descriptive_stat.rb', line 8

def self.add_val(val)
  if val.is_a? Integer
    @@data.push(val)
  else
    if val.is_a? Hash
      TcpsnitchAnalyzer.error("invalid value for descriptive statistic: "\
                              "non-terminal node")
    else
      TcpsnitchAnalyzer.error("invalid value for descriptive statistic: '#{val}'")
    end
  end
end


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
# File 'lib/tcpsnitch_analyzer/descriptive_stat.rb', line 21

def self.print(options)
  puts "Descriptive statistics:"
  @@data.descriptive_statistics.each do |key, value|
    puts "#{key}".ljust(20) + "#{value}" 
  end
  
  # Only plot CDF is we have a range
  return unless @@data.range > 0 

  x = @@data.sort
  n = x.size
  y = x.map do |el|
    ((x.rindex { |v| v <= el } || -1.0) + 1.0) / n * 100.0
  end

  Gnuplot.open do |gp|
    Gnuplot::Plot.new(gp) do |plot|
      plot.xrange "[#{@@data.min}:#{@@data.max}]; set logscale x"
      plot.title  "CDF for #{options.node_path} (#{options.event_filter} events)"
      plot.xlabel "Value"
      plot.ylabel "Normal CDF"
      plot.data << Gnuplot::DataSet.new([x,y]) do |ds|
        ds.with = "lines"
        ds.linewidth = 4
        ds.title = options.node_path.split('.').last
      end
    end
  end # Gnuplot.open
end