Spaces:
Running
Running
Fix leaderboard domain and dataset deduplication
Browse files- src/utils.py +58 -27
src/utils.py
CHANGED
|
@@ -83,6 +83,35 @@ RESULT_COLUMNS = [
|
|
| 83 |
"num_variates",
|
| 84 |
]
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
def _read_result_csv(path: str | Path) -> pd.DataFrame:
|
| 88 |
df = pd.read_csv(
|
|
@@ -204,6 +233,8 @@ def prepare_results_df(
|
|
| 204 |
return df
|
| 205 |
if Path(ds_properties).exists():
|
| 206 |
df = enrich_with_properties(df, ds_properties)
|
|
|
|
|
|
|
| 207 |
|
| 208 |
for metric in METRIC_COLUMNS:
|
| 209 |
df[metric] = pd.to_numeric(df[metric], errors="coerce")
|
|
@@ -268,8 +299,10 @@ def get_grouped_dfs(
|
|
| 268 |
subset = df[df["dataset"] == dataset]
|
| 269 |
if subset.empty:
|
| 270 |
continue
|
| 271 |
-
values = subset.
|
| 272 |
-
|
|
|
|
|
|
|
| 273 |
columns={f"Rank_{metric}": f"{METRIC_LABELS[metric]}_Rank" for metric in DISPLAY_METRICS}
|
| 274 |
)
|
| 275 |
dataset_values[dataset] = values
|
|
@@ -488,19 +521,6 @@ def load_live_aggregate_metadata_md(root_dir: str = "results") -> str:
|
|
| 488 |
f"{generated}."
|
| 489 |
)
|
| 490 |
|
| 491 |
-
|
| 492 |
-
DOMAIN_DISPLAY = {
|
| 493 |
-
"Weather": "Climate",
|
| 494 |
-
"Air Quality": "Climate",
|
| 495 |
-
"Transport": "Transport",
|
| 496 |
-
"Transportation": "Transportation",
|
| 497 |
-
"Finance": "Finance",
|
| 498 |
-
"Ocean": "Ocean",
|
| 499 |
-
"Hydrology": "Hydrology",
|
| 500 |
-
"Hazards": "Hazards",
|
| 501 |
-
"Web": "Web",
|
| 502 |
-
}
|
| 503 |
-
|
| 504 |
DATASET_SHORT_NAMES = {
|
| 505 |
"binance_btcusdt_1h_close": "BTC/USDT",
|
| 506 |
"coingecko_bitcoin_7d_price_usd": "Bitcoin USD",
|
|
@@ -521,7 +541,23 @@ DATASET_SHORT_NAMES = {
|
|
| 521 |
|
| 522 |
|
| 523 |
def display_domain(raw_domain: str) -> str:
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
|
| 527 |
def dataset_short_name(dataset: str) -> str:
|
|
@@ -565,15 +601,7 @@ def lookup_dataset_domain(dataset: str, root_dir: str = "results") -> str:
|
|
| 565 |
|
| 566 |
|
| 567 |
DOMAIN_TAB_ORDER = [
|
| 568 |
-
|
| 569 |
-
"Climate",
|
| 570 |
-
"Ocean",
|
| 571 |
-
"Hydrology",
|
| 572 |
-
"Transport",
|
| 573 |
-
"Transportation",
|
| 574 |
-
"Hazards",
|
| 575 |
-
"Web",
|
| 576 |
-
"Other",
|
| 577 |
]
|
| 578 |
|
| 579 |
|
|
@@ -582,7 +610,12 @@ def group_datasets_by_domain(
|
|
| 582 |
root_dir: str = "results",
|
| 583 |
) -> dict[str, list[str]]:
|
| 584 |
by_domain: dict[str, list[str]] = {}
|
|
|
|
| 585 |
for dataset in datasets:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
domain = display_domain(lookup_dataset_domain(dataset, root_dir))
|
| 587 |
by_domain.setdefault(domain, []).append(dataset)
|
| 588 |
|
|
@@ -889,11 +922,9 @@ DOMAIN_COLORS = {
|
|
| 889 |
"Climate": "#60a5fa",
|
| 890 |
"Ocean": "#34d399",
|
| 891 |
"Hydrology": "#818cf8",
|
| 892 |
-
"Transport": "#fbbf24",
|
| 893 |
"Transportation": "#14b8a6",
|
| 894 |
"Hazards": "#fb7185",
|
| 895 |
"Web": "#a78bfa",
|
| 896 |
-
"Other": "#94a3b8",
|
| 897 |
}
|
| 898 |
|
| 899 |
|
|
|
|
| 83 |
"num_variates",
|
| 84 |
]
|
| 85 |
|
| 86 |
+
CANONICAL_DOMAINS = [
|
| 87 |
+
"Finance",
|
| 88 |
+
"Climate",
|
| 89 |
+
"Ocean",
|
| 90 |
+
"Hydrology",
|
| 91 |
+
"Transportation",
|
| 92 |
+
"Web",
|
| 93 |
+
"Hazards",
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
DOMAIN_DISPLAY = {
|
| 97 |
+
"Finance": "Finance",
|
| 98 |
+
"Econ/Fin": "Finance",
|
| 99 |
+
"Sales": "Finance",
|
| 100 |
+
"Climate": "Climate",
|
| 101 |
+
"Weather": "Climate",
|
| 102 |
+
"Air Quality": "Climate",
|
| 103 |
+
"Nature": "Climate",
|
| 104 |
+
"Energy": "Climate",
|
| 105 |
+
"Ocean": "Ocean",
|
| 106 |
+
"Hydrology": "Hydrology",
|
| 107 |
+
"Transport": "Transportation",
|
| 108 |
+
"Transportation": "Transportation",
|
| 109 |
+
"Web": "Web",
|
| 110 |
+
"Web/CloudOps": "Web",
|
| 111 |
+
"Hazards": "Hazards",
|
| 112 |
+
"Healthcare": "Hazards",
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
|
| 116 |
def _read_result_csv(path: str | Path) -> pd.DataFrame:
|
| 117 |
df = pd.read_csv(
|
|
|
|
| 233 |
return df
|
| 234 |
if Path(ds_properties).exists():
|
| 235 |
df = enrich_with_properties(df, ds_properties)
|
| 236 |
+
if "domain" in df.columns:
|
| 237 |
+
df["domain"] = df["domain"].map(display_domain)
|
| 238 |
|
| 239 |
for metric in METRIC_COLUMNS:
|
| 240 |
df[metric] = pd.to_numeric(df[metric], errors="coerce")
|
|
|
|
| 299 |
subset = df[df["dataset"] == dataset]
|
| 300 |
if subset.empty:
|
| 301 |
continue
|
| 302 |
+
values = subset.groupby("model")[DISPLAY_METRICS].agg(aggregate_gmean).rename(
|
| 303 |
+
columns=METRIC_LABELS
|
| 304 |
+
)
|
| 305 |
+
ranks = subset.groupby("model")[rank_cols].agg(aggregate_rank_mean).rename(
|
| 306 |
columns={f"Rank_{metric}": f"{METRIC_LABELS[metric]}_Rank" for metric in DISPLAY_METRICS}
|
| 307 |
)
|
| 308 |
dataset_values[dataset] = values
|
|
|
|
| 521 |
f"{generated}."
|
| 522 |
)
|
| 523 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
DATASET_SHORT_NAMES = {
|
| 525 |
"binance_btcusdt_1h_close": "BTC/USDT",
|
| 526 |
"coingecko_bitcoin_7d_price_usd": "Bitcoin USD",
|
|
|
|
| 541 |
|
| 542 |
|
| 543 |
def display_domain(raw_domain: str) -> str:
|
| 544 |
+
domain = str(raw_domain).strip()
|
| 545 |
+
if domain in DOMAIN_DISPLAY:
|
| 546 |
+
return DOMAIN_DISPLAY[domain]
|
| 547 |
+
lowered = domain.lower()
|
| 548 |
+
if any(token in lowered for token in ("finance", "econ", "sales")):
|
| 549 |
+
return "Finance"
|
| 550 |
+
if any(token in lowered for token in ("climate", "weather", "air", "nature", "energy")):
|
| 551 |
+
return "Climate"
|
| 552 |
+
if "ocean" in lowered:
|
| 553 |
+
return "Ocean"
|
| 554 |
+
if "hydro" in lowered:
|
| 555 |
+
return "Hydrology"
|
| 556 |
+
if any(token in lowered for token in ("transport", "taxi")):
|
| 557 |
+
return "Transportation"
|
| 558 |
+
if any(token in lowered for token in ("web", "cloud", "wiki")):
|
| 559 |
+
return "Web"
|
| 560 |
+
return "Hazards"
|
| 561 |
|
| 562 |
|
| 563 |
def dataset_short_name(dataset: str) -> str:
|
|
|
|
| 601 |
|
| 602 |
|
| 603 |
DOMAIN_TAB_ORDER = [
|
| 604 |
+
*CANONICAL_DOMAINS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 605 |
]
|
| 606 |
|
| 607 |
|
|
|
|
| 610 |
root_dir: str = "results",
|
| 611 |
) -> dict[str, list[str]]:
|
| 612 |
by_domain: dict[str, list[str]] = {}
|
| 613 |
+
seen: set[str] = set()
|
| 614 |
for dataset in datasets:
|
| 615 |
+
dataset = dataset.split("/")[0].strip()
|
| 616 |
+
if dataset in seen:
|
| 617 |
+
continue
|
| 618 |
+
seen.add(dataset)
|
| 619 |
domain = display_domain(lookup_dataset_domain(dataset, root_dir))
|
| 620 |
by_domain.setdefault(domain, []).append(dataset)
|
| 621 |
|
|
|
|
| 922 |
"Climate": "#60a5fa",
|
| 923 |
"Ocean": "#34d399",
|
| 924 |
"Hydrology": "#818cf8",
|
|
|
|
| 925 |
"Transportation": "#14b8a6",
|
| 926 |
"Hazards": "#fb7185",
|
| 927 |
"Web": "#a78bfa",
|
|
|
|
| 928 |
}
|
| 929 |
|
| 930 |
|