Files
iAOP/core/edge-gateway/point_dict/schema.py
T
yunmei f49c0920d4 feat: 完成 issue #3 边缘采集网关模板化封装
- 点位字典 CSV schema/加载/自动校验(缺失字段/量纲/重复点号,PRD 5.1)
- 协议可插拔只读驱动:OPC UA(S7-1200 适配)/S7/Modbus/称重/能源/模拟
- 周期采集引擎:只读+背压保护+健康度指标(丢失率/P99/可用性)
- Kafka 流式上行 + 本地 spool 断点续传(丢失率≤0.02% 保障)
- 模板配置外置(gateway.yaml + 点位字典 CSV),换行业零改码
- 18 个单元测试全绿;端到端运行 SLA 达标
2026-08-04 15:32:16 +08:00

47 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""点位字典 CSV schema —— 对齐 PRD 5.1「边缘采集网关」字段规范表。
字段表(PRD 5.1):
device_id string 必填,唯一 设备编号,如 CLF-01
point_id string 必填,唯一 测点编号,如 CLF-01.TEMP
name string 必填 中文名,如 炉温
unit enum 必填 ℃ / kPa / m³/h / % / ...
dataType enum 必填 float / int / bool
sampleRate int 必填, >0 采集周期(ms)
qualityCode bool 默认 true 是否启用质量码
opcNode string 选填 OPC UA 节点路径
"""
from __future__ import annotations
from typing import List
# 合法量纲集合(可按行业模板扩展;此处覆盖化工/氯化车间常用量纲)
VALID_UNITS: List[str] = [
"℃", "kPa", "MPa", "m³/h", "m3/h", "%", "kg", "t", "t/h", "m³", "m3",
"A", "V", "Hz", "kW", "kWh", "Pa", "bar", "mm", "L", "L/min", "m/s",
]
# 合法数据类型集合
VALID_DATA_TYPES: List[str] = ["float", "int", "bool"]
# 必填字段
REQUIRED_FIELDS: List[str] = ["device_id", "point_id", "name", "unit", "dataType", "sampleRate"]
# CSV 表头(列顺序固定,便于实施工程师对照 DCS 点表填写)
CSV_HEADERS: List[str] = [
"device_id", "point_id", "name", "unit", "dataType", "sampleRate",
"qualityCode", "opcNode",
]
def is_valid_unit(unit: str) -> bool:
"""量纲合法性校验(大小写不敏感)。"""
if not unit or unit != unit.strip():
return False
return unit in VALID_UNITS
def is_valid_data_type(dtype: str) -> bool:
"""数据类型合法性校验。"""
return dtype in VALID_DATA_TYPES