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

Method parse_trajectory

codeclash/viewer/app.py:612–714  ·  view source on GitHub ↗

Parse a specific trajectory file Args: player_name: Name of the player round_num: Round number load_diffs: If True, load diff data. If False (default), skip loading diffs for performance load_messages: If True, load messages/submission/memory.

(
        self, player_name: str, round_num: int, *, load_diffs: bool = False, load_messages: bool = False
    )

Source from the content-addressed store, hash-verified

610 )
611
612 def parse_trajectory(
613 self, player_name: str, round_num: int, *, load_diffs: bool = False, load_messages: bool = False
614 ) -> TrajectoryInfo | None:
615 """Parse a specific trajectory file
616
617 Args:
618 player_name: Name of the player
619 round_num: Round number
620 load_diffs: If True, load diff data. If False (default), skip loading diffs for performance
621 load_messages: If True, load messages/submission/memory. If False (default), skip for performance
622 """
623 player_dir = self.log_dir / "players" / player_name
624 if not player_dir.exists():
625 return None
626
627 # Get stats from metadata.json first
628 metadata = self._get_metadata()
629 agent_stats = None
630
631 # Find the agent index for this player
632 agents = metadata.raw_data.get("agents", [])
633 for agent in agents:
634 if agent.get("name") == player_name:
635 agent_stats_dict = agent.get("agent_stats", {})
636 agent_stats = agent_stats_dict.get(str(round_num))
637 break
638
639 # Default values if not found in metadata
640 api_calls = 0
641 cost = 0.0
642 exit_status = None
643
644 if agent_stats:
645 api_calls = agent_stats.get("api_calls", 0)
646 cost = agent_stats.get("cost", 0.0)
647 exit_status = agent_stats.get("exit_status")
648
649 # Load trajectory file for messages, submission, and memory only if requested
650 traj_file = player_dir / f"{player_name}_r{round_num}.traj.json"
651 messages = []
652 submission = None
653 memory = None
654
655 if load_messages and traj_file.exists():
656 try:
657 data = json.loads(traj_file.read_text())
658 messages = data.get("messages", [])
659 info = data.get("info", {})
660 submission = info.get("submission")
661 memory = info.get("memory")
662 except (json.JSONDecodeError, KeyError) as e:
663 logger.error(f"Error parsing trajectory file {traj_file}: {e}", exc_info=True)
664
665 # Get diff data from changes file only if requested
666 diff = incremental_diff = modified_files = None
667 diff_by_files = incremental_diff_by_files = None
668
669 if load_diffs:

Callers 3

_render_game_viewer_implFunction · 0.95
load_trajectory_detailsFunction · 0.95
load_trajectory_diffsFunction · 0.95

Calls 5

_get_metadataMethod · 0.95
filter_git_diffFunction · 0.90
split_git_diff_by_filesFunction · 0.90
TrajectoryInfoClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected