新增 templates/ti-cl4/quality-forecast/features.py: - PointDict:解析 point_dict CSV(9 列,对齐 core/edge-gateway),检索/存在性校验 - FeatureSpec:声明式特征(source/transform/window/meaning),换行业只改清单 - FeatureExtractor:按清单从时序样本抽取特征矩阵,缺失值 NaN 占位 - 9 算子:raw/mean/std/min/max/range/diff/slope/ratio - 零依赖 YAML 子集加载(与 recipe-optim/data-bus 同款) - config/features.template.yaml:7 个默认特征(炉温/配比/CO波动/炉层/TiCl₄纯度) - 22 用例全通过;纯标准库零运行时依赖。
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Ti-1 质量预测 sanity 检查(无构建环境下的离线基本验证)。
|
|
|
|
检查项:
|
|
1. 默认特征清单 features.template.yaml 可加载且通过校验;
|
|
2. 特征 source/denominator 的点位都在默认点位字典内;
|
|
3. 全部测试用例通过。
|
|
|
|
用法:python _sanity_check.py
|
|
退出码:0 全通过,非 0 有失败。
|
|
"""
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
TESTS = os.path.join(HERE, "tests")
|
|
|
|
|
|
def main() -> int:
|
|
failures = []
|
|
|
|
# 1) 加载特征清单并校验点位
|
|
try:
|
|
sys.path.insert(0, TESTS)
|
|
import _bootstrap # noqa: F401 挂载 quality_forecast
|
|
from quality_forecast import features as F
|
|
ti_cl4 = os.path.dirname(HERE)
|
|
pd = F.PointDict.from_csv(
|
|
os.path.join(ti_cl4, "point-dict", "point_dict.default.csv"))
|
|
with open(os.path.join(HERE, "config", "features.template.yaml"),
|
|
"r", encoding="utf-8") as fh:
|
|
ext = F.load_feature_specs(fh.read(), pd)
|
|
if not ext.names:
|
|
failures.append("特征清单为空")
|
|
except Exception as exc: # noqa: BLE001
|
|
failures.append(f"特征清单加载失败: {exc}")
|
|
|
|
# 2) 跑测试
|
|
loader = unittest.TestLoader()
|
|
suite = loader.discover(TESTS, pattern="test_*.py")
|
|
runner = unittest.TextTestRunner(verbosity=1)
|
|
result = runner.run(suite)
|
|
if not result.wasSuccessful():
|
|
failures.append(f"{len(result.failures)} 失败, {len(result.errors)} 错误")
|
|
|
|
if failures:
|
|
print("\n[sanity] 失败:")
|
|
for f in failures:
|
|
print(" -", f)
|
|
return 1
|
|
print("\n[sanity] 全部通过")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|