()
| 13 | |
| 14 | |
| 15 | def main(): |
| 16 | model_to_num_files = {} |
| 17 | |
| 18 | if not DATA_CACHE.exists(): |
| 19 | tournaments = [x.parent for x in LOCAL_LOG_DIR.rglob("metadata.json")] |
| 20 | for game_log_folder in tqdm(tournaments): |
| 21 | with open(game_log_folder / "metadata.json") as f: |
| 22 | metadata = json.load(f) |
| 23 | try: |
| 24 | p2m = { |
| 25 | x["name"]: x["config"]["model"]["model_name"].strip("@").split("/")[-1] |
| 26 | for x in metadata["config"]["players"] |
| 27 | } |
| 28 | for model in p2m.values(): |
| 29 | if model not in model_to_num_files: |
| 30 | model_to_num_files[model] = [] |
| 31 | except KeyError: |
| 32 | continue |
| 33 | |
| 34 | for name in p2m.keys(): |
| 35 | changes_files = (game_log_folder / "players" / name).rglob("changes_r*.json") |
| 36 | for changes_file in changes_files: |
| 37 | with open(changes_file) as f: |
| 38 | changes = json.load(f) |
| 39 | try: |
| 40 | num_files = len(PatchSet(changes["incremental_diff"])) |
| 41 | except Exception as e: |
| 42 | print(f"Issue parsing diff in {changes_file}, skipping: {e}") |
| 43 | continue |
| 44 | model_to_num_files[p2m[name]].append(num_files) |
| 45 | |
| 46 | with open(DATA_CACHE, "w") as f: |
| 47 | json.dump(model_to_num_files, f, indent=2) |
| 48 | |
| 49 | with open(DATA_CACHE) as f: |
| 50 | model_to_num_files = json.load(f) |
| 51 | |
| 52 | # Plot CDF |
| 53 | plt.figure(figsize=(6, 6)) |
| 54 | for model, files_edited in model_to_num_files.items(): |
| 55 | sorted_files_edited = sorted(files_edited) |
| 56 | yvals = [i / len(sorted_files_edited) for i in range(len(sorted_files_edited))] |
| 57 | plt.step( |
| 58 | sorted_files_edited, yvals, label=MODEL_TO_DISPLAY_NAME[model], where="post", color=MODEL_TO_COLOR[model] |
| 59 | ) |
| 60 | |
| 61 | LIM = 20 |
| 62 | plt.xlim(0, LIM) # Limit x-axis to 40 for better visibility |
| 63 | plt.xticks(range(0, LIM + 1, 5), fontsize=18, fontproperties=FONT_REG) |
| 64 | plt.yticks([i / 10 for i in range(11)], [f"{i * 10}%" for i in range(11)], fontsize=18, fontproperties=FONT_REG) |
| 65 | plt.xlabel("Files Edited per Round", fontproperties=FONT_BOLD, fontsize=18) |
| 66 | # plt.ylabel("Cumulative Probability", fontproperties=FONT_BOLD, fontsize=18) |
| 67 | # plt.title("CDF of Files Edited per Round by Model") |
| 68 | FONT_BOLD.set_size(18) |
| 69 | plt.legend(prop=FONT_BOLD) |
| 70 | plt.grid(True) |
| 71 | plt.savefig(OUTPUT_FILE, dpi=300, bbox_inches="tight") |
| 72 | print(f"Saved CDF plot to {OUTPUT_FILE}") |
no outgoing calls
no test coverage detected