Class: Pwrake::Stat
- Inherits:
-
Object
- Object
- Pwrake::Stat
- Defined in:
- lib/pwrake/report/stat.rb
Instance Attribute Summary collapse
-
#bin ⇒ Object
readonly
Returns the value of attribute bin.
-
#hist ⇒ Object
readonly
Returns the value of attribute hist.
-
#hist_max ⇒ Object
readonly
Returns the value of attribute hist_max.
-
#hist_min ⇒ Object
readonly
Returns the value of attribute hist_min.
-
#kurt ⇒ Object
readonly
Returns the value of attribute kurt.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#mean_absolute_deviation ⇒ Object
readonly
Returns the value of attribute mean_absolute_deviation.
-
#median ⇒ Object
readonly
Returns the value of attribute median.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#sdev ⇒ Object
readonly
Returns the value of attribute sdev.
-
#skew ⇒ Object
readonly
Returns the value of attribute skew.
-
#sum ⇒ Object
readonly
Returns the value of attribute sum.
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Class Method Summary collapse
Instance Method Summary collapse
- #calc_median ⇒ Object
- #fmt(x) ⇒ Object
- #hist_each ⇒ Object
- #html_td ⇒ Object
-
#initialize(data) ⇒ Stat
constructor
A new instance of Stat.
- #make_logx_histogram(bin) ⇒ Object
Constructor Details
#initialize(data) ⇒ Stat
Returns a new instance of Stat.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pwrake/report/stat.rb', line 5 def initialize(data) @data = data @n = data.size if @n>0 @min = data.min @max = data.max @sum = data.inject(0){|s,x| s+x} @mean = @sum/@n @median = calc_median @mean_absolute_deviation = data.inject(0){|s,x| (x-@mean).abs} / @n if false and @n>1 @variance = data.inject(0){|s,x| y=x-@mean; y**2} / (@n-1) @sdev = Math.sqrt(@variance) @skew = data.inject(0){|s,x| y=(x-@mean)/@sdev; y**3} / @n @kurt = data.inject(0){|s,x| y=(x-@mean)/@sdev; y**4} / @n - 3 end end end |
Instance Attribute Details
#bin ⇒ Object (readonly)
Returns the value of attribute bin.
28 29 30 |
# File 'lib/pwrake/report/stat.rb', line 28 def bin @bin end |
#hist ⇒ Object (readonly)
Returns the value of attribute hist.
28 29 30 |
# File 'lib/pwrake/report/stat.rb', line 28 def hist @hist end |
#hist_max ⇒ Object (readonly)
Returns the value of attribute hist_max.
28 29 30 |
# File 'lib/pwrake/report/stat.rb', line 28 def hist_max @hist_max end |
#hist_min ⇒ Object (readonly)
Returns the value of attribute hist_min.
28 29 30 |
# File 'lib/pwrake/report/stat.rb', line 28 def hist_min @hist_min end |
#kurt ⇒ Object (readonly)
Returns the value of attribute kurt.
27 28 29 |
# File 'lib/pwrake/report/stat.rb', line 27 def kurt @kurt end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
25 26 27 |
# File 'lib/pwrake/report/stat.rb', line 25 def max @max end |
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
25 26 27 |
# File 'lib/pwrake/report/stat.rb', line 25 def mean @mean end |
#mean_absolute_deviation ⇒ Object (readonly)
Returns the value of attribute mean_absolute_deviation.
26 27 28 |
# File 'lib/pwrake/report/stat.rb', line 26 def mean_absolute_deviation @mean_absolute_deviation end |
#median ⇒ Object (readonly)
Returns the value of attribute median.
25 26 27 |
# File 'lib/pwrake/report/stat.rb', line 25 def median @median end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
25 26 27 |
# File 'lib/pwrake/report/stat.rb', line 25 def min @min end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
24 25 26 |
# File 'lib/pwrake/report/stat.rb', line 24 def n @n end |
#sdev ⇒ Object (readonly)
Returns the value of attribute sdev.
27 28 29 |
# File 'lib/pwrake/report/stat.rb', line 27 def sdev @sdev end |
#skew ⇒ Object (readonly)
Returns the value of attribute skew.
27 28 29 |
# File 'lib/pwrake/report/stat.rb', line 27 def skew @skew end |
#sum ⇒ Object (readonly)
Returns the value of attribute sum.
25 26 27 |
# File 'lib/pwrake/report/stat.rb', line 25 def sum @sum end |
#variance ⇒ Object (readonly)
Returns the value of attribute variance.
27 28 29 |
# File 'lib/pwrake/report/stat.rb', line 27 def variance @variance end |
Class Method Details
.html_th ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/pwrake/report/stat.rb', line 97 def self.html_th a = %w[command count sum mean median min max] "<tr>" + "<th></th>"*2 + "<th colspan=#{a.size-2}>time (seconds)</th>" + "</tr>\n<tr>" + "<th>%s</th>" * a.size % a + "</tr>\n" end |
Instance Method Details
#calc_median ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pwrake/report/stat.rb', line 58 def calc_median if @n==1 @data[0] elsif @n==2 @mean else case @n%2 when 1 i = (@n-1)/2 @data.sort[i] else i = @n/2 s = @data.sort (s[i]+s[i+1])/2 end end end |
#fmt(x) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pwrake/report/stat.rb', line 76 def fmt(x) case x when Numeric a = x.abs if a == 0 "0" elsif a < 1 "%.3g" % x else "%.3f" % x end else x.to_s end end |
#hist_each ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pwrake/report/stat.rb', line 46 def hist_each if @hist n = @hist.size n.times do |i| x1 = 10**(@bin*(i+@i_min)) x2 = 10**(@bin*(i+1+@i_min)) y = @hist[i] yield x1,x2,y end end end |
#html_td ⇒ Object
92 93 94 95 |
# File 'lib/pwrake/report/stat.rb', line 92 def html_td '<td align="right">%i</td><td align="right">%s</td><td align="right">%s</td><td align="right">%s</td><td align="right">%s</td><td align="right">%s</td>' % [@n, fmt(@sum), fmt(@mean), fmt(@median), fmt(@min), fmt(@max)] end |
#make_logx_histogram(bin) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pwrake/report/stat.rb', line 30 def make_logx_histogram(bin) if @min>0 @bin = bin # 1.0/10 @i_max = (Math.log10(@max)/@bin).floor @i_min = (Math.log10(@min)/@bin).floor @hist_min = 10**(@i_min * @bin) @hist_max = 10**((@i_max+1) * @bin) @hist = Array.new(@i_max-@i_min+1,0) @data.each do |x| i = (Math.log10(x)/@bin-@i_min).floor raise "invalid index i=#{i}" if i<0 || i>@i_max-@i_min @hist[i] += 1 end end end |