Module: RequestLogAnalyzer::Tracker::StatisticsTracking
Instance Method Summary collapse
-
#hits(cat) ⇒ Object
Get the number of hits of a specific category.
-
#hits_overall ⇒ Object
Get the total hits of a all categories.
-
#max(cat) ⇒ Object
Get the maximum duration of a specific category.
-
#mean(cat) ⇒ Object
Get the average duration of a specific category.
-
#mean_overall ⇒ Object
Get the average duration of a all categories.
-
#min(cat) ⇒ Object
Get the minimal duration of a specific category.
-
#sorted_by(by = nil) ⇒ Object
Return categories sorted by a given key.
-
#statistics_header(options) ⇒ Object
Returns the column header for a statistics table to report on the statistics result.
-
#statistics_row(cat) ⇒ Object
Returns a row of statistics information for a report table, given a category.
-
#stddev(cat) ⇒ Object
Get the standard deviation of the duration of a specific category.
-
#sum(cat) ⇒ Object
Get the total duration of a specific category.
-
#sum_overall ⇒ Object
Get the cumlative duration of a all categories.
-
#update_statistics(category, number) ⇒ Object
Update sthe running calculation of statistics with the newly found numeric value.
-
#variance(cat) ⇒ Object
Get the variance of the duration of a specific category.
Instance Method Details
#hits(cat) ⇒ Object
Get the number of hits of a specific category. cat
The category
121 122 123 |
# File 'lib/request_log_analyzer/tracker.rb', line 121 def hits(cat) @categories[cat][:hits] end |
#hits_overall ⇒ Object
Get the total hits of a all categories.
173 174 175 |
# File 'lib/request_log_analyzer/tracker.rb', line 173 def hits_overall @categories.inject(0) { |sum, (name, cat)| sum + cat[:hits] } end |
#max(cat) ⇒ Object
Get the maximum duration of a specific category. cat
The category
139 140 141 |
# File 'lib/request_log_analyzer/tracker.rb', line 139 def max(cat) @categories[cat][:max] end |
#mean(cat) ⇒ Object
Get the average duration of a specific category. cat
The category
145 146 147 |
# File 'lib/request_log_analyzer/tracker.rb', line 145 def mean(cat) @categories[cat][:mean] end |
#mean_overall ⇒ Object
Get the average duration of a all categories.
163 164 165 |
# File 'lib/request_log_analyzer/tracker.rb', line 163 def mean_overall sum_overall / hits_overall end |
#min(cat) ⇒ Object
Get the minimal duration of a specific category. cat
The category
133 134 135 |
# File 'lib/request_log_analyzer/tracker.rb', line 133 def min(cat) @categories[cat][:min] end |
#sorted_by(by = nil) ⇒ Object
Return categories sorted by a given key. by
The key to sort on. This parameter can be omitted if a sorting block is provided instead
179 180 181 182 183 184 185 |
# File 'lib/request_log_analyzer/tracker.rb', line 179 def sorted_by(by = nil) if block_given? categories.sort { |a, b| yield(b[1]) <=> yield(a[1]) } else categories.sort { |a, b| send(by, b[0]) <=> send(by, a[0]) } end end |
#statistics_header(options) ⇒ Object
Returns the column header for a statistics table to report on the statistics result
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/request_log_analyzer/tracker.rb', line 188 def statistics_header() [ {:title => [:title], :width => :rest}, {:title => 'Hits', :align => :right, :highlight => ([:highlight] == :hits), :min_width => 4}, {:title => 'Sum', :align => :right, :highlight => ([:highlight] == :sum), :min_width => 6}, {:title => 'Mean', :align => :right, :highlight => ([:highlight] == :mean), :min_width => 6}, {:title => 'StdDev', :align => :right, :highlight => ([:highlight] == :stddev), :min_width => 6}, {:title => 'Min', :align => :right, :highlight => ([:highlight] == :min), :min_width => 6}, {:title => 'Max', :align => :right, :highlight => ([:highlight] == :max), :min_width => 6} ] end |
#statistics_row(cat) ⇒ Object
Returns a row of statistics information for a report table, given a category
201 202 203 204 |
# File 'lib/request_log_analyzer/tracker.rb', line 201 def statistics_row(cat) [cat, hits(cat), display_value(sum(cat)), display_value(mean(cat)), display_value(stddev(cat)), display_value(min(cat)), display_value(max(cat))] end |
#stddev(cat) ⇒ Object
Get the standard deviation of the duration of a specific category. cat
The category
151 152 153 |
# File 'lib/request_log_analyzer/tracker.rb', line 151 def stddev(cat) Math.sqrt(variance(cat)) end |
#sum(cat) ⇒ Object
Get the total duration of a specific category. cat
The category
127 128 129 |
# File 'lib/request_log_analyzer/tracker.rb', line 127 def sum(cat) @categories[cat][:sum] end |
#sum_overall ⇒ Object
Get the cumlative duration of a all categories.
168 169 170 |
# File 'lib/request_log_analyzer/tracker.rb', line 168 def sum_overall @categories.inject(0.0) { |sum, (name, cat)| sum + cat[:sum] } end |
#update_statistics(category, number) ⇒ Object
Update sthe running calculation of statistics with the newly found numeric value.
category
-
The category for which to update the running statistics calculations
number
-
The numeric value to update the calculations with.
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/request_log_analyzer/tracker.rb', line 107 def update_statistics(category, number) @categories[category] ||= {:hits => 0, :sum => 0, :mean => 0.0, :sum_of_squares => 0.0, :min => number, :max => number } delta = number - @categories[category][:mean] @categories[category][:hits] += 1 @categories[category][:mean] += (delta / @categories[category][:hits]) @categories[category][:sum_of_squares] += delta * (number - @categories[category][:mean]) @categories[category][:sum] += number @categories[category][:min] = number if number < @categories[category][:min] @categories[category][:max] = number if number > @categories[category][:max] end |
#variance(cat) ⇒ Object
Get the variance of the duration of a specific category. cat
The category
157 158 159 160 |
# File 'lib/request_log_analyzer/tracker.rb', line 157 def variance(cat) return 0.0 if @categories[cat][:hits] <= 1 (@categories[cat][:sum_of_squares] / (@categories[cat][:hits] - 1)) end |