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

Method load_matrix_analysis

codeclash/viewer/app.py:837–908  ·  view source on GitHub ↗

Load and process matrix.json if it exists

(self)

Source from the content-addressed store, hash-verified

835 }
836
837 def load_matrix_analysis(self) -> dict[str, Any] | None:
838 """Load and process matrix.json if it exists"""
839 matrix_file = self.log_dir / "matrix.json"
840 if not matrix_file.exists():
841 return None
842
843 try:
844 matrix_data = json.loads(matrix_file.read_text())
845 matrices = matrix_data.get("matrices", {})
846 processed_matrices = {}
847
848 for matrix_name, matrix in matrices.items():
849 processed_matrix = {"name": matrix_name, "data": {}, "max_rounds": 0}
850
851 # Extract base player name from matrix name
852 base_player_name = matrix_name.split("_vs_")[0] if "_vs_" in matrix_name else None
853
854 # Determine matrix dimensions
855 max_i = max_j = 0
856 for i_str in matrix.keys():
857 i = int(i_str)
858 max_i = max(max_i, i)
859 for j_str in matrix[i_str].keys():
860 j = int(j_str)
861 max_j = max(max_j, j)
862
863 processed_matrix["max_rounds"] = max(max_i, max_j)
864
865 # Process each cell
866 for i_str in matrix.keys():
867 i = int(i_str)
868 processed_matrix["data"][i] = {}
869
870 for j_str in matrix[i_str].keys():
871 j = int(j_str)
872 cell_data = matrix[i_str][j_str]
873 scores = cell_data.get("scores", {})
874
875 # Calculate win percentage from row player perspective
876 row_player_name = f"{base_player_name}_r{i}" if base_player_name else None
877 if row_player_name and row_player_name in scores:
878 row_player_score = scores.get(row_player_name, 0)
879 total_games = sum(scores.values())
880 ties = scores.get("Tie", 0)
881 win_percentage = (
882 ((row_player_score + 0.5 * ties) / total_games) * 100 if total_games > 0 else 0
883 )
884 else:
885 win_percentage = 0
886
887 processed_matrix["data"][i][j] = {
888 "win_percentage": round(win_percentage, 1),
889 "scores": scores,
890 "winner": cell_data.get("winner"),
891 "total_games": sum(scores.values()) if scores else 0,
892 }
893
894 processed_matrices[matrix_name] = processed_matrix

Callers 1

_render_game_viewer_implFunction · 0.95

Calls 1

getMethod · 0.80

Tested by

no test coverage detected