Skip to content

Instantly share code, notes, and snippets.

@guilhermewop
Forked from Werkov/git-time-stats.py
Last active December 23, 2015 20:19
Show Gist options
  • Save guilhermewop/6689276 to your computer and use it in GitHub Desktop.
Save guilhermewop/6689276 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# Estimates time spent on a project from commit timestamps
#
# If two commits are less than INERTIA time apart, the time
# between them is considered spent, otherwise SINGLE_COMMIT
# time is taken.
import os
SINGLE_COMMIT=1800 # 30 min
#INERTIA=7200 # 2 h
#INERTIA=21600 # 6 h
INERTIA=28800 # 8 h
#log = os.popen("git log --since='2013-01-01' --until='2013-06-30' --author='guilhermewop@gmail.com' --pretty='format:%ae;%at'")
log = os.popen("git log --since='2013-01-01' --until='2013-06-30' --pretty='format:%ae;%at'")
lines = [line.strip().split(';') for line in log]
commits = dict()
last_commits = dict()
cum_time = dict()
for line in sorted(lines):
name, time = line
time = int(time)
if name not in last_commits:
last_commits[name] = None
cum_time[name] = 0
commits[name] = 0
if last_commits[name] != None and time - last_commits[name] <= INERTIA:
cum_time[name] += time - last_commits[name]
else:
cum_time[name] += SINGLE_COMMIT
commits[name] += 1
last_commits[name] = time
for name, time in cum_time.items():
print("{}\t{:.1f}\t{}\t{:.0f}".format(name, time/3600, commits[name], time/commits[name]/60))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment