65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import yaml
|
|
|
|
|
|
ROOT_DIR = Path(__file__).resolve().parents[1]
|
|
CONFIG_PATH = ROOT_DIR / "config" / "mapping.yaml"
|
|
|
|
|
|
@dataclass
|
|
class AppConfig:
|
|
path: Path
|
|
data: dict[str, Any]
|
|
|
|
@classmethod
|
|
def load(cls, path: Path = CONFIG_PATH) -> "AppConfig":
|
|
with path.open("r", encoding="utf-8") as f:
|
|
data = yaml.safe_load(f) or {}
|
|
return cls(path=path, data=data)
|
|
|
|
def save(self) -> None:
|
|
with self.path.open("w", encoding="utf-8") as f:
|
|
yaml.safe_dump(self.data, f, allow_unicode=True, sort_keys=False)
|
|
|
|
@property
|
|
def defaults(self) -> dict[str, str]:
|
|
return self.data.setdefault("defaults", {})
|
|
|
|
@property
|
|
def field_mappings(self) -> dict[str, str]:
|
|
return self.data.setdefault("field_mappings", {})
|
|
|
|
@property
|
|
def dynamic_field_mappings(self) -> dict[str, str]:
|
|
return self.data.setdefault("dynamic_field_mappings", {})
|
|
|
|
@property
|
|
def ignored_fields(self) -> set[str]:
|
|
return set(self.data.setdefault("ignored_fields", []))
|
|
|
|
@property
|
|
def bore_map(self) -> dict[str, dict[str, str]]:
|
|
return self.data.setdefault("bore_map", {})
|
|
|
|
@property
|
|
def deepseek(self) -> dict[str, Any]:
|
|
return self.data.setdefault("deepseek", {})
|
|
|
|
@property
|
|
def template_path(self) -> Path:
|
|
configured = self.data.get("template", {}).get("path", "焊接数据导入模版.xls")
|
|
return ROOT_DIR / configured
|
|
|
|
@property
|
|
def output_sheet(self) -> str:
|
|
return self.data.get("template", {}).get("output_sheet", "Sheet1")
|
|
|
|
@property
|
|
def confidence_threshold(self) -> float:
|
|
return float(self.deepseek.get("confidence_threshold", 0.85))
|