yocto-autobuilder-helper/scripts/patchmetrics-generate-chartdata
Richard Purdie a263c0b0d3 srcipts/generate-chartdata: Drop dateutil dependency
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2022-06-30 16:33:54 +01:00

55 lines
1.8 KiB
Python
Executable File

#!/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")