debug average vs max
This commit is contained in:
@@ -23,12 +23,24 @@ def clip(val: float, bounds: Tuple[float, float]) -> float:
|
||||
return max(lo, min(hi, val))
|
||||
|
||||
|
||||
def _match_factory_row(df: pd.DataFrame, cols: dict, factory_code: str) -> pd.Series:
|
||||
"""Match factory by English name first, fall back to Chinese name."""
|
||||
eng_col = cols["工厂英文名"]
|
||||
cn_col = cols["工厂中文名"]
|
||||
code_norm = factory_code.strip().lower()
|
||||
mask_eng = df[eng_col].astype(str).str.strip().str.lower() == code_norm
|
||||
if mask_eng.any():
|
||||
return df.loc[mask_eng].iloc[0]
|
||||
mask_cn = df[cn_col].astype(str).str.strip() == factory_code.strip()
|
||||
if mask_cn.any():
|
||||
return df.loc[mask_cn].iloc[0]
|
||||
raise ValueError(f"在{eng_col}/{cn_col} 中找不到工厂 {factory_code}")
|
||||
|
||||
|
||||
def load_factory_row(csv_path: Path, factory_code: str) -> tuple[pd.Series, pd.DataFrame, dict]:
|
||||
df, cols, _ = read_csv_with_encoding(csv_path, required={"工厂中文名", "工厂英文名", "工厂平均磨合系数", "最小误差"})
|
||||
row = df.loc[df[cols["工厂英文名"]].astype(str).str.strip() == factory_code]
|
||||
if row.empty:
|
||||
raise ValueError(f"在 {csv_path} 中找不到工厂英文名: {factory_code}")
|
||||
return row.iloc[0], df, cols
|
||||
row = _match_factory_row(df, cols, factory_code)
|
||||
return row, df, cols
|
||||
|
||||
|
||||
def _csv_lock_path(csv_path: Path) -> Path:
|
||||
@@ -64,16 +76,14 @@ def update_factory_csv(csv_path: Path, factory_code: str, new_factor: float, new
|
||||
fd = _acquire_lock(lock_path)
|
||||
try:
|
||||
df, cols, enc = read_csv_with_encoding(csv_path, required={"工厂中文名", "工厂英文名", "工厂平均磨合系数", "最小误差"})
|
||||
mask = df[cols["工厂英文名"]].astype(str).str.strip() == factory_code
|
||||
if not mask.any():
|
||||
raise ValueError(f"在 {csv_path} 中找不到工厂英文名: {factory_code}")
|
||||
row = _match_factory_row(df, cols, factory_code)
|
||||
mask = df.index == row.name
|
||||
df.loc[mask, cols["工厂平均磨合系数"]] = float(new_factor)
|
||||
df.loc[mask, cols["最小误差"]] = float(new_error)
|
||||
df.to_csv(csv_path, index=False, encoding=enc)
|
||||
finally:
|
||||
_release_lock(lock_path, fd)
|
||||
|
||||
|
||||
def update_production_line_csv(csv_path: Path, factory_name_cn: str, line_ids: List[str], best_genes: List[float]) -> None:
|
||||
lock_path = _csv_lock_path(csv_path)
|
||||
fd = _acquire_lock(lock_path)
|
||||
@@ -105,7 +115,7 @@ def evaluate(factory_code: str, line_ids: List[str], genes: List[float]) -> floa
|
||||
model.line_factor[lid] = float(val)
|
||||
while model.running:
|
||||
model.step()
|
||||
return model.mean_abs_error
|
||||
return model.error
|
||||
|
||||
|
||||
def mutate(genes: List[float]) -> List[float]:
|
||||
|
||||
Reference in New Issue
Block a user