Analyze line counts across all rounds for all files that appear in changed files
(self)
| 727 | return sorted((player_name, round_num) for player_name in player_names for round_num in round_nums) |
| 728 | |
| 729 | def analyze_line_counts(self) -> dict[str, Any]: |
| 730 | """Analyze line counts across all rounds for all files that appear in changed files""" |
| 731 | # Collect all files that appear in any changed files across all rounds and players |
| 732 | all_files = set() |
| 733 | players_dir = self.log_dir / "players" |
| 734 | |
| 735 | if not players_dir.exists(): |
| 736 | return {"all_files": [], "line_counts_by_round": {}} |
| 737 | |
| 738 | # First pass: collect all files from all changes_r*.json files |
| 739 | for player_dir in players_dir.iterdir(): |
| 740 | if not player_dir.is_dir(): |
| 741 | continue |
| 742 | |
| 743 | for changes_file in player_dir.glob("changes_r*.json"): |
| 744 | try: |
| 745 | changes_data = json.loads(changes_file.read_text()) |
| 746 | modified_files = changes_data.get("modified_files", {}) |
| 747 | all_files.update(modified_files.keys()) |
| 748 | except (json.JSONDecodeError, KeyError): |
| 749 | continue |
| 750 | |
| 751 | all_files_list = sorted(list(all_files)) |
| 752 | |
| 753 | # Second pass: count lines for each file in each round for each player |
| 754 | line_counts_by_round = {} |
| 755 | |
| 756 | for player_dir in players_dir.iterdir(): |
| 757 | if not player_dir.is_dir(): |
| 758 | continue |
| 759 | |
| 760 | player_name = player_dir.name |
| 761 | |
| 762 | # Get all rounds for this player |
| 763 | changes_files = sorted(player_dir.glob("changes_r*.json"), key=lambda x: int(x.stem.split("_r")[1])) |
| 764 | |
| 765 | # Track line counts for this player across rounds |
| 766 | player_line_counts = {} |
| 767 | current_file_lines = {} # Track current state of each file |
| 768 | |
| 769 | for changes_file in changes_files: |
| 770 | try: |
| 771 | round_num = int(changes_file.stem.split("_r")[1]) |
| 772 | changes_data = json.loads(changes_file.read_text()) |
| 773 | modified_files = changes_data.get("modified_files", {}) |
| 774 | |
| 775 | # Update line counts for files that changed in this round |
| 776 | for file_path, file_content in modified_files.items(): |
| 777 | if file_content: |
| 778 | current_file_lines[file_path] = len(file_content.splitlines()) |
| 779 | |
| 780 | # Record line counts for all files in this round |
| 781 | round_line_counts = {} |
| 782 | for file_path in all_files_list: |
| 783 | round_line_counts[file_path] = current_file_lines.get(file_path, 0) |
| 784 | |
| 785 | player_line_counts[round_num] = round_line_counts |
| 786 |
no test coverage detected