status_config.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # status_config.py
  2. import pandas as pd
  3. import os
  4. from typing import Dict, List, Set
  5. class StatusConfig:
  6. """状态测点配置管理器"""
  7. def __init__(self, status_csv_path: str = None):
  8. self.status_features = set()
  9. self.status_csv_path = status_csv_path
  10. self._load_status_features()
  11. def _load_status_features(self):
  12. """加载状态测点配置"""
  13. # 如果提供了CSV文件路径,从文件加载
  14. if self.status_csv_path and os.path.exists(self.status_csv_path):
  15. try:
  16. df = pd.read_csv(self.status_csv_path)
  17. if 'status_feature' in df.columns:
  18. self.status_features = set(df['status_feature'].dropna().tolist())
  19. print(f"加载 {len(self.status_features)} 个状态测点")
  20. return
  21. except Exception as e:
  22. print(f"加载状态测点CSV文件失败: {str(e)}")
  23. # 如果没有CSV文件或加载失败,使用内置的状态测点关键词
  24. status_keywords = [
  25. 'sts', 'pump_act', 'sig', 'fault', 'conv_err', 'alarm',
  26. 'chain', 'estop', 'ups'
  27. ]
  28. self.status_features = set(status_keywords)
  29. print("使用内置状态测点关键词")
  30. def is_status_feature(self, feature_name: str) -> bool:
  31. """判断是否为状态测点"""
  32. feature_lower = feature_name.lower()
  33. return any(keyword in feature_lower for keyword in self.status_features)
  34. def filter_status_features(self, features: List[str]) -> List[str]:
  35. """过滤掉状态测点,只保留量测数据"""
  36. return [f for f in features if not self.is_status_feature(f)]
  37. def get_status_features(self, features: List[str]) -> List[str]:
  38. """获取状态测点列表"""
  39. return [f for f in features if self.is_status_feature(f)]