Skip to content

Instantly share code, notes, and snippets.

@yaauie
Created January 21, 2015 22:11
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 yaauie/91f6f7f03686b85c0b31 to your computer and use it in GitHub Desktop.
Save yaauie/91f6f7f03686b85c0b31 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Given STDIN of unix timestamps (one or more per line),
# analyze the weekly distribution at hourly granularity.
day_counts_by_hour = []
$stdin.each_line do |line|
next if line.chomp.empty?
line.split(/\s/).each do |timestamp_string|
timestamp = Integer(timestamp_string.chomp)
time = Time.at(timestamp)
# hourly_stats[time.hour] += 1
# daily_stats[time.wday] += 1
day_counts_by_hour[time.hour] ||= Array.new(7, 0)
day_counts_by_hour[time.hour][time.wday] += 1
end
end
day_counts_by_hour.each_with_index do |day_counts, hour|
puts "#{hour}:\t" + day_counts.join("\t")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment