Created
March 2, 2012 15:02
-
-
Save jesperhj/1958988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'json' | |
require 'pp' | |
############################################################ | |
# mapper code | |
############################################################ | |
def put_line line, action | |
l = JSON.parse line | |
puts "#{l['uid']}\t#{action}:#{l['ip']}" if !l['uid'].nil? | |
end | |
STDIN.each do |line| | |
if line.match /u_c/ | |
put_line line, 'e' | |
elsif line.match /a":"PAGE_LOAD/ | |
put_line line, 'a' | |
end | |
end | |
############################################################ | |
# mapper code | |
############################################################ | |
def print_res uid, logged_in_ips | |
puts "#{logged_in_ips}\t#{uid}" if uid != 0 | |
end | |
current_uid = 0 | |
logged_in_ips = 0 | |
ips = Array.new | |
STDIN.each do |line| | |
res = line.match /^(\d+)\t([a,e]):(.*)$/ | |
u_id = res[1] | |
action = res[2] | |
ip = res[3] | |
if u_id != current_uid | |
print_res current_uid, logged_in_ips | |
current_uid = u_id | |
ips = Array.new | |
logged_in_ips = 0 | |
end | |
if action == 'a' && !ips.include?(ip) | |
ips << ip | |
elsif action == 'e' && ips.include?(ip) | |
logged_in_ips += 1 | |
end | |
end | |
print_res current_uid, logged_in_ips |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment