Skip to content

Instantly share code, notes, and snippets.

@cantlin
Created March 4, 2014 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cantlin/9352387 to your computer and use it in GitHub Desktop.
Save cantlin/9352387 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require "json"
infile = "antarctica_hits"
lines = File.readlines infile
parsed_lines = lines.map do |line|
line = line.gsub(/2014-02-28T12-ip-10.*\.internal:/, "")
JSON.parse(line) rescue next
end.compact
puts "", "found #{lines.length} hit events"
puts " WEB_INITIAL: #{parsed_lines.select {|h| h['eventType'] === "WEB_INITIAL"}.length}"
puts " WEB_ADDITIONAL: #{parsed_lines.select {|h| h['eventType'] === "WEB_ADDITIONAL"}.length}", ""
hits = {}
parsed_lines.each do |hit|
hits[hit['viewId']] ||= []
if hit['eventType'] == "WEB_ADDITIONAL"
begin
hits[hit['viewId']] << hit['client']['page']['depth']
rescue StandardError
end
end
end
hits.reject! {|k, v| v.empty?}
puts "averaging across #{hits.length} views (avg #{(hits.map {|k, d| d.length}.reduce(&:+) / hits.length.to_f).round(2)} events per view)"
depths = hits.map {|k, depths| depths.max}.flatten
total = depths.reduce(&:+)
mean = total.to_f / hits.length
puts "mean: #{mean.round(3)}%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment