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
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/usr/bin/env python3
import json, os.path, collections
import sys
import argparse
import subprocess
import tempfile
from datetime import datetime, date, timedelta
args = argparse.ArgumentParser(description="Generate Patch Metric Chart data files")
args.add_argument("-j", "--json", help="JSON data file to use")
args.add_argument("-o", "--outputdir", help="output directory")
args = args.parse_args()
status_values = ["accepted", "pending", "inappropriate", "backport", "submitted", "denied", "inactive-upstream", "malformed-upstream-status", "malformed-sob"]
data = json.load(open(args.json))
#
# Write the latest patch breakdown to a file for the pie chart
#
latest = {'date' : "0"}
for i in data:
if int(i['date']) > int(latest['date']):
latest = i
json.dump(latest, open(args.outputdir + "/patch-status-pie.json", "w"), sort_keys=True, indent="\t")
#
# Write patch counts by day
#
def round_to_day(val):
return int((datetime.fromtimestamp(int(val)).date() - date(1970, 1, 1)).total_seconds())
a_year_ago = (datetime.now() - timedelta(days=365) - datetime(1970, 1, 1)).total_seconds()
newdata = []
lastyeardata = []
databydate = {}
for i in data:
rounded = round_to_day(i['date'])
if rounded not in databydate:
databydate[rounded] = i
elif rounded in databydate and databydate[rounded]['date'] < i['date']:
databydate[rounded] = i
for i in databydate:
for todel in ['commit', 'commit_count']:
if todel in databydate[i]:
del databydate[i][todel]
newdata.append(databydate[i])
if int(databydate[i]['date']) > a_year_ago:
lastyeardata.append(databydate[i])
json.dump(newdata, open(args.outputdir + "/patch-status-byday.json", "w"), sort_keys=True, indent="\t")
json.dump(lastyeardata, open(args.outputdir + "/patch-status-byday-lastyear.json", "w"), sort_keys=True, indent="\t")
|