diff options
author | Patrick Simianer <p@simianer.de> | 2011-12-03 21:38:59 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2011-12-03 21:38:59 +0100 |
commit | 0f9024d49f7622d1c135aa2e3f9ddc6bc4349fb9 (patch) | |
tree | fc087cb9a222d00fc8b2f6d4484a62c581b84e54 /dtrain/hstreaming/rule_count/red.rb | |
parent | 68fd129f5f69162fc2385bd3e57335968dfc74c2 (diff) |
new rule count
Diffstat (limited to 'dtrain/hstreaming/rule_count/red.rb')
-rw-r--r-- | dtrain/hstreaming/rule_count/red.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/dtrain/hstreaming/rule_count/red.rb b/dtrain/hstreaming/rule_count/red.rb new file mode 100644 index 00000000..8f9109cc --- /dev/null +++ b/dtrain/hstreaming/rule_count/red.rb @@ -0,0 +1,22 @@ +STDIN.set_encoding 'utf-8' +STDOUT.set_encoding 'utf-8' + +def output(key, val) + puts "#{key}\t#{val}" +end + +prev_key = nil +sum = 0 +while line = STDIN.gets + key, val = line.strip.split /\t/ + if key != prev_key && sum > 0 + output prev_key, sum + prev_key = key + sum = 0 + elsif !prev_key + prev_key = key + end + sum += val.to_i +end +output prev_key, sum + |