Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez
Created September 3, 2014 07:14
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 jbgutierrez/48792a00c66eb35caa67 to your computer and use it in GitHub Desktop.
Save jbgutierrez/48792a00c66eb35caa67 to your computer and use it in GitHub Desktop.
Distribution of hours spent typing commands at my zsh shell each day
#!/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