Created
January 21, 2015 22:11
-
-
Save yaauie/91f6f7f03686b85c0b31 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 | |
# 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