Created
March 4, 2014 18:19
-
-
Save cantlin/9352387 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
#! /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