Spaces:
Sleeping
Sleeping
fix-dashboard-ui-backend
Browse filesFiles changed (11)
- .hfignoreAdded+9
- __pycache__/app.cpython-311.pyc
- __pycache__/kotak_neo.cpython-311.pyc
- data/nifty50_1d.parquet+2-2
- data/nifty50_1m.parquet+2-2
- data/opening_direction_training_dataset.parquet+2-2
- kotak_neo.py+1-1
- models/latest_prediction.csv+1-1
- models/yahoo_history_cache.sqlite3+2-2
- nifty_backend/__pycache__/runtime.cpython-311.pyc+2-2
- nifty_backend/runtime.py+130
123456789__pycache__/*.pyc.pytest_cache/.mypy_cache/.ruff_cache/.venv/venv/.env*.log123version https://git-lfs.github.com/spec/v1oid sha256:4d0830f9d3cfa91f02ce717b556983beb12f897bc537a623c67e38f22ce05cafsize 78366123version https://git-lfs.github.com/spec/v1oid sha256:e9a3425f3bf8271fb9002f3f770dc8607e401e9e8e5b0066495fe73092210242size 78452
123version https://git-lfs.github.com/spec/v1oid sha256:b5d6022df273daa1f020676214ec35536426fd84f2d7efb669797287e27ffa2dsize 18589635123version https://git-lfs.github.com/spec/v1oid sha256:9df0c2b2820487db987459070243b498551961894fc49bb55f467d1b0466f2f2size 18609051
123version https://git-lfs.github.com/spec/v1oid sha256:722c8225451abcb49463d2a57354bc0c9b5eb519f31a25fa3c5242adc4dbbadasize 4463631123version https://git-lfs.github.com/spec/v1oid sha256:6fa5d8cf0e098429ce3b3c4739b498a5bed3884cd1dbe6c4fda97b4600a26474size 4464130
438 unmodified lines439440441442443444445438 unmodified lines"status": self.status(),"as_of": _utc_now_iso(),"neo_behavior": {"holdings_note": "Kotak Neo shows CNC delivery buys in Positions on trade day and in Holdings/T1 from the next trading day.","trade_history_note": "Kotak Neo trade history availability is limited by Neo's own order and portfolio tracker behavior.",},"summary": {438 unmodified lines439440441442443444445438 unmodified lines"status": self.status(),"as_of": _utc_now_iso(),"neo_behavior": {"holdings_note": "","trade_history_note": "Kotak Neo trade history availability is limited by Neo's own order and portfolio tracker behavior.",},"summary": {
12input_date,first5_start,first5_end,prediction,prob_up,confidence,threshold,model_name,is_overridden2026-05-27,2026-05-27 09:15:00,2026-05-27 09:19:00,UP,0.6970470349448922,0.7720470349448922,0.425,blend_extra_trees_tight_logit_overlay,False12input_date,first5_start,first5_end,prediction,prob_up,confidence,threshold,model_name,is_overridden2026-06-02,2026-06-02 09:15:00,2026-06-02 09:19:00,DOWN,0.6609583467127472,0.7359583467127473,0.425,blend_extra_trees_tight_logit_overlay,True
123version https://git-lfs.github.com/spec/v1oid sha256:534853b3b5984c2c4128ed073412f090ce96d6cb7a9da4aaa98a20482a2a4bffsize 155648123version https://git-lfs.github.com/spec/v1oid sha256:1dcb91ddef71b32d679585287872891cb4f4ddc992b8d3c3659989829323a454size 225280
123version https://git-lfs.github.com/spec/v1oid sha256:758fbd828aed6b736b14e5a2a6834ef5559a3bf92b1f3e607f375249240ea6cbsize 104535123version https://git-lfs.github.com/spec/v1oid sha256:89f2a00f920ffc636fbdd9b8b9b0fb6c6cbe955a5de208b7879183571d861e84size 112925
63 unmodified lines6465666768691024 unmodified lines10941095109610971098109997 unmodified lines119711981199120012011202105 unmodified lines1308130913101311131213135 unmodified lines13191320132113221323132463 unmodified linesREFRESH_READY = "ready"REFRESH_FAILED = "failed"REFRESH_NORMAL = "normal"DECISION_OVERLAYS = [{1024 unmodified lines_file_cache_key(OPENING_DATASET_PATH),_file_cache_key(MODEL_DIR / "candidate_results.csv"),_file_cache_key(NIFTY_1M_PATH),)with _dashboard_payload_lock:return copy.deepcopy(_dashboard_payload_cached(key))97 unmodified lines"latest": t5_latest,"tomorrow_latest": tomorrow_latest,"tplus1_latest": tplus1_latest,"metrics": metrics,"summary": summary,"tomorrow_summary": tomorrow_summary,105 unmodified lines}def refresh_market_close_data(session_date: date | None = None) -> dict[str, Any]:now = datetime.now(IST)session_date = session_date or now.date()5 unmodified linesminutes = fetch_yahoo_minutes(period="7d")minute_frame = append_parquet_rows(NIFTY_1M_PATH, minutes, ["date"])daily_info = refresh_daily_data()t5_prediction = refresh_first5_prediction(session_date=session_date, minutes=minutes)tplus1_prediction = refresh_tplus1_prediction(session_date=session_date)outcomes = update_opening_outcomes_from_daily()63 unmodified lines646566676869701024 unmodified lines109510961097109810991100110197 unmodified lines1199120012011202120312041205105 unmodified lines131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714385 unmodified lines1444144514461447144814491450145114521453145463 unmodified linesREFRESH_READY = "ready"REFRESH_FAILED = "failed"REFRESH_NORMAL = "normal"LIVE_ACCURACY_PATH = MODEL_DIR / "live_accuracy.json"DECISION_OVERLAYS = [{1024 unmodified lines_file_cache_key(OPENING_DATASET_PATH),_file_cache_key(MODEL_DIR / "candidate_results.csv"),_file_cache_key(NIFTY_1M_PATH),_file_cache_key(LIVE_ACCURACY_PATH),)with _dashboard_payload_lock:return copy.deepcopy(_dashboard_payload_cached(key))97 unmodified lines"latest": t5_latest,"tomorrow_latest": tomorrow_latest,"tplus1_latest": tplus1_latest,"live_accuracy": load_live_accuracy(),"metrics": metrics,"summary": summary,"tomorrow_summary": tomorrow_summary,105 unmodified lines}def load_live_accuracy() -> dict[str, Any]:"""Load the live accuracy ledger from disk."""if LIVE_ACCURACY_PATH.exists():try:return json.loads(LIVE_ACCURACY_PATH.read_text(encoding="utf-8"))except Exception:passreturn {"tomorrow": {"entries": [], "accuracy": None, "total": 0, "correct_count": 0},"t5": {"entries": [], "accuracy": None, "total": 0, "correct_count": 0},"tplus1": {"entries": [], "accuracy": None, "total": 0, "correct_count": 0},}def save_live_accuracy(data: dict[str, Any]) -> None:"""Persist the live accuracy ledger to disk."""LIVE_ACCURACY_PATH.write_text(json.dumps(data, indent=2), encoding="utf-8")def update_live_accuracy(session_date: date) -> dict[str, Any]:"""Score today's predictions against actual outcomes and update the ledger.Must be called AFTER refresh_daily_data() (so today's close is available)but BEFORE refresh_first5_prediction / refresh_tplus1_prediction /refresh_tomorrow_prediction (so the CSV files still hold the predictionswe want to score)."""ledger = load_live_accuracy()daily = pd.read_parquet(NIFTY_1D_PATH)daily["_date"] = pd.to_datetime(daily["date"], errors="coerce").dt.normalize()today_rows = daily[daily["_date"].dt.date == session_date]if today_rows.empty:return ledgerday_open = float(today_rows.iloc[-1]["open"])day_close = float(today_rows.iloc[-1]["close"])if not (np.isfinite(day_open) and np.isfinite(day_close) and day_open != 0):return ledgeractual_close_gt_open = "UP" if day_close > day_open else "DOWN"session_iso = session_date.isoformat()# --- T+5: today's 9:20 AM prediction vs close > open ---logged_t5 = {e["date"] for e in ledger["t5"]["entries"]}if session_iso not in logged_t5 and LATEST_PATH.exists():try:t5_row = pd.read_csv(LATEST_PATH).iloc[-1].to_dict()if str(t5_row.get("input_date", ""))[:10] == session_iso:pred = str(t5_row.get("prediction", "")).upper()if pred in ("UP", "DOWN"):ledger["t5"]["entries"].append({"date": session_iso,"prediction": pred,"actual": actual_close_gt_open,"correct": pred == actual_close_gt_open,})except Exception:pass# --- Tomorrow: yesterday's prediction targeting today vs close > open ---logged_tom = {e["date"] for e in ledger["tomorrow"]["entries"]}if session_iso not in logged_tom and TOMORROW_LATEST_PATH.exists():try:tom_row = pd.read_csv(TOMORROW_LATEST_PATH).iloc[-1].to_dict()if str(tom_row.get("target_date", ""))[:10] == session_iso:pred = str(tom_row.get("prediction", "")).upper()if pred in ("UP", "DOWN"):ledger["tomorrow"]["entries"].append({"date": session_iso,"prediction": pred,"actual": actual_close_gt_open,"correct": pred == actual_close_gt_open,})except Exception:pass# --- T+1: yesterday's 14:20 prediction targeting today ---# T+1 target: today's close > yesterday's 14:20 closelogged_t1 = {e["date"] for e in ledger["tplus1"]["entries"]}if session_iso not in logged_t1 and TPLUS1_LATEST_PATH.exists():try:t1_row = pd.read_csv(TPLUS1_LATEST_PATH).iloc[-1].to_dict()if str(t1_row.get("target_date", ""))[:10] == session_iso:pred = str(t1_row.get("prediction", "")).upper()input_date_str = str(t1_row.get("input_date", ""))[:10]input_day = date.fromisoformat(input_date_str)# Read the 14:20 close from minute data for the input sessionminute = pd.read_parquet(NIFTY_1M_PATH, columns=["date", "close"])minute["dt"] = pd.to_datetime(minute["date"], errors="coerce")minute = minute.dropna(subset=["dt"])minute["session_date"] = minute["dt"].dt.normalize()minute["time_str"] = minute["dt"].dt.strftime("%H:%M")window = minute[(minute["session_date"].dt.date == input_day)& (minute["time_str"] >= "14:00")& (minute["time_str"] <= "14:20")].sort_values("dt")if not window.empty and pred in ("UP", "DOWN"):w_close = float(window.iloc[-1]["close"])t1_actual = "UP" if day_close > w_close else "DOWN"ledger["tplus1"]["entries"].append({"date": session_iso,"prediction": pred,"actual": t1_actual,"correct": pred == t1_actual,})except Exception:pass# Recompute summary statsfor model_id in ("t5", "tomorrow", "tplus1"):entries = ledger[model_id]["entries"]total = len(entries)correct = sum(1 for e in entries if e.get("correct"))ledger[model_id]["total"] = totalledger[model_id]["correct_count"] = correctledger[model_id]["accuracy"] = correct / total if total > 0 else Nonesave_live_accuracy(ledger)clear_dashboard_payload_cache()return ledgerdef refresh_market_close_data(session_date: date | None = None) -> dict[str, Any]:now = datetime.now(IST)session_date = session_date or now.date()5 unmodified linesminutes = fetch_yahoo_minutes(period="7d")minute_frame = append_parquet_rows(NIFTY_1M_PATH, minutes, ["date"])daily_info = refresh_daily_data()# Score live predictions BEFORE they get overwritten by fresh onestry:update_live_accuracy(session_date)except Exception as exc:print(f"[close-refresh] live accuracy update failed: {exc}", flush=True)t5_prediction = refresh_first5_prediction(session_date=session_date, minutes=minutes)tplus1_prediction = refresh_tplus1_prediction(session_date=session_date)outcomes = update_opening_outcomes_from_daily()
.hfignoreAdded+9
__pycache__/app.cpython-311.pyc
__pycache__/kotak_neo.cpython-311.pyc
data/nifty50_1d.parquet+2-2
data/nifty50_1m.parquet+2-2
data/opening_direction_training_dataset.parquet+2-2
kotak_neo.py+1-1
models/latest_prediction.csv+1-1
models/yahoo_history_cache.sqlite3+2-2
nifty_backend/__pycache__/runtime.cpython-311.pyc+2-2
nifty_backend/runtime.py+130