Spaces:
Running
Running
Deploy Space: update src
Browse files- src/utils.py +16 -95
src/utils.py
CHANGED
|
@@ -123,40 +123,15 @@ def load_all_results(root_dir: str = "results") -> pd.DataFrame:
|
|
| 123 |
df = df.sort_values(by=["model", "dataset"]).reset_index(drop=True)
|
| 124 |
df["model"] = df["model"].replace(LEGACY_MODEL_NAMES)
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
try:
|
| 136 |
-
cfg = json.loads(config_json.read_text())
|
| 137 |
-
if "model" in cfg:
|
| 138 |
-
detected_models.add(cfg["model"])
|
| 139 |
-
except Exception:
|
| 140 |
-
pass
|
| 141 |
-
# Read model display names from the CSV file itself as a fallback
|
| 142 |
-
try:
|
| 143 |
-
temp_df = pd.read_csv(p / "all_results.csv", nrows=5)
|
| 144 |
-
if "model" in temp_df.columns:
|
| 145 |
-
detected_models.update(temp_df["model"].dropna().unique())
|
| 146 |
-
except Exception:
|
| 147 |
-
pass
|
| 148 |
-
|
| 149 |
-
# Fallback to defaults if no models are detected
|
| 150 |
-
if not detected_models:
|
| 151 |
-
detected_models = {
|
| 152 |
-
"Toto-2.0-1B",
|
| 153 |
-
"Moirai-1.1-Large",
|
| 154 |
-
"Chronos-2",
|
| 155 |
-
"Timer-S1",
|
| 156 |
-
"TiRex",
|
| 157 |
-
"TimesFM-2.5"
|
| 158 |
-
}
|
| 159 |
-
df = df[df["model"].isin(detected_models)]
|
| 160 |
|
| 161 |
parts = df["dataset"].astype(str).str.split("/", expand=True)
|
| 162 |
if parts.shape[1] < 3:
|
|
@@ -663,9 +638,10 @@ def _today_start_utc8() -> datetime:
|
|
| 663 |
|
| 664 |
def get_dataset_last_eval_time(ds_base: str, root_dir: str = "results") -> datetime | None:
|
| 665 |
latest_dt: datetime | None = None
|
|
|
|
| 666 |
# Scan model directories
|
| 667 |
for model_dir in Path(root_dir).iterdir():
|
| 668 |
-
if not model_dir.is_dir() or
|
| 669 |
continue
|
| 670 |
forecasts_dir = model_dir / "forecasts"
|
| 671 |
if not forecasts_dir.is_dir():
|
|
@@ -717,32 +693,12 @@ def make_domain_pie_chart(root_dir: str = "results") -> object | None:
|
|
| 717 |
today_start = _today_start_utc8()
|
| 718 |
utc8 = today_start.tzinfo
|
| 719 |
|
| 720 |
-
# Read eval_history.jsonl
|
| 721 |
history_path = Path(root_dir) / "eval_history.jsonl"
|
| 722 |
timestamp_counts: dict[str, int] = {} # domain → total timestamps
|
| 723 |
domain_datasets: dict[str, set[str]] = {} # domain → set of dataset short names
|
| 724 |
|
| 725 |
if history_path.exists():
|
| 726 |
-
try:
|
| 727 |
-
with open(history_path) as f:
|
| 728 |
-
for line in f:
|
| 729 |
-
if not line.strip():
|
| 730 |
-
continue
|
| 731 |
-
entry = json.loads(line)
|
| 732 |
-
eval_at = entry.get("evaluated_at", "")
|
| 733 |
-
if eval_at:
|
| 734 |
-
eval_dt = datetime.fromisoformat(eval_at.replace("Z", "+00:00"))
|
| 735 |
-
if eval_dt.astimezone(utc8) >= today_start:
|
| 736 |
-
ds_base = entry.get("dataset", "")
|
| 737 |
-
pred_len = entry.get("prediction_length", 0)
|
| 738 |
-
domain = get_domain(ds_base)
|
| 739 |
-
timestamp_counts[domain] = timestamp_counts.get(domain, 0) + pred_len
|
| 740 |
-
domain_datasets.setdefault(domain, set()).add(dataset_short_name(ds_base))
|
| 741 |
-
except Exception:
|
| 742 |
-
pass
|
| 743 |
-
|
| 744 |
-
# Fallback to cumulative history (no today filter) if today is empty
|
| 745 |
-
if not timestamp_counts and history_path.exists():
|
| 746 |
try:
|
| 747 |
with open(history_path) as f:
|
| 748 |
for line in f:
|
|
@@ -757,46 +713,12 @@ def make_domain_pie_chart(root_dir: str = "results") -> object | None:
|
|
| 757 |
except Exception:
|
| 758 |
pass
|
| 759 |
|
| 760 |
-
# Fallback to
|
| 761 |
-
if not timestamp_counts:
|
| 762 |
-
seen_datasets: set[str] = set()
|
| 763 |
-
for model_dir in sorted(Path(root_dir).iterdir()):
|
| 764 |
-
if not model_dir.is_dir() or not (model_dir / "all_results.csv").exists():
|
| 765 |
-
continue
|
| 766 |
-
forecasts_dir = model_dir / "forecasts"
|
| 767 |
-
if not forecasts_dir.is_dir():
|
| 768 |
-
continue
|
| 769 |
-
for fp in forecasts_dir.glob("*.json"):
|
| 770 |
-
try:
|
| 771 |
-
snap = json.loads(fp.read_text())
|
| 772 |
-
except Exception:
|
| 773 |
-
continue
|
| 774 |
-
|
| 775 |
-
eval_at = snap.get("evaluated_at", "")
|
| 776 |
-
if eval_at:
|
| 777 |
-
try:
|
| 778 |
-
eval_dt = datetime.fromisoformat(eval_at.replace("Z", "+00:00"))
|
| 779 |
-
if eval_dt.astimezone(utc8) < today_start:
|
| 780 |
-
continue
|
| 781 |
-
except Exception:
|
| 782 |
-
continue
|
| 783 |
-
|
| 784 |
-
ds_full = snap.get("dataset", "")
|
| 785 |
-
ds_base = ds_full.split("/")[0]
|
| 786 |
-
if ds_base in seen_datasets:
|
| 787 |
-
continue
|
| 788 |
-
seen_datasets.add(ds_base)
|
| 789 |
-
|
| 790 |
-
domain = get_domain(ds_base)
|
| 791 |
-
n_ts = len(snap.get("context", [])) + len(snap.get("actuals", []))
|
| 792 |
-
timestamp_counts[domain] = timestamp_counts.get(domain, 0) + n_ts
|
| 793 |
-
domain_datasets.setdefault(domain, set()).add(dataset_short_name(ds_base))
|
| 794 |
-
|
| 795 |
-
# Fallback to cumulative snapshots count (no today filter) if still empty
|
| 796 |
if not timestamp_counts:
|
| 797 |
seen_datasets: set[str] = set()
|
|
|
|
| 798 |
for model_dir in sorted(Path(root_dir).iterdir()):
|
| 799 |
-
if not model_dir.is_dir() or
|
| 800 |
continue
|
| 801 |
forecasts_dir = model_dir / "forecasts"
|
| 802 |
if not forecasts_dir.is_dir():
|
|
@@ -837,10 +759,9 @@ def make_domain_pie_chart(root_dir: str = "results") -> object | None:
|
|
| 837 |
marker=dict(colors=colors),
|
| 838 |
hole=0.25,
|
| 839 |
)])
|
| 840 |
-
date_str = today_start.strftime("%Y-%m-%d")
|
| 841 |
fig.update_layout(
|
| 842 |
title=dict(
|
| 843 |
-
text=
|
| 844 |
font=dict(size=16, weight="bold"),
|
| 845 |
),
|
| 846 |
margin=dict(l=20, r=20, t=60, b=20),
|
|
|
|
| 123 |
df = df.sort_values(by=["model", "dataset"]).reset_index(drop=True)
|
| 124 |
df["model"] = df["model"].replace(LEGACY_MODEL_NAMES)
|
| 125 |
|
| 126 |
+
ALLOWED_MODELS = {
|
| 127 |
+
"Toto-2.0-1B",
|
| 128 |
+
"Moirai-1.1-Large",
|
| 129 |
+
"Chronos-2",
|
| 130 |
+
"Timer-S1",
|
| 131 |
+
"TiRex",
|
| 132 |
+
"TimesFM-2.5"
|
| 133 |
+
}
|
| 134 |
+
df = df[df["model"].isin(ALLOWED_MODELS)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
parts = df["dataset"].astype(str).str.split("/", expand=True)
|
| 137 |
if parts.shape[1] < 3:
|
|
|
|
| 638 |
|
| 639 |
def get_dataset_last_eval_time(ds_base: str, root_dir: str = "results") -> datetime | None:
|
| 640 |
latest_dt: datetime | None = None
|
| 641 |
+
ALLOWED_SLUGS = {"chronos_2", "moirai_1_1_large", "timer_s1", "timesfm_2_5", "tirex", "toto_2_0_1b"}
|
| 642 |
# Scan model directories
|
| 643 |
for model_dir in Path(root_dir).iterdir():
|
| 644 |
+
if not model_dir.is_dir() or model_dir.name not in ALLOWED_SLUGS:
|
| 645 |
continue
|
| 646 |
forecasts_dir = model_dir / "forecasts"
|
| 647 |
if not forecasts_dir.is_dir():
|
|
|
|
| 693 |
today_start = _today_start_utc8()
|
| 694 |
utc8 = today_start.tzinfo
|
| 695 |
|
| 696 |
+
# Read eval_history.jsonl (Cumulative)
|
| 697 |
history_path = Path(root_dir) / "eval_history.jsonl"
|
| 698 |
timestamp_counts: dict[str, int] = {} # domain → total timestamps
|
| 699 |
domain_datasets: dict[str, set[str]] = {} # domain → set of dataset short names
|
| 700 |
|
| 701 |
if history_path.exists():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
try:
|
| 703 |
with open(history_path) as f:
|
| 704 |
for line in f:
|
|
|
|
| 713 |
except Exception:
|
| 714 |
pass
|
| 715 |
|
| 716 |
+
# Fallback to cumulative snapshots count (no today filter) if empty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 717 |
if not timestamp_counts:
|
| 718 |
seen_datasets: set[str] = set()
|
| 719 |
+
ALLOWED_SLUGS = {"chronos_2", "moirai_1_1_large", "timer_s1", "timesfm_2_5", "tirex", "toto_2_0_1b"}
|
| 720 |
for model_dir in sorted(Path(root_dir).iterdir()):
|
| 721 |
+
if not model_dir.is_dir() or model_dir.name not in ALLOWED_SLUGS:
|
| 722 |
continue
|
| 723 |
forecasts_dir = model_dir / "forecasts"
|
| 724 |
if not forecasts_dir.is_dir():
|
|
|
|
| 759 |
marker=dict(colors=colors),
|
| 760 |
hole=0.25,
|
| 761 |
)])
|
|
|
|
| 762 |
fig.update_layout(
|
| 763 |
title=dict(
|
| 764 |
+
text="Evaluated timestamps by domain",
|
| 765 |
font=dict(size=16, weight="bold"),
|
| 766 |
),
|
| 767 |
margin=dict(l=20, r=20, t=60, b=20),
|