Finalize SQLite defaults and refresh calibration artifacts
This commit is contained in:
@@ -16,6 +16,7 @@ from src.analysis.probability_snapshot_archive import ( # noqa: E402
|
||||
load_snapshot_rows_for_day,
|
||||
)
|
||||
from src.database.runtime_state import STATE_STORAGE_FILE, get_state_storage_mode # noqa: E402
|
||||
from scripts.fit_probability_calibration import _default_history_arg # noqa: E402
|
||||
|
||||
|
||||
def _load_daily_records(path: Path) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||
@@ -53,8 +54,8 @@ def main() -> int:
|
||||
)
|
||||
parser.add_argument(
|
||||
"--history-file",
|
||||
default=str(Path("data") / "daily_records.json"),
|
||||
help="Path to daily_records.json",
|
||||
default=_default_history_arg(),
|
||||
help="Optional legacy daily_records.json path. In sqlite mode this defaults to the runtime database.",
|
||||
)
|
||||
parser.add_argument("--city", help="Optional city filter, e.g. ankara")
|
||||
parser.add_argument("--date", help="Optional YYYY-MM-DD filter")
|
||||
@@ -70,8 +71,8 @@ def main() -> int:
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
history_path = Path(args.history_file)
|
||||
data = _load_daily_records(history_path)
|
||||
history_path = Path(args.history_file) if args.history_file else None
|
||||
data = _load_daily_records(history_path or Path())
|
||||
model_name = str(args.model or "").strip()
|
||||
city_filter = str(args.city or "").strip().lower() or None
|
||||
date_filter = str(args.date or "").strip() or None
|
||||
@@ -133,8 +134,8 @@ def main() -> int:
|
||||
if changed:
|
||||
previous_mode = get_state_storage_mode()
|
||||
# Reuse existing save path semantics. In sqlite-only mode, save_history would skip file write.
|
||||
save_history(str(history_path), data)
|
||||
if previous_mode == STATE_STORAGE_FILE and not history_path.exists():
|
||||
save_history(str(history_path or ""), data)
|
||||
if previous_mode == STATE_STORAGE_FILE and (history_path is None or not history_path.exists()):
|
||||
raise FileNotFoundError(history_path)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -13,6 +13,7 @@ from src.analysis.probability_calibration import ( # noqa: E402
|
||||
apply_probability_calibration,
|
||||
build_probability_features,
|
||||
)
|
||||
from scripts.fit_probability_calibration import _default_history_arg # noqa: E402
|
||||
|
||||
|
||||
def _sample_to_features(sample):
|
||||
@@ -44,7 +45,7 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="Backfill shadow probability snapshots into daily records.")
|
||||
parser.add_argument(
|
||||
"--history-file",
|
||||
default=os.path.join(PROJECT_ROOT, "data", "daily_records.json"),
|
||||
default=_default_history_arg(),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--training-samples",
|
||||
|
||||
@@ -9,6 +9,7 @@ if PROJECT_ROOT not in sys.path:
|
||||
|
||||
from src.analysis.deb_algorithm import load_history, reconcile_recent_actual_highs, save_history # noqa: E402
|
||||
from src.data_collection.city_registry import CITY_REGISTRY # noqa: E402
|
||||
from scripts.fit_probability_calibration import _default_history_arg # noqa: E402
|
||||
|
||||
|
||||
def _target_dates(city_info: dict, lookback_days: int) -> list[str]:
|
||||
@@ -50,7 +51,7 @@ def main() -> None:
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
history_file = os.path.join(PROJECT_ROOT, "data", "daily_records.json")
|
||||
history_file = _default_history_arg() or ""
|
||||
data = load_history(history_file)
|
||||
|
||||
selected = {str(item).strip().lower() for item in args.cities if str(item).strip()}
|
||||
|
||||
@@ -11,6 +11,7 @@ if PROJECT_ROOT not in sys.path:
|
||||
|
||||
from src.analysis.deb_algorithm import load_history # noqa: E402
|
||||
from src.analysis.settlement_rounding import apply_city_settlement # noqa: E402
|
||||
from scripts.fit_probability_calibration import _default_history_arg # noqa: E402
|
||||
|
||||
|
||||
def _sf(value):
|
||||
@@ -112,7 +113,7 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="Build live shadow probability report from daily records.")
|
||||
parser.add_argument(
|
||||
"--history-file",
|
||||
default=os.path.join(PROJECT_ROOT, "data", "daily_records.json"),
|
||||
default=_default_history_arg(),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
|
||||
@@ -16,6 +16,7 @@ from src.analysis.probability_calibration import ( # noqa: E402
|
||||
)
|
||||
from src.analysis.settlement_rounding import apply_city_settlement # noqa: E402
|
||||
from scripts.fit_probability_calibration import ( # noqa: E402
|
||||
_default_history_arg,
|
||||
_extract_samples,
|
||||
_load_json_if_exists,
|
||||
)
|
||||
@@ -61,7 +62,7 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="Evaluate legacy vs EMOS probability calibration.")
|
||||
parser.add_argument(
|
||||
"--history-file",
|
||||
default=os.path.join(PROJECT_ROOT, "data", "daily_records.json"),
|
||||
default=_default_history_arg(),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--settlement-history",
|
||||
|
||||
@@ -8,6 +8,8 @@ if PROJECT_ROOT not in sys.path:
|
||||
sys.path.insert(0, PROJECT_ROOT)
|
||||
|
||||
from scripts.fit_probability_calibration import ( # noqa: E402
|
||||
_default_history_arg,
|
||||
_default_snapshot_arg,
|
||||
_extract_samples,
|
||||
_load_history_with_fallback,
|
||||
_load_json_if_exists,
|
||||
@@ -19,7 +21,7 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="Export normalized probability calibration training samples.")
|
||||
parser.add_argument(
|
||||
"--history-file",
|
||||
default=os.path.join(PROJECT_ROOT, "data", "daily_records.json"),
|
||||
default=_default_history_arg(),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--settlement-history",
|
||||
@@ -41,7 +43,7 @@ def main():
|
||||
)
|
||||
parser.add_argument(
|
||||
"--snapshot-file",
|
||||
default=os.path.join(PROJECT_ROOT, "data", "probability_training_snapshots.jsonl"),
|
||||
default=_default_snapshot_arg(),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from src.analysis.probability_calibration import ( # noqa: E402
|
||||
from src.analysis.deb_algorithm import load_history # noqa: E402
|
||||
from src.database.runtime_state import ( # noqa: E402
|
||||
ProbabilitySnapshotRepository,
|
||||
STATE_STORAGE_FILE,
|
||||
STATE_STORAGE_SQLITE,
|
||||
get_state_storage_mode,
|
||||
)
|
||||
@@ -38,6 +39,22 @@ def _load_json_if_exists(path):
|
||||
return data if isinstance(data, dict) else {}
|
||||
|
||||
|
||||
def _legacy_history_path():
|
||||
return os.path.join(PROJECT_ROOT, "data", "daily_records.json")
|
||||
|
||||
|
||||
def _legacy_snapshot_path():
|
||||
return os.path.join(PROJECT_ROOT, "data", "probability_training_snapshots.jsonl")
|
||||
|
||||
|
||||
def _default_history_arg():
|
||||
return _legacy_history_path() if get_state_storage_mode() == STATE_STORAGE_FILE else None
|
||||
|
||||
|
||||
def _default_snapshot_arg():
|
||||
return _legacy_snapshot_path() if get_state_storage_mode() == STATE_STORAGE_FILE else None
|
||||
|
||||
|
||||
def _load_history_with_fallback(path):
|
||||
data = load_history(path)
|
||||
if data:
|
||||
@@ -253,8 +270,8 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="Fit PolyWeather probability calibration parameters.")
|
||||
parser.add_argument(
|
||||
"--history-file",
|
||||
default=os.path.join(PROJECT_ROOT, "data", "daily_records.json"),
|
||||
help="Path to the historical daily_records.json file.",
|
||||
default=_default_history_arg(),
|
||||
help="Optional legacy daily_records.json path. In sqlite mode this defaults to the runtime database.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
@@ -273,8 +290,8 @@ def main():
|
||||
)
|
||||
parser.add_argument(
|
||||
"--snapshot-file",
|
||||
default=os.path.join(PROJECT_ROOT, "data", "probability_training_snapshots.jsonl"),
|
||||
help="Optional JSONL file with archived probability snapshots.",
|
||||
default=_default_snapshot_arg(),
|
||||
help="Optional legacy JSONL snapshot archive path. In sqlite mode this defaults to the runtime database.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version",
|
||||
|
||||
Reference in New Issue
Block a user