Skip to content

Commit

Permalink
! random sanpling default value
Browse files Browse the repository at this point in the history
  • Loading branch information
niko committed Sep 12, 2011
1 parent 67b092e commit 03b8699
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/jsongrepper.rb
Expand Up @@ -71,7 +71,9 @@ def sums
def reset_sums! def reset_sums!
@sums = {} @sums = {}
end end
def summarize(random_sampling=1) def summarize(random_sampling=nil)
random_sampling ||= 1

sums.each do |field, occurences| sums.each do |field, occurences|
total = 0 total = 0
puts "\nSummary for #{field}:" puts "\nSummary for #{field}:"
Expand Down
6 changes: 6 additions & 0 deletions qed/jsongrep.rdoc
Expand Up @@ -145,4 +145,10 @@ Is meant to speed up the processing of large data sets.
}.equals '' }.equals ''




Random sampling also works with an explicit nil.

g = JsonGrepper.new('{"a":3, "b":5}').random_sampling(nil).grep(nil).condition('self.c = a + b ; c > 6').print('c').summarize(['a','c'])
output_of { JsonGrepper.summarize(nil) }


JsonGrepper.summarize then also takes a random sampling argument and multiplies the respective occurrences with the sample rate. JsonGrepper.summarize then also takes a random sampling argument and multiplies the respective occurrences with the sample rate.

0 comments on commit 03b8699

Please sign in to comment.