refactor: merge _check_fault and _classify_fault into _analyze_fault
一次调用返回(fault_status, fault_type)元组,简化诊断逻辑
This commit is contained in:
+14
-33
@@ -65,13 +65,9 @@ class FaultDiagnoser:
|
||||
roi = img[y1:y2, x1:x2]
|
||||
temp_features = self.extractor.extract_from_roi(roi)
|
||||
|
||||
fault_status = self._check_fault(temp_features)
|
||||
fault_status, fault_type = self._analyze_fault(temp_features)
|
||||
temp_features['fault_status'] = fault_status
|
||||
# abnormal 时才进行故障分类,normal 时类型为 none
|
||||
if fault_status == 'abnormal':
|
||||
temp_features['fault_type'] = self._classify_fault(temp_features)
|
||||
else:
|
||||
temp_features['fault_type'] = 'none'
|
||||
temp_features['fault_type'] = fault_type
|
||||
|
||||
result['faults'].append(temp_features)
|
||||
else:
|
||||
@@ -80,51 +76,36 @@ class FaultDiagnoser:
|
||||
result['summary'] = self._generate_summary(result['faults'])
|
||||
return result
|
||||
|
||||
def _check_fault(self, temp_features: Dict) -> str:
|
||||
def _analyze_fault(self, temp_features: Dict) -> tuple:
|
||||
"""
|
||||
根据温度特征判断是否有故障
|
||||
分析温度特征,判断故障状态和类型
|
||||
|
||||
Args:
|
||||
temp_features: 温度特征
|
||||
|
||||
Returns:
|
||||
'normal' 或 'abnormal'
|
||||
(fault_status, fault_type) 元组
|
||||
"""
|
||||
max_temp = temp_features.get('temp_max', 0)
|
||||
mean_temp = temp_features.get('temp_mean', 0)
|
||||
std_temp = temp_features.get('temp_std', 0)
|
||||
temp_range = max_temp - temp_features.get('temp_mean', 0)
|
||||
|
||||
max_threshold = self.temp_threshold.get('max_temp', 200)
|
||||
std_threshold = self.temp_threshold.get('std_temp', 50)
|
||||
|
||||
if max_temp > max_threshold or std_temp > std_threshold:
|
||||
return 'abnormal'
|
||||
return 'normal'
|
||||
|
||||
def _classify_fault(self, temp_features: Dict) -> str:
|
||||
"""
|
||||
故障分类
|
||||
|
||||
Args:
|
||||
temp_features: 温度特征
|
||||
|
||||
Returns:
|
||||
故障类型
|
||||
"""
|
||||
max_temp = temp_features.get('temp_max', 0)
|
||||
mean_temp = temp_features.get('temp_mean', 0)
|
||||
std_temp = temp_features.get('temp_std', 0)
|
||||
|
||||
temp_range = max_temp - mean_temp
|
||||
# 判断状态:两项都不超标才为 normal
|
||||
if max_temp <= max_threshold and std_temp <= std_threshold:
|
||||
return ('normal', 'none')
|
||||
|
||||
# 分类故障类型
|
||||
if std_temp > 30:
|
||||
return 'hotspot'
|
||||
return ('abnormal', 'hotspot')
|
||||
elif temp_range > 50:
|
||||
return 'local_overheating'
|
||||
return ('abnormal', 'local_overheating')
|
||||
elif max_temp > 180:
|
||||
return 'overheat'
|
||||
return ('abnormal', 'overheat')
|
||||
else:
|
||||
return 'suspect'
|
||||
return ('abnormal', 'suspect')
|
||||
|
||||
def _generate_summary(self, faults: List[Dict]) -> Dict:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user