Spaces:
Runtime error
Runtime error
Add model selector for rank history
Browse files805 unmodified lines80680780880981081131 unmodified lines843844845846847848805 unmodified lines_RANK_COLS = [c for c in BASELINE_RANK_HISTORY_COLUMNS if c.endswith("_Rank")]_DAILY_DISPLAY_COLS = ["date", "model"] + _RANK_COLS_WEEKLY_DISPLAY_COLS = ["week", "model"] + _RANK_COLSdef _read_rank_history(path: Path, date_col: str) -> pd.DataFrame:31 unmodified linesreturn _read_rank_history(Path(root_dir) / "baseline_rank_history_weekly.csv", "week")# ---------------------------------------------------------------------------# Forecast snapshot utilities# ---------------------------------------------------------------------------805 unmodified lines80680780880981081181231 unmodified lines844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890805 unmodified lines_RANK_COLS = [c for c in BASELINE_RANK_HISTORY_COLUMNS if c.endswith("_Rank")]_DAILY_DISPLAY_COLS = ["date", "model"] + _RANK_COLS_WEEKLY_DISPLAY_COLS = ["week", "model"] + _RANK_COLS_MONTHLY_DISPLAY_COLS = ["month", "model"] + _RANK_COLSdef _read_rank_history(path: Path, date_col: str) -> pd.DataFrame:31 unmodified linesreturn _read_rank_history(Path(root_dir) / "baseline_rank_history_weekly.csv", "week")def load_baseline_rank_history_monthly(root_dir: str = "results") -> pd.DataFrame:"""Load monthly tracked-model rank history aggregated from daily history."""daily_path = Path(root_dir) / "baseline_rank_history_daily.csv"if not daily_path.exists():daily_path = Path(root_dir) / "baseline_rank_history.csv"if not daily_path.exists():return pd.DataFrame(columns=_MONTHLY_DISPLAY_COLS)try:df = pd.read_csv(daily_path)except Exception:return pd.DataFrame(columns=_MONTHLY_DISPLAY_COLS)if "date" not in df.columns:return pd.DataFrame(columns=_MONTHLY_DISPLAY_COLS)df["date"] = pd.to_datetime(df["date"], errors="coerce")df = df.dropna(subset=["date"])if df.empty:return pd.DataFrame(columns=_MONTHLY_DISPLAY_COLS)if "model" not in df.columns:df["model"] = ""df["month"] = df["date"].dt.strftime("%Y-%m")for col in _RANK_COLS:if col in df.columns:df[col] = pd.to_numeric(df[col], errors="coerce")present_rank_cols = [col for col in _RANK_COLS if col in df.columns]if present_rank_cols:monthly = (df.groupby(["month", "model"], dropna=False)[present_rank_cols].mean(numeric_only=True).round(3).reset_index())else:monthly = df.loc[:, ["month", "model"]].drop_duplicates()for col in present_rank_cols:monthly[col] = monthly[col].map(format_rank_number)present = [c for c in _MONTHLY_DISPLAY_COLS if c in monthly.columns]return monthly[present].sort_values(["month", "model"]).reset_index(drop=True)# ---------------------------------------------------------------------------# Forecast snapshot utilities# ---------------------------------------------------------------------------
src/utils.py+42