Skip to content

Instantly share code, notes, and snippets.

@noahhl
Created September 29, 2011 14:24
Show Gist options
  • Select an option

  • Save noahhl/1250828 to your computer and use it in GitHub Desktop.

Select an option

Save noahhl/1250828 to your computer and use it in GitHub Desktop.
# Run from the directory containing your git repository
require 'time'
Dir.glob("./*").each do |dir|
`cd #{dir} && git log --pretty=format:'%an: %at' >> ~/commit_times.txt`
end
file = File.new(File.expand_path("~/commit_times.txt"), "r")
commits = []
while(line=file.gets)
commits << line
end
file.close
commits.collect!{|c| {:author => c.split(": ")[0], :timestamp => Time.at(c.split(": ")[1].split("\n")[0].to_i) }}
authors = commits.collect{|c| c[:author]}.uniq
authors.each do |author|
total = commits.select{|c| c[:author].split(" ")[0].downcase == author}.size
if total > 50
puts "#{author} (#{total} total commits)"
puts "Times in UTC"
Range.new(0,23).each do |hour|
count = commits.select{|c| c[:author].split(" ")[0].downcase == author && c[:timestamp].utc.hour == hour}.size
puts "#{hour.to_s.rjust(2, "0")}: #{"*"*(count.to_f/total * 100).round}"
end
end
end
authors.each do |author|
total = commits.select{|c| c[:author] == author}.size
if total > 50
counts = []
Range.new(0,23).each do |hour|
counts << commits.select{|c| c[:author] == author && c[:timestamp].utc.hour == hour}.size
end
puts "#{author}, #{counts.join(",")}"
end
end
commits = []
Dir.glob("./*").each do |dir|
commits << `cd #{dir} && git log --oneline --shortstat --pretty="%an" | awk 'BEGIN {print ""} {printf("\%s",NR\%3 ? \$0"\t" : \$0"\\n")}'`.split("\n")
end
commits.flatten!
class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end
changes = commits.collect{|c| {:committer => c.split("\t\t")[0], :changes => c.split("\t\t")[1].split(",")[1,2].collect{|b| b.lstrip.split(" ")[0].to_i}.sum} rescue nil}
changes.compact!
authors = changes.collect{|c| c[:committer]}.uniq
authors.each do |author|
changeset = changes.find_all{|c| c[:committer] == author}
puts "#{author}: #{changeset.collect{|c| c[:changes]}.sum / changeset.count}"
end
library(reshape)
library(ggplot2)
commits <- read.csv("~/commits_by_person.csv", stringsAsFactors = F, header=F)
names(commits) <- c("committer", 0:23)
commits$total <- 0
for(i in 1:nrow(commits)) {
commits$total[i] <- sum(commits[i,2:25])
}
commits$max <- 0
for(i in 1:nrow(commits)) {
commits$max[i] <- which(commits[i, 2:25]==max(commits[i,2:25]))[1]
}
commits$tz <- 0
for(i in 1:nrow(commits)) {
commits$tz[i] <- as.numeric(readline(paste("\n", commits$committer[i])))
}
commits$max <- commits$max + commits$tz
commits$order <- order(commits$max)
commits <- melt(commits, id=c("committer", "total", "tz", "max", "order"))
names(commits) <- c("committer", "total", "tz", "max", "order", "hour", "count")
commits$count <- as.numeric(commits$count)
commits$portion <- commits$count / commits$total
commits$hour <- as.numeric(commits$hour)
commits$localtime <- commits$hour + commits$tz
commits$offsethour <- commits$localtime
commits$offsethour[commits$localtime < 5] <- 24+commits$localtime[commits$localtime < 5]
for(i in 1:nrow(commits)) {
commits$nick[i] <- strsplit(commits$committer[i], ' ')[[1]][1]
}
commits$nick[commits$committer=="Jason Fried"] <- "JF"
commits$nick[commits$committer=="Jason Zimdars"] <- "JZ"
ggplot(commits, aes(offsethour, weight=portion)) + geom_histogram(binwidth=1, fill='steelblue', colour='grey90') + facet_grid(nick ~ ., scales='free') + xlab("Hour (UTC)") + ylab("Portion of commits") + opts(title="Circadian rhythms of 37signals", axis.text.y=theme_blank(), axis.ticks=theme_blank()) + xlim(5,28)
order <- c("Noah", "Taylor", "Jamie", "Craig", "Trevor", "JZ", "John", "JF", "Jeremy", "Javan", "Jamis", "Scott", "Will", "Jeffrey", "David", "Ryan", "Sam", "Pratik")
for(name in unique(commits$nick)) {
commits$order[commits$nick == name] <- which(name == order)
}
lbl.fn <- function(variable, value) {
order[value]
}
ggplot(commits, aes(offsethour, weight=portion)) + geom_histogram(binwidth=1, fill='steelblue', colour='grey90') + facet_grid(order ~ ., scales='free', labeller = 'lbl.fn') + xlab("Hour (local time)") + ylab("Portion of commits") + opts(title="Circadian rhythms of 37signals", axis.text.y=theme_blank(), axis.ticks=theme_blank()) + xlim(5,28)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment