Created
September 3, 2014 07:14
-
-
Save jbgutierrez/48792a00c66eb35caa67 to your computer and use it in GitHub Desktop.
Distribution of hours spent typing commands at my zsh shell each day
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 | |
# coding: UTF-8 | |
require 'pathname' | |
require 'googlecharts' | |
file = Pathname.new 'zsh_history' | |
dates = {} | |
file.each_line do |line| | |
next unless line =~ /^: / | |
seconds = line[/\d+/].to_i | |
time = Time.at seconds | |
key = time | |
key -= 8 * 60 * 60 if time.hour < 8 | |
key = key.strftime "%F" | |
dates[key] = [time] unless dates[key] | |
dates[key][1] = time | |
end | |
counted = Hash.new(0) | |
dates.each do |time, pair| | |
from, to = *pair | |
hours = (to - from) / 3600 | |
hours = hours.round(0) | |
counted[hours] += 1 | |
puts "#{time} (#{from}-#{to}): #{hours}" | |
end | |
puts Gchart.pie(:data => counted.values, :title => 'zsh hours', :size => '400x200', :labels => counted.keys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment