"""Re-split the downloaded feature requests by issue number: odd numbers for exploration, even numbers held out. Reads the two files written by the download run (paths as arguments) and writes explore.json and holdout.json into $CLAIMSET_RUN_DIR. Reports only counts. """ import json import os import sys issues = [] for p in sys.argv[1:]: issues += json.load(open(p)) issues.sort(key=lambda i: i["number"]) explore = [i for i in issues if i["number"] % 2 == 1] holdout = [i for i in issues if i["number"] % 2 == 0] out = os.environ.get("CLAIMSET_RUN_DIR", ".") for name, part in (("explore", explore), ("holdout", holdout)): with open(os.path.join(out, f"{name}.json"), "w") as f: json.dump(part, f, indent=0, ensure_ascii=False) results = [ {"quantity": "feature-request issues with odd numbers (exploration set)", "value": len(explore)}, {"quantity": "feature-request issues with even numbers (held-out set)", "value": len(holdout)}, ] path = os.environ.get("CLAIMSET_RESULTS") if path: with open(path, "w") as f: json.dump(results, f) print(json.dumps(results))