Spaces:
Sleeping
Sleeping
Upload 42 files
Browse filesFiles changed (4)
12input_date,target_date,prediction,prob_up,confidence,threshold,model_name,source_model,validation_accuracy,test_accuracy2026-05-26,2026-05-27,DOWN,0.4892079705003583,0.5107920294996418,0.543,nifty_tomorrow_direction_model,tuned_daily_forest_single,0.5780141843971631,0.618279569892473112input_date,target_date,prediction,prob_up,confidence,threshold,model_name,source_model,validation_accuracy,test_accuracy2026-05-27,2026-05-29,DOWN,0.503279589082978,0.503279589082978,0.543,nifty_tomorrow_direction_model,tuned_daily_forest_single,0.5780141843971631,0.6182795698924731
24 unmodified lines2526272829303132333435363724 unmodified lines"valid_end": "2025-08-17","test_start": "2025-08-18","test_end": "2026-05-20","latest_forecast_date": "2026-05-26","latest_forecast_for": "next trading session 2026-05-27","latest_forecast_prob_up": 0.4892079705003583,"latest_forecast_signal": "DOWN","feature_count": 301,"model_name": "nifty_tomorrow_direction_model","source_model": "tuned_daily_forest_single","target": "next trading session NIFTY 50 direction","latest_target_date": "2026-05-27"}24 unmodified lines2526272829303132333435363724 unmodified lines"valid_end": "2025-08-17","test_start": "2025-08-18","test_end": "2026-05-20","latest_forecast_date": "2026-05-27","latest_forecast_for": "next trading session 2026-05-29","latest_forecast_prob_up": 0.503279589082978,"latest_forecast_signal": "DOWN","feature_count": 301,"model_name": "nifty_tomorrow_direction_model","source_model": "tuned_daily_forest_single","target": "next trading session NIFTY 50 direction","latest_target_date": "2026-05-29"}
577 unmodified lines578579580581582583584585586587588589590591252 unmodified lines844845846847848849850851852853854855856857858859860350 unmodified lines12111212121312141215121627 unmodified lines1244124512461247124812493 unmodified lines12531254125512561257125812591260126112621 unmodified line126412651266126712681269127016 unmodified lines128712881289129012911292577 unmodified lines}def latest_tomorrow_prediction() -> dict[str, Any]:if TOMORROW_LATEST_PATH.exists():row = pd.read_csv(TOMORROW_LATEST_PATH).iloc[-1].to_dict()return {k: (None if pd.isna(v) else v) for k, v in row.items()}summary = load_tomorrow_summary()return {"input_date": summary.get("latest_forecast_date"),"target_date": None,"prediction": summary.get("latest_forecast_signal"),"prob_up": summary.get("latest_forecast_prob_up"),"confidence": None,252 unmodified lines}pd.DataFrame([row]).to_csv(TOMORROW_LATEST_PATH, index=False)summary = dict(summary)summary.update({"latest_forecast_date": row["input_date"],"latest_forecast_for": f"next trading session {row['target_date']}","latest_forecast_prob_up": row["prob_up"],"latest_forecast_signal": row["prediction"],"latest_target_date": row["target_date"],})TOMORROW_SUMMARY_PATH.write_text(json.dumps(summary, indent=2), encoding="utf-8")return rowdef _json_ready_frame(df: pd.DataFrame, limit: int | None = None) -> list[dict[str, Any]]:350 unmodified linesreturn None if pd.isna(value) else value.date()def expected_completed_daily_date(now: datetime | None = None) -> date:now = now or datetime.now(IST)if is_trading_day(now.date()) and now.time() < CLOSE_REFRESH_READY:27 unmodified lineslatest_daily = latest_parquet_date(NIFTY_1D_PATH)latest_minutes = latest_parquet_date(NIFTY_1M_PATH)latest_t5 = latest_prediction_input_date(LATEST_PATH)latest_tplus1 = latest_prediction_input_date(TPLUS1_LATEST_PATH)return {"server_time_ist": now.isoformat(),3 unmodified lines"latest_daily_date": latest_daily.isoformat() if latest_daily else None,"latest_minute_date": latest_minutes.isoformat() if latest_minutes else None,"latest_t5_date": latest_t5.isoformat() if latest_t5 else None,"latest_tplus1_date": latest_tplus1.isoformat() if latest_tplus1 else None,"daily_stale": is_stale(latest_daily, expected_daily),"minutes_stale": is_stale(latest_minutes, expected_minutes),"t5_stale": is_stale(latest_t5, expected_minutes),"tplus1_stale": is_stale(latest_tplus1, expected_tplus1),}1 unmodified linedef refresh_stale_data_once(now: datetime | None = None) -> dict[str, Any]:now = now or datetime.now(IST)status = stale_data_status(now)if not any(status[key] for key in ("daily_stale", "minutes_stale", "t5_stale", "tplus1_stale")):return {"status": "fresh", **status, "actions": []}if not _stale_refresh_lock.acquire(blocking=False):return {"status": "skipped", "reason": "stale refresh already running", **status, "actions": []}16 unmodified linesoutcomes = update_opening_outcomes_from_daily()actions.append({"name": "daily", **daily_info})actions.append({"name": "opening_outcomes", **outcomes})try:tomorrow = refresh_tomorrow_prediction(session_date=date.fromisoformat(status["expected_daily_date"]))actions.append({"name": "tomorrow_prediction", "input_date": tomorrow.get("input_date")})577 unmodified lines578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611252 unmodified lines864865866867868869870871872873874875876877878879880881350 unmodified lines12321233123412351236123712381239124012411242124312441245124627 unmodified lines12741275127612771278127912803 unmodified lines1284128512861287128812891290129112921293129412951 unmodified line129712981299130013011302130316 unmodified lines13201321132213231324132513261327577 unmodified lines}def latest_tomorrow_prediction() -> dict[str, Any]:latest_daily = latest_parquet_date(NIFTY_1D_PATH)if TOMORROW_LATEST_PATH.exists():row = pd.read_csv(TOMORROW_LATEST_PATH).iloc[-1].to_dict()cleaned = {k: (None if pd.isna(v) else v) for k, v in row.items()}try:input_day = date.fromisoformat(str(cleaned.get("input_date"))[:10])except Exception:input_day = Noneif latest_daily is not None and (input_day is None or input_day < latest_daily):try:return refresh_tomorrow_prediction(session_date=latest_daily)except Exception:return cleanedreturn cleanedsummary = load_tomorrow_summary()try:summary_input_day = date.fromisoformat(str(summary.get("latest_forecast_date"))[:10])except Exception:summary_input_day = Noneif latest_daily is not None and (summary_input_day is None or summary_input_day < latest_daily):try:return refresh_tomorrow_prediction(session_date=latest_daily)except Exception:passreturn {"input_date": summary.get("latest_forecast_date"),"target_date": None,"prediction": summary.get("latest_forecast_signal"),"prob_up": summary.get("latest_forecast_prob_up"),"confidence": None,252 unmodified lines}pd.DataFrame([row]).to_csv(TOMORROW_LATEST_PATH, index=False)summary = dict(summary)summary.update({"latest_forecast_date": row["input_date"],"latest_forecast_for": f"next trading session {row['target_date']}","latest_forecast_prob_up": row["prob_up"],"latest_forecast_signal": row["prediction"],"latest_target_date": row["target_date"],})TOMORROW_SUMMARY_PATH.write_text(json.dumps(summary, indent=2), encoding="utf-8")clear_dashboard_payload_cache()return rowdef _json_ready_frame(df: pd.DataFrame, limit: int | None = None) -> list[dict[str, Any]]:350 unmodified linesreturn None if pd.isna(value) else value.date()def latest_tomorrow_input_date() -> date | None:try:latest = latest_tomorrow_prediction()raw = latest.get("input_date")return date.fromisoformat(str(raw)[:10]) if raw else Noneexcept Exception:return Nonedef expected_completed_daily_date(now: datetime | None = None) -> date:now = now or datetime.now(IST)if is_trading_day(now.date()) and now.time() < CLOSE_REFRESH_READY:27 unmodified lineslatest_daily = latest_parquet_date(NIFTY_1D_PATH)latest_minutes = latest_parquet_date(NIFTY_1M_PATH)latest_t5 = latest_prediction_input_date(LATEST_PATH)latest_tomorrow = latest_tomorrow_input_date()latest_tplus1 = latest_prediction_input_date(TPLUS1_LATEST_PATH)return {"server_time_ist": now.isoformat(),3 unmodified lines"latest_daily_date": latest_daily.isoformat() if latest_daily else None,"latest_minute_date": latest_minutes.isoformat() if latest_minutes else None,"latest_t5_date": latest_t5.isoformat() if latest_t5 else None,"latest_tomorrow_date": latest_tomorrow.isoformat() if latest_tomorrow else None,"latest_tplus1_date": latest_tplus1.isoformat() if latest_tplus1 else None,"daily_stale": is_stale(latest_daily, expected_daily),"minutes_stale": is_stale(latest_minutes, expected_minutes),"t5_stale": is_stale(latest_t5, expected_minutes),"tomorrow_stale": is_stale(latest_tomorrow, expected_daily),"tplus1_stale": is_stale(latest_tplus1, expected_tplus1),}1 unmodified linedef refresh_stale_data_once(now: datetime | None = None) -> dict[str, Any]:now = now or datetime.now(IST)status = stale_data_status(now)if not any(status[key] for key in ("daily_stale", "minutes_stale", "t5_stale", "tomorrow_stale", "tplus1_stale")):return {"status": "fresh", **status, "actions": []}if not _stale_refresh_lock.acquire(blocking=False):return {"status": "skipped", "reason": "stale refresh already running", **status, "actions": []}16 unmodified linesoutcomes = update_opening_outcomes_from_daily()actions.append({"name": "daily", **daily_info})actions.append({"name": "opening_outcomes", **outcomes})if status["daily_stale"] or status["tomorrow_stale"]:try:tomorrow = refresh_tomorrow_prediction(session_date=date.fromisoformat(status["expected_daily_date"]))actions.append({"name": "tomorrow_prediction", "input_date": tomorrow.get("input_date")})
models/tomorrow_latest_prediction.csv+1-1
models/tomorrow_summary.json+4-4
nifty_backend/__pycache__/runtime.cpython-311.pyc
nifty_backend/runtime.py+51-16