apachecrunch 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/procedure_dsl.rb +58 -3
- metadata +2 -2
data/lib/procedure_dsl.rb
CHANGED
@@ -52,6 +52,22 @@ class ApacheCrunch
|
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
|
+
# DSL routine that calculates the sum of the quantities given by the block
|
56
|
+
#
|
57
|
+
# All values produced by the block must have a to_f method, and this routine
|
58
|
+
# returns a float.
|
59
|
+
class Sum < ProcedureRoutine
|
60
|
+
def execute(&blk)
|
61
|
+
rslt = 0.0
|
62
|
+
while @_current_entry = @_log_parser.next_entry
|
63
|
+
rslt += instance_eval(&blk).to_f
|
64
|
+
end
|
65
|
+
|
66
|
+
rslt
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
55
71
|
# DSL routine(s) that filter(s) for entries for which the given block evaluates to true
|
56
72
|
#
|
57
73
|
# This can be called as 'filter()', which means the filtering happens in a temporary file, or
|
@@ -191,14 +207,17 @@ class ApacheCrunch
|
|
191
207
|
# time_to_serve
|
192
208
|
# end
|
193
209
|
#
|
194
|
-
# would return two numbers, the lower and upper bound of a 95% confidence interval for the
|
195
|
-
# of time_to_serve.
|
210
|
+
# would return two numbers, the lower and upper bound of a 95% confidence interval for the
|
211
|
+
# values of time_to_serve.
|
212
|
+
#
|
213
|
+
# This routine returns a float, and the block must always evaluate to something with a to_f
|
214
|
+
# method.
|
196
215
|
class ConfidenceInterval < ProcedureRoutine
|
197
216
|
def execute(confidence, &blk)
|
198
217
|
# Build a list of all the values found
|
199
218
|
values = []
|
200
219
|
while @_current_entry = @_log_parser.next_entry
|
201
|
-
values << instance_eval(&blk)
|
220
|
+
values << instance_eval(&blk).to_f
|
202
221
|
end
|
203
222
|
values.sort!
|
204
223
|
|
@@ -211,6 +230,26 @@ class ApacheCrunch
|
|
211
230
|
end
|
212
231
|
|
213
232
|
|
233
|
+
# DSL routine that determines the nth percentile for the values to which the block evaluates
|
234
|
+
#
|
235
|
+
# This routine returns a float, and the block must always evaluate to something with a to_f
|
236
|
+
# method.
|
237
|
+
class Percentile < ProcedureRoutine
|
238
|
+
def execute(n, &blk)
|
239
|
+
# Build a list of all the values found
|
240
|
+
values = []
|
241
|
+
while @_current_entry = @_log_parser.next_entry
|
242
|
+
values << instance_eval(&blk).to_f
|
243
|
+
end
|
244
|
+
values.sort!
|
245
|
+
|
246
|
+
puts "values.length: #{values.length}"
|
247
|
+
puts "n/100.0*values.length: #{n/100.0*values.length}"
|
248
|
+
return values[((n/100.0)*values.length).to_i]
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
|
214
253
|
# DSL routine that finds the most common n values for the given block.
|
215
254
|
#
|
216
255
|
# Returns a list of lists, each of which is [value, count]. This list is sorted by count.
|
@@ -275,6 +314,14 @@ class ApacheCrunch
|
|
275
314
|
nil
|
276
315
|
end
|
277
316
|
|
317
|
+
# DSL routine 'sum'
|
318
|
+
def sum(&blk)
|
319
|
+
routine = Sum.new(@_log_parser)
|
320
|
+
rv = routine.execute(&blk)
|
321
|
+
routine.finish
|
322
|
+
rv
|
323
|
+
end
|
324
|
+
|
278
325
|
# DSL routine 'count_by'
|
279
326
|
def count_by(&blk)
|
280
327
|
routine = CountBy.new(@_log_parser)
|
@@ -307,6 +354,14 @@ class ApacheCrunch
|
|
307
354
|
rv
|
308
355
|
end
|
309
356
|
|
357
|
+
# DSL routine 'percentile'
|
358
|
+
def percentile(n, &blk)
|
359
|
+
routine = Percentile.new(@_log_parser)
|
360
|
+
rv = routine.execute(n, &blk)
|
361
|
+
routine.finish
|
362
|
+
rv
|
363
|
+
end
|
364
|
+
|
310
365
|
# DSL routine 'most_common'
|
311
366
|
def most_common(n, &blk)
|
312
367
|
routine = MostCommon.new(@_log_parser)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apachecrunch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.6"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Slimmon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|