Skip to content
Snippets Groups Projects
Commit b99246f1 authored by Dave Pigott's avatar Dave Pigott
Browse files

Merge branch 'add-compare' into 'main'

Add compare script

See merge request !13
parents 75e5b474 0f6adbac
No related branches found
No related tags found
1 merge request!13Add compare script
compare 0 → 100755
#!/usr/bin/env python3
import json
import argparse
def load_json_as_dict(file_path):
try:
with open(file_path, 'r') as file:
data = json.load(file)
return data
except Exception as e:
print(f"An error occurred while loading {file_path}: {e}")
return None
def calculate_percentages(summary_dict):
percentages = {}
total_jobs = summary_dict.get("total_jobs", 0)
if total_jobs > 0:
for key, value in summary_dict.items():
if key != "total_jobs":
percentages[key] = (value / total_jobs) * 100
return percentages
def compare_reports(file1, file2):
data1 = load_json_as_dict(file1)
data2 = load_json_as_dict(file2)
if data1 and data2:
summary1 = data1.get("summary", {})
summary2 = data2.get("summary", {})
percentages1 = calculate_percentages(summary1)
percentages2 = calculate_percentages(summary2)
print("Percentage change report:")
for key in percentages1.keys():
if key in percentages2:
change = percentages2[key] - percentages1[key]
print(f"{key}: {change:.2f}%")
else:
print(f"{key} is not present in both reports.")
else:
print("Error: One or both of the files could not be loaded.")
def main():
parser = argparse.ArgumentParser(description="Compare job percentages between two JSON reports.")
parser.add_argument('file1', type=str, help="Path to the first JSON file")
parser.add_argument('file2', type=str, help="Path to the second JSON file")
args = parser.parse_args()
compare_reports(args.file1, args.file2)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment