Spaces:
Sleeping
Sleeping
File size: 1,145 Bytes
798c69b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import json
from datetime import datetime, timezone
from pathlib import Path
from src.shared.config import PROJECT_ROOT
DEFAULT_INFERENCE_LOG_PATH = PROJECT_ROOT / "logs" / "inference_requests.jsonl"
def build_inference_log_entry(
*,
store: int,
start_date: str,
forecast_days: int,
promo: int,
state_holiday: str,
school_holiday: int,
model_version: str,
latency_ms: float,
) -> dict[str, object]:
"""Builds a single structured inference log event."""
return {
"timestamp_utc": datetime.now(timezone.utc).isoformat(),
"store": store,
"start_date": start_date,
"forecast_days": forecast_days,
"promo": promo,
"state_holiday": state_holiday,
"school_holiday": school_holiday,
"model_version": model_version,
"latency_ms": round(latency_ms, 3),
}
def append_jsonl_record(path: Path, payload: dict[str, object]) -> None:
"""Appends a JSON line to the configured log file."""
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("a", encoding="utf-8") as f:
f.write(json.dumps(payload) + "\n")
|