|
@@ -1,4 +1,4 @@
|
|
|
-from typing import Dict
|
|
|
|
|
|
|
+from typing import Dict, Optional
|
|
|
from dataclasses import replace
|
|
from dataclasses import replace
|
|
|
|
|
|
|
|
import numpy as np
|
|
import numpy as np
|
|
@@ -62,15 +62,14 @@ class DQNStateBuilder:
|
|
|
# ======================================================================
|
|
# ======================================================================
|
|
|
# 对外主接口
|
|
# 对外主接口
|
|
|
# ======================================================================
|
|
# ======================================================================
|
|
|
-
|
|
|
|
|
def build_from_csv_pair(
|
|
def build_from_csv_pair(
|
|
|
- self,
|
|
|
|
|
- unit_name,
|
|
|
|
|
- uf_state_default,
|
|
|
|
|
- state_bounds,
|
|
|
|
|
- prev_cycle_csv: str,
|
|
|
|
|
- init_cycle_csv: str,
|
|
|
|
|
- predict_cycle_csv: str,
|
|
|
|
|
|
|
+ self,
|
|
|
|
|
+ unit_name,
|
|
|
|
|
+ uf_state_default,
|
|
|
|
|
+ state_bounds,
|
|
|
|
|
+ prev_cycle_csv: str,
|
|
|
|
|
+ init_cycle_csv: str,
|
|
|
|
|
+ predict_cycle_csv: Optional[str] = None,
|
|
|
) -> UFState:
|
|
) -> UFState:
|
|
|
"""
|
|
"""
|
|
|
使用【上一完整化学周期 CSV】+【当前周期初始 CSV】+ 【当前周期预测 CSV】构建 UFState
|
|
使用【上一完整化学周期 CSV】+【当前周期初始 CSV】+ 【当前周期预测 CSV】构建 UFState
|
|
@@ -78,11 +77,26 @@ class DQNStateBuilder:
|
|
|
|
|
|
|
|
df_prev = pd.read_csv(prev_cycle_csv)
|
|
df_prev = pd.read_csv(prev_cycle_csv)
|
|
|
df_init = pd.read_csv(init_cycle_csv)
|
|
df_init = pd.read_csv(init_cycle_csv)
|
|
|
- df_predict = pd.read_csv(predict_cycle_csv)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # predict_csv 允许为空
|
|
|
|
|
+ df_predict = None
|
|
|
|
|
+ if predict_cycle_csv is not None:
|
|
|
|
|
+ df_predict = pd.read_csv(predict_cycle_csv)
|
|
|
|
|
|
|
|
# 分别处理两个 CSV
|
|
# 分别处理两个 CSV
|
|
|
- prev_features = self._analyze_previous_cycle_csv(df_prev, unit_name, uf_state_default, state_bounds)
|
|
|
|
|
- init_features = self._analyze_init_cycle_csv(df_init, unit_name, uf_state_default, state_bounds)
|
|
|
|
|
|
|
+ prev_features = self._analyze_previous_cycle_csv(
|
|
|
|
|
+ df_prev,
|
|
|
|
|
+ unit_name,
|
|
|
|
|
+ uf_state_default,
|
|
|
|
|
+ state_bounds
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ init_features = self._analyze_init_cycle_csv(
|
|
|
|
|
+ df_init,
|
|
|
|
|
+ unit_name,
|
|
|
|
|
+ uf_state_default,
|
|
|
|
|
+ state_bounds
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 化学清洗去除阻力(上一周期末 - 当前初始)
|
|
# 化学清洗去除阻力(上一周期末 - 当前初始)
|
|
|
ceb_removal = max(
|
|
ceb_removal = max(
|
|
@@ -90,16 +104,20 @@ class DQNStateBuilder:
|
|
|
0.0
|
|
0.0
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- # 使用df_predict修正 nuk
|
|
|
|
|
- corrected_nuk = self._correct_nuk_with_predict(
|
|
|
|
|
- df_predict=df_predict,
|
|
|
|
|
- unit_name=unit_name,
|
|
|
|
|
- R_start=init_features["R_start"],
|
|
|
|
|
- q_mean=init_features["q_mean"],
|
|
|
|
|
- temp_celsius=init_features["temp_mean"],
|
|
|
|
|
- base_nuk=prev_features["nuK"],
|
|
|
|
|
- uf_state_default=uf_state_default,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ # 默认直接使用上一周期 nuK
|
|
|
|
|
+ corrected_nuk = prev_features["nuK"]
|
|
|
|
|
+
|
|
|
|
|
+ # 如果提供了 predict_csv,则进行在线修正
|
|
|
|
|
+ if df_predict is not None:
|
|
|
|
|
+ corrected_nuk = self._correct_nuk_with_predict(
|
|
|
|
|
+ df_predict=df_predict,
|
|
|
|
|
+ unit_name=unit_name,
|
|
|
|
|
+ R_start=init_features["R_start"],
|
|
|
|
|
+ q_mean=init_features["q_mean"],
|
|
|
|
|
+ temp_celsius=init_features["temp_mean"],
|
|
|
|
|
+ base_nuk=prev_features["nuK"],
|
|
|
|
|
+ uf_state_default=uf_state_default,
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 构建 UFState
|
|
# 构建 UFState
|
|
|
current_state = replace(
|
|
current_state = replace(
|
|
@@ -107,8 +125,8 @@ class DQNStateBuilder:
|
|
|
TMP=init_features["tmp_mean"],
|
|
TMP=init_features["tmp_mean"],
|
|
|
q_UF=init_features["q_mean"],
|
|
q_UF=init_features["q_mean"],
|
|
|
temp=init_features["temp_mean"],
|
|
temp=init_features["temp_mean"],
|
|
|
- R = init_features["R_start"],
|
|
|
|
|
- nuK = corrected_nuk,
|
|
|
|
|
|
|
+ R=init_features["R_start"],
|
|
|
|
|
+ nuK=corrected_nuk,
|
|
|
slope=prev_features["slope"],
|
|
slope=prev_features["slope"],
|
|
|
power=prev_features["power"],
|
|
power=prev_features["power"],
|
|
|
ceb_removal=ceb_removal,
|
|
ceb_removal=ceb_removal,
|
|
@@ -192,6 +210,7 @@ class DQNStateBuilder:
|
|
|
# -------- 5️⃣ 短期污染拟合(nuK)--------
|
|
# -------- 5️⃣ 短期污染拟合(nuK)--------
|
|
|
st_fitter = ShortTermCycleFoulingFitter(unit_name)
|
|
st_fitter = ShortTermCycleFoulingFitter(unit_name)
|
|
|
nuK, st_r2 = st_fitter.fit_cycle(stable_segments)
|
|
nuK, st_r2 = st_fitter.fit_cycle(stable_segments)
|
|
|
|
|
+
|
|
|
if (
|
|
if (
|
|
|
pd.isna(nuK)
|
|
pd.isna(nuK)
|
|
|
or pd.isna(st_r2)
|
|
or pd.isna(st_r2)
|
|
@@ -200,6 +219,14 @@ class DQNStateBuilder:
|
|
|
):
|
|
):
|
|
|
nuK = uf_state_default.nuK
|
|
nuK = uf_state_default.nuK
|
|
|
|
|
|
|
|
|
|
+ nuK = float(
|
|
|
|
|
+ np.clip(
|
|
|
|
|
+ nuK,
|
|
|
|
|
+ state_bounds.nuK_min,
|
|
|
|
|
+ state_bounds.nuK_max,
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
# -------- 6️⃣ 长期不可逆污染拟合 --------
|
|
# -------- 6️⃣ 长期不可逆污染拟合 --------
|
|
|
lt_fitter = LongTermFoulingFitter(unit_name)
|
|
lt_fitter = LongTermFoulingFitter(unit_name)
|
|
|
slope, power, lt_r2 = lt_fitter.fit_cycle(stable_segments)
|
|
slope, power, lt_r2 = lt_fitter.fit_cycle(stable_segments)
|