| from __future__ import annotations |
|
|
| from typing import Any, Mapping |
|
|
| from .constants import GOLD_COMPANION_REPO, PUBLIC_DATASET_REPO |
|
|
|
|
| SPACE_URL = "https://huggingface.co/spaces/AgenticFinLab/H2EPR-Bench-Explorer" |
| PUBLIC_DATASET_URL = f"https://huggingface.co/datasets/{PUBLIC_DATASET_REPO}" |
| GOLD_COMPANION_URL = f"https://huggingface.co/datasets/{GOLD_COMPANION_REPO}" |
|
|
|
|
| def _first_value(value: Any) -> str: |
| if isinstance(value, (list, tuple)): |
| return str(value[0]).strip() if value else "" |
| return str(value or "").strip() |
|
|
|
|
| def query_param_event_id(query_params: Mapping[str, Any]) -> str: |
| return _first_value(query_params.get("event_id")) |
|
|
|
|
| def resolve_selected_event_index(rows: list[dict[str, Any]], requested_event_id: str = "") -> int: |
| if not rows: |
| return 0 |
| if requested_event_id: |
| for index, row in enumerate(rows): |
| if str(row.get("event_id", "")).strip() == requested_event_id: |
| return index |
| return 0 |
|
|
|
|
| def build_event_links(event_id: str, gantt_html_path: str = "") -> dict[str, str]: |
| event_id = event_id.strip() |
| links = { |
| "explorer": f"{SPACE_URL}?event_id={event_id}", |
| "public_dataset": PUBLIC_DATASET_URL, |
| "gold_request": GOLD_COMPANION_URL, |
| "finalcascade_jsonl": f"{PUBLIC_DATASET_URL}/blob/main/data/finmycelium_finalcascade_public.jsonl", |
| } |
| if gantt_html_path: |
| links["gantt_html"] = f"{PUBLIC_DATASET_URL}/blob/main/{gantt_html_path.lstrip('/')}" |
| return links |
|
|
|
|
| def filter_summary_text(filtered_count: int, total_count: int) -> str: |
| return f"Showing {filtered_count:,} of {total_count:,} events" |
|
|