forked from Wafelack/orion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sloc_chart.py
executable file
·41 lines (36 loc) · 1.54 KB
/
sloc_chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
from matplotlib import pyplot as plt
from datetime import datetime, timedelta
import subprocess
import json
import sys
if len(sys.argv) != 2:
print(f'Usage: {sys.argv[0]} <LANG>')
exit(1)
lang = sys.argv[1]
hashes=[h.split(' ')[0] for h in subprocess.run(['git', 'log', '--oneline'], capture_output=True).stdout.decode('utf-8').strip().split('\n')]
commit_date = subprocess.run(['git', 'show', '-s', '--oneline', '--format=%ci', hashes[-1]], capture_output=True).stdout.decode('utf-8').strip().split(' ')[0]
dateified = datetime.strptime(commit_date, '%Y-%m-%d')
today = datetime.now()
dates = []
sloc = []
while dateified < today:
date = dateified - timedelta(days=1)
stringified = f'{date.year}-{date.month}-{date.day}'
commit_hash = subprocess.run(['git', 'log', '--oneline', f'--after="{stringified}"'], capture_output=True).stdout.decode('utf-8').strip().split('\n')[-1].split(' ')[0]
print(f'{stringified}:{commit_hash} => ', end='')
subprocess.run(['git', 'checkout', commit_hash], capture_output=True)
stats=subprocess.run(['tokei', '-o', 'json'], capture_output=True).stdout.decode('utf-8').strip()
jsoned = json.loads(stats)
commit_sloc = 0
if lang in jsoned:
commit_sloc=int(json.loads(stats)[lang]['code'])
print(commit_sloc)
dates.append(stringified)
sloc.append(commit_sloc)
subprocess.run(['git', 'switch', '-'], capture_output=True)
dateified=dateified + timedelta(weeks=1)
plt.plot(dates, sloc)
plt.xlabel('Date (%Y-%m-%d)')
plt.ylabel('SLOC count')
plt.show()