Page MenuHomePhabricator
Paste P5946

Script to convert thresholds output to CSV
ActivePublic

Authored by awight on Aug 30 2017, 5:57 AM.
Tags
None
Referenced Files
F9216904: Script to convert thresholds output to CSV
Aug 30 2017, 5:57 AM
Subscribers
None
#!/usr/bin/python
import csv
import json
content = open("draftquality.json", "r").read()
data = json.loads(content)
thresholds = data["scores"]["enwiki"]["draftquality"]["info"]["statistics"]["thresholds"]
out = open("draftquality.csv", "w")
fieldnames = thresholds["OK"][0].keys()
fieldnames.insert(0, "class")
writer = csv.DictWriter(out, fieldnames)
writer.writeheader()
for target_class, points in thresholds.items():
for threshold in points:
line = {"class": target_class}
line.update(threshold)
writer.writerow(line)
out.close()