Jitendra12421 commited on
Commit
2c55aaf
·
verified ·
1 Parent(s): 910e6b7

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -236,6 +236,7 @@ def attach_market_state(payload: dict) -> dict:
236
  # we forcefully load it directly from app.py's relative path.
237
  mfe_summary_fallback = {}
238
  mfe_latest_fallback = {}
 
239
  try:
240
  models_dir = Path(__file__).resolve().parent / "models"
241
  mfe_out = models_dir / "nifty_opening_mfe_regressor" / "outputs"
@@ -244,6 +245,27 @@ def attach_market_state(payload: dict) -> dict:
244
  if (mfe_out / "latest_prediction.csv").exists():
245
  row = pd.read_csv(mfe_out / "latest_prediction.csv").iloc[-1].to_dict()
246
  mfe_latest_fallback = {k: (None if pd.isna(v) else v) for k, v in row.items()}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  except Exception as exc:
248
  print(f"Fallback MFE load failed: {exc}", flush=True)
249
 
@@ -252,6 +274,7 @@ def attach_market_state(payload: dict) -> dict:
252
  tplus1_latest = payload.get("predictions", {}).get("tplus1", {}).get("latest") or payload.get("tplus1_latest") or {}
253
  mfe_latest = payload.get("predictions", {}).get("mfe", {}).get("latest") or mfe_latest_fallback
254
  mfe_summary = payload.get("predictions", {}).get("mfe", {}).get("summary") or mfe_summary_fallback
 
255
  t5_available = bool(state["t5_available"] and t5_latest.get("prediction"))
256
  tplus1_available = bool(state["tplus1_available"] and tplus1_latest.get("prediction"))
257
  tomorrow_available = bool(tomorrow_latest.get("prediction"))
@@ -313,6 +336,7 @@ def attach_market_state(payload: dict) -> dict:
313
  "reason": None if t5_available else state["t5_detail"],
314
  "latest": mfe_latest,
315
  "summary": mfe_summary,
 
316
  },
317
  }
318
  return payload
 
236
  # we forcefully load it directly from app.py's relative path.
237
  mfe_summary_fallback = {}
238
  mfe_latest_fallback = {}
239
+ mfe_history_fallback = []
240
  try:
241
  models_dir = Path(__file__).resolve().parent / "models"
242
  mfe_out = models_dir / "nifty_opening_mfe_regressor" / "outputs"
 
245
  if (mfe_out / "latest_prediction.csv").exists():
246
  row = pd.read_csv(mfe_out / "latest_prediction.csv").iloc[-1].to_dict()
247
  mfe_latest_fallback = {k: (None if pd.isna(v) else v) for k, v in row.items()}
248
+ if (mfe_out / "test_predictions.csv").exists():
249
+ hist_df = pd.read_csv(mfe_out / "test_predictions.csv")
250
+ hist_records = []
251
+ for _, r in hist_df.iterrows():
252
+ try:
253
+ dt = str(r["date"])
254
+ f5c = float(r["first5_close"])
255
+ pred_up = float(r["predicted_up_points"])
256
+ pred_dn = float(r["predicted_down_points"])
257
+ act_hi = float(r["day_high"])
258
+ act_lo = float(r["day_low"])
259
+ hist_records.append({
260
+ "date": dt,
261
+ "actual_high": act_hi,
262
+ "predicted_high": f5c + pred_up,
263
+ "actual_low": act_lo,
264
+ "predicted_low": f5c - pred_dn
265
+ })
266
+ except Exception:
267
+ continue
268
+ mfe_history_fallback = hist_records
269
  except Exception as exc:
270
  print(f"Fallback MFE load failed: {exc}", flush=True)
271
 
 
274
  tplus1_latest = payload.get("predictions", {}).get("tplus1", {}).get("latest") or payload.get("tplus1_latest") or {}
275
  mfe_latest = payload.get("predictions", {}).get("mfe", {}).get("latest") or mfe_latest_fallback
276
  mfe_summary = payload.get("predictions", {}).get("mfe", {}).get("summary") or mfe_summary_fallback
277
+ mfe_history = payload.get("predictions", {}).get("mfe", {}).get("history") or mfe_history_fallback
278
  t5_available = bool(state["t5_available"] and t5_latest.get("prediction"))
279
  tplus1_available = bool(state["tplus1_available"] and tplus1_latest.get("prediction"))
280
  tomorrow_available = bool(tomorrow_latest.get("prediction"))
 
336
  "reason": None if t5_available else state["t5_detail"],
337
  "latest": mfe_latest,
338
  "summary": mfe_summary,
339
+ "history": mfe_history,
340
  },
341
  }
342
  return payload