更新 统计信息到 log中的方式
This commit is contained in:
@@ -88,25 +88,61 @@ class LogManager:
|
|||||||
fail_items = []
|
fail_items = []
|
||||||
if fail_details:
|
if fail_details:
|
||||||
# 按失败次数排序,取前5个
|
# 按失败次数排序,取前5个
|
||||||
sorted_fail_items = sorted(fail_details.items(), key=lambda x: x[1], reverse=True)[:5]
|
sorted_fail_items = sorted(fail_details.items(), key=lambda x: x[1], reverse=True)[:10]
|
||||||
for test_name, count in sorted_fail_items:
|
for test_name, count in sorted_fail_items:
|
||||||
fail_items.append(f"{test_name}({count}次)")
|
fail_items.append(f"{test_name}({count}次)")
|
||||||
|
if len (sorted_fail_items)>10:
|
||||||
|
lastitems = sorted(fail_details.items(), key=lambda x: x[1], reverse=True)[10:]
|
||||||
|
messageappend =''
|
||||||
|
for test_name, count in lastitems:
|
||||||
|
messageappend +=f"{test_name}({count}次)|"
|
||||||
|
fail_items.append(f"{messageappend})")
|
||||||
|
|
||||||
# 写入Cell统计信息
|
# 写入Cell统计信息
|
||||||
f.write(f"Cell {cell}: 文件数={file_count}, SN:{sn_list}, FAIL数={fail_count}\n")
|
f.write(f"Cell {cell}: 文件数={file_count}, SN:{sn_list}, FAIL数={fail_count}\n")
|
||||||
|
|
||||||
# 如果有失败项,写入失败详情
|
# 如果有失败项,写入失败详情
|
||||||
if fail_items:
|
if fail_items:
|
||||||
f.write(f" FAIL项: {', '.join(fail_items)}\n")
|
f.write(f" FAIL项:\n{'\n'.join(fail_items)}\n")
|
||||||
|
|
||||||
# SN统计
|
# SN统计(优化后的格式)
|
||||||
if statistics_data.get('sn_statistics'):
|
if statistics_data.get('sn_statistics'):
|
||||||
f.write("\n=== SN统计 ===\n")
|
f.write("\n=== SN统计 ===\n")
|
||||||
sn_stats = statistics_data['sn_statistics']
|
sn_stats = statistics_data['sn_statistics']
|
||||||
for sn, stats in sn_stats.items():
|
|
||||||
f.write(f"SN {sn}: 文件数={stats.get('file_count', 0)}, "
|
# 按SN排序(按字母顺序)
|
||||||
f"Cell数={len(stats.get('cells', []))}, "
|
sorted_sns = sorted(sn_stats.keys())
|
||||||
f"FAIL数={stats.get('fail_count', 0)}\n")
|
|
||||||
|
for sn in sorted_sns:
|
||||||
|
stats = sn_stats[sn]
|
||||||
|
file_count = stats.get('file_count', 0)
|
||||||
|
cells = stats.get('cells', [])
|
||||||
|
fail_count = stats.get('fail_count', 0)
|
||||||
|
fail_details = stats.get('fail_details', {})
|
||||||
|
|
||||||
|
# Cell列表(逗号分隔)
|
||||||
|
cell_list = ','.join(sorted(cells, key=lambda x: int(x) if x.isdigit() else x))
|
||||||
|
|
||||||
|
# 失败项详情
|
||||||
|
fail_items = []
|
||||||
|
if fail_details:
|
||||||
|
# 按失败次数排序,取前5个
|
||||||
|
sorted_fail_items = sorted(fail_details.items(), key=lambda x: x[1], reverse=True)[:10]
|
||||||
|
for test_name, count in sorted_fail_items:
|
||||||
|
fail_items.append(f"{test_name}({count}次)")
|
||||||
|
if len (sorted_fail_items)>10:
|
||||||
|
lastitems = sorted(fail_details.items(), key=lambda x: x[1], reverse=True)[10:]
|
||||||
|
messageappend =''
|
||||||
|
for test_name, count in lastitems:
|
||||||
|
messageappend +=f"{test_name}({count}次)|"
|
||||||
|
fail_items.append(f"{messageappend})")
|
||||||
|
|
||||||
|
# 写入SN统计信息
|
||||||
|
f.write(f"SN {sn}: 文件数={file_count}, Cell数={len(cells)}, FAIL数={fail_count}\n")
|
||||||
|
|
||||||
|
# 如果有失败项,写入失败详情
|
||||||
|
if fail_items:
|
||||||
|
f.write(f" FAIL项:\n{'\n'.join(fail_items)}\n")
|
||||||
|
|
||||||
# 失败项统计
|
# 失败项统计
|
||||||
if statistics_data.get('failure_details'):
|
if statistics_data.get('failure_details'):
|
||||||
@@ -885,7 +921,8 @@ class StatisticsCollector:
|
|||||||
'file_count': 0,
|
'file_count': 0,
|
||||||
'cells': set(),
|
'cells': set(),
|
||||||
'fail_count': 0,
|
'fail_count': 0,
|
||||||
'elevation_count': 0
|
'elevation_count': 0,
|
||||||
|
'fail_details': defaultdict(int) # 新增:SN级别的失败项详情
|
||||||
})
|
})
|
||||||
|
|
||||||
self.failure_details = {
|
self.failure_details = {
|
||||||
@@ -920,8 +957,8 @@ class StatisticsCollector:
|
|||||||
self.cell_statistics[cell]['sn_set'].add(sn)
|
self.cell_statistics[cell]['sn_set'].add(sn)
|
||||||
self.cell_statistics[cell]['fail_count'] += fail_count
|
self.cell_statistics[cell]['fail_count'] += fail_count
|
||||||
|
|
||||||
# 收集失败项详情
|
# 收集失败项详情(同时收集SN和Cell级别的)
|
||||||
self._collect_fail_details(cell, rows, result.get("headers", []))
|
self._collect_fail_details(sn, cell, rows, result.get("headers", []))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.failed_files += 1
|
self.failed_files += 1
|
||||||
@@ -929,8 +966,8 @@ class StatisticsCollector:
|
|||||||
f"{result.get('file', '未知文件')}: {result.get('error', '未知错误')}"
|
f"{result.get('file', '未知文件')}: {result.get('error', '未知错误')}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _collect_fail_details(self, cell, rows, headers):
|
def _collect_fail_details(self, sn, cell, rows, headers):
|
||||||
"""收集失败项详情"""
|
"""收集失败项详情(包括SN和Cell级别)"""
|
||||||
try:
|
try:
|
||||||
# 找到状态列和测试名称列的索引
|
# 找到状态列和测试名称列的索引
|
||||||
status_idx = -1
|
status_idx = -1
|
||||||
@@ -958,6 +995,8 @@ class StatisticsCollector:
|
|||||||
test_name = str(row[test_name_col_idx]).strip()
|
test_name = str(row[test_name_col_idx]).strip()
|
||||||
|
|
||||||
if 'FAIL' in status_val and test_name:
|
if 'FAIL' in status_val and test_name:
|
||||||
|
# 同时记录SN级别和Cell级别的失败项
|
||||||
|
self.sn_statistics[sn]['fail_details'][test_name] += 1
|
||||||
self.cell_statistics[cell]['fail_details'][test_name] += 1
|
self.cell_statistics[cell]['fail_details'][test_name] += 1
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1004,7 +1043,8 @@ class StatisticsCollector:
|
|||||||
'sn_statistics': {sn: {
|
'sn_statistics': {sn: {
|
||||||
'file_count': stats['file_count'],
|
'file_count': stats['file_count'],
|
||||||
'cells': list(stats['cells']),
|
'cells': list(stats['cells']),
|
||||||
'fail_count': stats['fail_count']
|
'fail_count': stats['fail_count'],
|
||||||
|
'fail_details': dict(stats['fail_details']) # 包含失败项详情
|
||||||
} for sn, stats in self.sn_statistics.items()},
|
} for sn, stats in self.sn_statistics.items()},
|
||||||
'failure_details': self.failure_details,
|
'failure_details': self.failure_details,
|
||||||
'test_elevation_stats': self.test_elevation_stats
|
'test_elevation_stats': self.test_elevation_stats
|
||||||
@@ -1038,7 +1078,7 @@ class ParallelHTMLReportProcessor:
|
|||||||
self._collect_sn_distribution(all_files)
|
self._collect_sn_distribution(all_files)
|
||||||
|
|
||||||
# 显示文件分布
|
# 显示文件分布
|
||||||
# self._display_file_distribution()
|
self._display_file_distribution()
|
||||||
|
|
||||||
# 设置工作进程数
|
# 设置工作进程数
|
||||||
if max_workers is None:
|
if max_workers is None:
|
||||||
@@ -1133,8 +1173,8 @@ class ParallelHTMLReportProcessor:
|
|||||||
if len(self.sn_file_counts) > 10:
|
if len(self.sn_file_counts) > 10:
|
||||||
dist_info.append(f"... 还有 {len(self.sn_file_counts) - 10} 个SN")
|
dist_info.append(f"... 还有 {len(self.sn_file_counts) - 10} 个SN")
|
||||||
|
|
||||||
self.log_manager.log_info(f"SN文件分布: {chr(10).join(dist_info)}")
|
self.log_manager.log_info(f"{Fore.MAGENTA}⚫SN文件分布: \n{chr(10).join(dist_info)}")
|
||||||
print(f"{Fore.MAGENTA}⚫ SN文件分布:\n{Fore.CYAN}{chr(10).join(dist_info)}")
|
# print(f"{Fore.MAGENTA}⚫ SN文件分布:\n{Fore.CYAN}{chr(10).join(dist_info)}")
|
||||||
|
|
||||||
def _store_result_data(self, result):
|
def _store_result_data(self, result):
|
||||||
"""存储处理结果"""
|
"""存储处理结果"""
|
||||||
|
|||||||
Reference in New Issue
Block a user