MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / build_data

Function build_data

codeclash/analysis/viz/line_chart_per_round_changes.py:51–106  ·  view source on GitHub ↗

Walk logs and build model -> list[list[int]] for rounds 1..ROUNDS. Returns a dict where each model maps to a list of ROUNDS lists, where each inner list contains ints = number of lines changed in that game/round by that model.

(log_dir: Path)

Source from the content-addressed store, hash-verified

49
50
51def build_data(log_dir: Path):
52 """Walk logs and build model -> list[list[int]] for rounds 1..ROUNDS.
53
54 Returns a dict where each model maps to a list of ROUNDS lists, where each
55 inner list contains ints = number of lines changed in that game/round by
56 that model.
57 """
58 model_to_round_lines = {}
59
60 tournaments = [x.parent for x in log_dir.rglob("metadata.json")]
61 for game_log_folder in tqdm(tournaments, desc="Scanning tournaments"):
62 try:
63 with open(game_log_folder / "metadata.json") as f:
64 metadata = json.load(f)
65 except Exception:
66 continue
67
68 try:
69 p2m = {
70 x["name"]: x["config"]["model"]["model_name"].strip("@").split("/")[-1]
71 for x in metadata["config"]["players"]
72 }
73 except Exception:
74 # malformed metadata
75 continue
76
77 # ensure models exist in dict
78 for model in set(p2m.values()):
79 model_to_round_lines.setdefault(model, [[] for _ in range(ROUNDS)])
80
81 # collect changes files per player
82 for player_name, model in p2m.items():
83 changes_files = (game_log_folder / "players" / player_name).rglob("changes_r*.json")
84 for changes_file in changes_files:
85 m = re.search(r"changes_r(\d+)\.json", changes_file.name)
86 if not m:
87 continue
88 round_idx = int(m.group(1))
89 if round_idx < 1 or round_idx > ROUNDS:
90 continue
91
92 try:
93 with open(changes_file) as f:
94 changes = json.load(f)
95 except Exception:
96 continue
97
98 patch_text = changes.get("incremental_diff")
99 if not patch_text:
100 # no diff recorded for this round
101 continue
102
103 num_lines = _lines_changed_from_patch_text(patch_text)
104 model_to_round_lines.setdefault(model, [[] for _ in range(ROUNDS)])[round_idx - 1].append(num_lines)
105
106 return model_to_round_lines
107
108

Callers 1

mainFunction · 0.70

Calls 2

getMethod · 0.80

Tested by

no test coverage detected