feat(application): integrate measured-load ingestion training and planner source
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
import joblib
|
||||
|
||||
MODEL_DIR = "/app/data/models"
|
||||
|
||||
|
||||
def model_path(aid, forecast_id):
|
||||
os.makedirs(MODEL_DIR, exist_ok=True)
|
||||
return os.path.join(MODEL_DIR, f"forecast_var_{forecast_id}_{aid}.pkl")
|
||||
|
||||
|
||||
def save_model(aid, forecast_id, artifact):
|
||||
path = model_path(aid, forecast_id)
|
||||
tmp_path = f"{path}.tmp.{os.getpid()}"
|
||||
try:
|
||||
joblib.dump(artifact, tmp_path)
|
||||
os.replace(tmp_path, path)
|
||||
finally:
|
||||
if os.path.exists(tmp_path):
|
||||
os.remove(tmp_path)
|
||||
return path
|
||||
|
||||
|
||||
def load_model(aid, forecast_id):
|
||||
path = model_path(aid, forecast_id)
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
try:
|
||||
return joblib.load(path)
|
||||
except Exception as exc:
|
||||
print(f"Modell {path} konnte nicht geladen werden: {exc}")
|
||||
return None
|
||||
Reference in New Issue
Block a user