| import re |
| import os |
| from collections import Counter |
|
|
| |
| |
| LOG_FILE = 'copy_errors.log' |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| PATH_PATTERN = re.compile(r'data/raw_images/([^/]+)/([^/]+)/images/') |
| |
|
|
| def analyze_log(log_file): |
| if not os.path.exists(log_file): |
| print(f"[Error] 找不到日志文件: {log_file}") |
| return |
|
|
| print(f"[*] 正在分析日志文件: {log_file} ...") |
|
|
| failed_categories = set() |
| failed_sequences = set() |
| |
| |
| category_counter = Counter() |
| sequence_counter = Counter() |
|
|
| |
| cat_seq_map = {} |
|
|
| with open(log_file, 'r', encoding='utf-8') as f: |
| current_path = "" |
| |
| for line in f: |
| line = line.strip() |
| |
| |
| |
| if line.startswith("[FAIL] 图片路径:"): |
| |
| path_str = line.split(": ", 1)[1] |
| |
| |
| match = PATH_PATTERN.search(path_str) |
| if match: |
| category = match.group(1) |
| sequence = match.group(2) |
|
|
| |
| failed_categories.add(category) |
| failed_sequences.add(sequence) |
|
|
| |
| category_counter[category] += 1 |
| sequence_counter[sequence] += 1 |
|
|
| |
| if category not in cat_seq_map: |
| cat_seq_map[category] = set() |
| cat_seq_map[category].add(sequence) |
| else: |
| |
| |
| pass |
|
|
| |
| print("\n" + "="*50) |
| print("分析报告 (Analysis Report)") |
| print("="*50) |
|
|
| print(f"\n1. 缺失图片涉及的 Category 总数: {len(failed_categories)}") |
| print("-" * 30) |
| |
| for cat, count in category_counter.most_common(): |
| print(f" - {cat}: 缺失 {count} 张图") |
|
|
| print(f"\n2. 缺失图片涉及的 Sequence 总数: {len(failed_sequences)}") |
| print("-" * 30) |
| |
| top_n = 20 |
| for seq, count in sequence_counter.most_common(top_n): |
| print(f" - {seq}: 缺失 {count} 张图") |
| if len(sequence_counter) > top_n: |
| print(f" ... (还有 {len(sequence_counter) - top_n} 个 sequence)") |
|
|
| print(f"\n3. 详细层级结构 (Category -> Sequence)") |
| print("-" * 30) |
| for cat in sorted(cat_seq_map.keys()): |
| seqs = cat_seq_map[cat] |
| print(f"[{cat}] 下有 {len(seqs)} 个有问题的 sequence:") |
| |
| sorted_seqs = sorted(list(seqs)) |
| |
| |
| |
| print(f" {', '.join(sorted_seqs)}") |
| print("") |
|
|
| |
| output_file = "missing_stats.txt" |
| with open(output_file, 'w', encoding='utf-8') as f_out: |
| f_out.write("=== 缺失数据统计 ===\n") |
| f_out.write(f"Category 总数: {len(failed_categories)}\n") |
| f_out.write(f"Sequence 总数: {len(failed_sequences)}\n\n") |
| |
| f_out.write("=== Category 列表 (格式: 名称 [缺失数量]) ===\n") |
| for cat, count in category_counter.most_common(): |
| f_out.write(f"{cat} [{count}]\n") |
| |
| f_out.write("\n=== Sequence 列表 (按 Category 分组) ===\n") |
| for cat in sorted(cat_seq_map.keys()): |
| f_out.write(f"\n[{cat}]\n") |
| for seq in sorted(list(cat_seq_map[cat])): |
| f_out.write(f" - {seq} (缺失 {sequence_counter[seq]} 张)\n") |
| |
| print(f"\n[*] 详细统计已保存至: {output_file}") |
|
|
| if __name__ == "__main__": |
| analyze_log(LOG_FILE) |
|
|