- 将配置相关类移动到model模块 - 实现依赖注入容器管理各组件依赖关系 - 重构配置加载逻辑支持多层级键值查找 - 更新主应用入口支持命令行参数解析 - 统一日志输出格式替换原有打印语句 - 引入钻井实时数据模型简化数据处理 - 移除硬编码字段映射改用动态配置方式 - 优化数据库写入逻辑基于新的数据模型
73 lines
1.6 KiB
Python
73 lines
1.6 KiB
Python
from dataclasses import dataclass
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class MqttConfig:
|
|
broker: str
|
|
client_id: str
|
|
mock_client_id: str
|
|
sender_client_id: str
|
|
subscriber_client_id: str
|
|
username: str | None
|
|
password: str | None
|
|
pub_topic: str | None
|
|
sub_topic: str | None
|
|
ack_topic: str | None
|
|
data_file: str
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class TmsConfig:
|
|
device_code: str
|
|
equipment_sn: str
|
|
timeout: int
|
|
keepalive: int
|
|
server_ip: str | None
|
|
server_port: int | None
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class WitsConfig:
|
|
host: str
|
|
port: int
|
|
timeout: int
|
|
source_file: str
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class TdengineConfig:
|
|
url: str = ""
|
|
username: str = ""
|
|
password: str = ""
|
|
database: str = ""
|
|
stable: str = "drilling_realtime_st"
|
|
device_code: str = "GJ-304-0088"
|
|
pool_size: int = 2
|
|
timeout: int = 10
|
|
|
|
@property
|
|
def base_url(self):
|
|
if not self.url:
|
|
return ""
|
|
raw = str(self.url).strip()
|
|
if raw.lower().startswith("jdbc:taos-rs://"):
|
|
raw = "http://" + raw[len("jdbc:TAOS-RS://") :]
|
|
elif "://" not in raw:
|
|
raw = "http://" + raw
|
|
parsed = urlparse(raw)
|
|
return f"{parsed.scheme or 'http'}://{parsed.hostname or '127.0.0.1'}:{parsed.port or 6041}"
|
|
|
|
@property
|
|
def enabled(self):
|
|
return bool(self.base_url and self.database and self.username)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class AppConfig:
|
|
mqtt: MqttConfig
|
|
tms: TmsConfig
|
|
wits: WitsConfig
|
|
tdengine: TdengineConfig
|
|
raw: dict
|