refactor(config): 重构配置模块并优化应用依赖注入

- 将配置相关类移动到model模块
- 实现依赖注入容器管理各组件依赖关系
- 重构配置加载逻辑支持多层级键值查找
- 更新主应用入口支持命令行参数解析
- 统一日志输出格式替换原有打印语句
- 引入钻井实时数据模型简化数据处理
- 移除硬编码字段映射改用动态配置方式
- 优化数据库写入逻辑基于新的数据模型
This commit is contained in:
2026-03-12 10:41:26 +08:00
parent 6d13da4cc2
commit 6557479a2f
16 changed files with 783 additions and 589 deletions

176
model/drilling.py Normal file
View File

@@ -0,0 +1,176 @@
import time
from dataclasses import dataclass
from datetime import datetime
DATA_KEYS = [
"ts",
"wellid",
"stknum",
"recid",
"seqid",
"actual_date",
"actual_time",
"actcod",
"deptbitm",
"deptbitv",
"deptmeas",
"deptvert",
"blkpos",
"ropa",
"hkla",
"hklx",
"woba",
"wobx",
"torqa",
"torqx",
"rpma",
"sppa",
"chkp",
"spm1",
"spm2",
"spm3",
"tvolact",
"tvolcact",
"mfop",
"mfoa",
"mfia",
"mdoa",
"mdia",
"mtoa",
"mtia",
"mcoa",
"mcia",
"stkc",
"lagstks",
"deptretm",
"gasa",
"space1",
"space2",
"space3",
"space4",
"space5",
]
@dataclass(frozen=True)
class DrillingRealtimeData:
ts: int
wellid: str
stknum: int
recid: int
seqid: int
actual_date: float
actual_time: float
actcod: int
deptbitm: float
deptbitv: float
deptmeas: float
deptvert: float
blkpos: float
ropa: float
hkla: float
hklx: float
woba: float
wobx: float
torqa: float
torqx: float
rpma: int
sppa: float
chkp: float
spm1: int
spm2: int
spm3: int
tvolact: float
tvolcact: float
mfop: int
mfoa: float
mfia: float
mdoa: float
mdia: float
mtoa: float
mtia: float
mcoa: float
mcia: float
stkc: int
lagstks: int
deptretm: float
gasa: float
space1: float
space2: float
space3: float
space4: float
space5: float
@classmethod
def empty(cls, wellid=""):
now = datetime.utcnow()
return cls(
ts=int(time.time() * 1000),
wellid=wellid,
stknum=0,
recid=0,
seqid=0,
actual_date=float(now.strftime("%Y%m%d")),
actual_time=float(now.strftime("%H%M%S")),
actcod=0,
deptbitm=0.0,
deptbitv=0.0,
deptmeas=0.0,
deptvert=0.0,
blkpos=0.0,
ropa=0.0,
hkla=0.0,
hklx=0.0,
woba=0.0,
wobx=0.0,
torqa=0.0,
torqx=0.0,
rpma=0,
sppa=0.0,
chkp=0.0,
spm1=0,
spm2=0,
spm3=0,
tvolact=0.0,
tvolcact=0.0,
mfop=0,
mfoa=0.0,
mfia=0.0,
mdoa=0.0,
mdia=0.0,
mtoa=0.0,
mtia=0.0,
mcoa=0.0,
mcia=0.0,
stkc=0,
lagstks=0,
deptretm=0.0,
gasa=0.0,
space1=0.0,
space2=0.0,
space3=0.0,
space4=0.0,
space5=0.0,
)
@classmethod
def from_payload(cls, payload):
meta = payload.get("meta") if isinstance(payload, dict) and isinstance(payload.get("meta"), dict) else {}
data = payload.get("data") if isinstance(payload, dict) and isinstance(payload.get("data"), dict) else {}
values = {key: data.get(key, 0) for key in DATA_KEYS}
values["ts"] = int(data.get("ts", data.get("record_time", int(time.time() * 1000))))
values["wellid"] = data.get("wellid") or meta.get("equipment_code") or meta.get("equipment_sn") or ""
return cls(**values)
def to_payload(self, equipment_code):
return {
"meta": {
"equipment_code": equipment_code,
"equipment_sn": equipment_code,
},
"data": {
key: getattr(self, key)
for key in DATA_KEYS
},
}