Spaces:
Runtime error
Runtime error
Upload runtime.py
Browse files1260 unmodified lines1261126212631264126412651266126712681269127039 unmodified lines1310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134717 unmodified lines1365136613671333133413351336133713381339134013411342134313441345134613681369137013713 unmodified lines1375137613771378137913801381138213831384138513861387138813891390126 unmodified lines151715181519148815201521152214 unmodified lines153715381539150915401541154215431260 unmodified lines _file_cache_key(TOMORROW_PREDICTION_HISTORY_PATH), ) with _dashboard_payload_lock: return copy.deepcopy(_dashboard_payload_cached(key)) payload = copy.deepcopy(_dashboard_payload_cached(key)) # Always rebuild track record (fresh Yahoo daily + calendar window), never serve from LRU cache. payload["charts"]["track_record"] = build_prediction_track_record(sessions=10) return payload
def warm_dashboard_payload_cache() -> None:39 unmodified lines return indexed
def _load_track_record_daily_rows() -> pd.DataFrame: """Daily OHLC for track record: live Yahoo pull merged over parquet history.""" frames: list[pd.DataFrame] = [] if NIFTY_1D_PATH.exists(): try: frames.append(pd.read_parquet(NIFTY_1D_PATH)) except Exception: pass try: yahoo_daily = fetch_yahoo_daily(period="3mo") if not yahoo_daily.empty: frames.append(yahoo_daily) try: append_parquet_rows(NIFTY_1D_PATH, yahoo_daily, ["date"]) except Exception: pass except Exception: pass
if not frames: return pd.DataFrame()
combined = pd.concat(frames, ignore_index=True) combined["date"] = pd.to_datetime(combined["date"], errors="coerce").dt.normalize() combined = combined.dropna(subset=["date"]).sort_values("date") combined = combined.drop_duplicates(subset=["date"], keep="last") combined = combined[ combined["close"].map(lambda value: np.isfinite(float(value)) if pd.notna(value) else False) ].copy() return combined.reset_index(drop=True)
def _rolling_tomorrow_prediction( input_day: date, daily_rows: pd.DataFrame,17 unmodified lines fallback_prob = float(summary.get("latest_forecast_prob_up", 0.49900560447008563)) forecaster_by_target = _load_forecaster_predictions_by_target()
end_session = _track_record_end_session() latest_daily = latest_parquet_date(NIFTY_1D_PATH) if latest_daily is None or latest_daily < end_session: try: refresh_daily_data() except Exception: pass
daily_rows = pd.read_parquet(NIFTY_1D_PATH) daily_rows["date"] = pd.to_datetime(daily_rows["date"], errors="coerce").dt.normalize() daily_rows = daily_rows.dropna(subset=["date"]).sort_values("date") daily_rows = daily_rows[ daily_rows["close"].map(lambda value: np.isfinite(float(value)) if pd.notna(value) else False) ].copy() daily_rows = _load_track_record_daily_rows() if daily_rows.empty: return []
3 unmodified lines if pd.notna(row["close"]) and np.isfinite(float(row["close"])) }
end_session = _track_record_end_session() available_through = max( (day for day in closes_by_date if day <= end_session), default=None, ) if available_through is None: return [] if available_through < end_session: end_session = available_through
session_dates = last_n_trading_sessions(end_session, sessions)
records: list[dict[str, Any]] = []126 unmodified lines "total_test_days": int(tomorrow_summary.get("n_test") or len(tomorrow_test) or 0), "models": model_metrics, } track_record = build_prediction_track_record(sessions=10) return { "latest": t5_latest, "tomorrow_latest": tomorrow_latest,14 unmodified lines "tomorrow_recent_predictions": _json_ready_frame(tomorrow_recent), "tomorrow_history_predictions": _json_ready_frame(tomorrow_history.tail(80)), "tplus1_recent_predictions": _json_ready_frame(tplus1_test.tail(40)), "track_record": track_record, "track_record": [], }, "data_status": { "nifty_1m_rows": int(len(pd.read_parquet(NIFTY_1M_PATH, columns=["date"]))),runtime.py+48-17