Fix Explorer event display fields
Browse files- app.py +7 -4
- src/h2epr_explorer/filters.py +44 -3
app.py
CHANGED
|
@@ -16,7 +16,7 @@ from h2epr_explorer.constants import (
|
|
| 16 |
RELEASE_BOUNDARY_NOTICE,
|
| 17 |
)
|
| 18 |
from h2epr_explorer.data_loader import load_catalog, load_event_graph, load_finalcascade_summary, load_stages
|
| 19 |
-
from h2epr_explorer.filters import filter_catalog
|
| 20 |
from h2epr_explorer.render_gantt import build_timeline_figure
|
| 21 |
|
| 22 |
|
|
@@ -62,13 +62,16 @@ if not filtered_rows:
|
|
| 62 |
st.warning("No event matches the current filters.")
|
| 63 |
st.stop()
|
| 64 |
|
|
|
|
|
|
|
| 65 |
selected_event = st.selectbox(
|
| 66 |
"Selected event",
|
| 67 |
[row["event_id"] for row in filtered_rows],
|
| 68 |
-
format_func=lambda event_id:
|
| 69 |
)
|
| 70 |
|
| 71 |
event_row = catalog[catalog["event_id"] == selected_event].iloc[0]
|
|
|
|
| 72 |
event_stages = stages[stages["event_id"] == selected_event].sort_values("stage_order")
|
| 73 |
summary_row = summary[summary["event_id"] == selected_event]
|
| 74 |
|
|
@@ -79,8 +82,8 @@ with tabs[0]:
|
|
| 79 |
st.dataframe(_select_columns(catalog[catalog["event_id"].isin([row["event_id"] for row in filtered_rows])], CATALOG_COLUMNS), use_container_width=True, height=520)
|
| 80 |
|
| 81 |
with tabs[1]:
|
| 82 |
-
st.subheader(
|
| 83 |
-
st.write(
|
| 84 |
c1, c2, c3, c4 = st.columns(4)
|
| 85 |
c1.metric("Domain", str(event_row.get("domain", "")))
|
| 86 |
c2.metric("Category", str(event_row.get("event_category", "")))
|
|
|
|
| 16 |
RELEASE_BOUNDARY_NOTICE,
|
| 17 |
)
|
| 18 |
from h2epr_explorer.data_loader import load_catalog, load_event_graph, load_finalcascade_summary, load_stages
|
| 19 |
+
from h2epr_explorer.filters import event_description, event_display_label, event_name, filter_catalog
|
| 20 |
from h2epr_explorer.render_gantt import build_timeline_figure
|
| 21 |
|
| 22 |
|
|
|
|
| 62 |
st.warning("No event matches the current filters.")
|
| 63 |
st.stop()
|
| 64 |
|
| 65 |
+
event_labels = {row["event_id"]: event_display_label(row) for row in catalog_rows}
|
| 66 |
+
|
| 67 |
selected_event = st.selectbox(
|
| 68 |
"Selected event",
|
| 69 |
[row["event_id"] for row in filtered_rows],
|
| 70 |
+
format_func=lambda event_id: event_labels.get(event_id, event_id),
|
| 71 |
)
|
| 72 |
|
| 73 |
event_row = catalog[catalog["event_id"] == selected_event].iloc[0]
|
| 74 |
+
event_record = event_row.to_dict()
|
| 75 |
event_stages = stages[stages["event_id"] == selected_event].sort_values("stage_order")
|
| 76 |
summary_row = summary[summary["event_id"] == selected_event]
|
| 77 |
|
|
|
|
| 82 |
st.dataframe(_select_columns(catalog[catalog["event_id"].isin([row["event_id"] for row in filtered_rows])], CATALOG_COLUMNS), use_container_width=True, height=520)
|
| 83 |
|
| 84 |
with tabs[1]:
|
| 85 |
+
st.subheader(event_name(event_record))
|
| 86 |
+
st.write(event_description(event_record))
|
| 87 |
c1, c2, c3, c4 = st.columns(4)
|
| 88 |
c1.metric("Domain", str(event_row.get("domain", "")))
|
| 89 |
c2.metric("Category", str(event_row.get("event_category", "")))
|
src/h2epr_explorer/filters.py
CHANGED
|
@@ -3,14 +3,56 @@ from __future__ import annotations
|
|
| 3 |
from typing import Any, Iterable
|
| 4 |
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def _contains_query(row: dict[str, Any], query: str) -> bool:
|
| 10 |
if not query:
|
| 11 |
return True
|
| 12 |
needle = query.casefold()
|
| 13 |
-
return any(needle in
|
| 14 |
|
| 15 |
|
| 16 |
def filter_catalog(
|
|
@@ -38,4 +80,3 @@ def filter_catalog(
|
|
| 38 |
continue
|
| 39 |
filtered.append(row)
|
| 40 |
return filtered
|
| 41 |
-
|
|
|
|
| 3 |
from typing import Any, Iterable
|
| 4 |
|
| 5 |
|
| 6 |
+
NAME_FIELDS = ("display_name", "event_name_en", "event_name", "event_name_zh")
|
| 7 |
+
DESCRIPTION_FIELDS = ("short_description", "event_descriptor_en", "event_description_en", "event_description_zh")
|
| 8 |
+
SEARCH_FIELDS = (
|
| 9 |
+
"event_id",
|
| 10 |
+
"display_name",
|
| 11 |
+
"event_name_en",
|
| 12 |
+
"event_name",
|
| 13 |
+
"event_name_zh",
|
| 14 |
+
"short_description",
|
| 15 |
+
"event_descriptor_en",
|
| 16 |
+
"event_description_zh",
|
| 17 |
+
"domain",
|
| 18 |
+
"event_category",
|
| 19 |
+
"keywords",
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _text_value(value: Any) -> str:
|
| 24 |
+
if isinstance(value, list):
|
| 25 |
+
return " ".join(str(item) for item in value)
|
| 26 |
+
return str(value or "")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def event_name(row: dict[str, Any]) -> str:
|
| 30 |
+
for field in NAME_FIELDS:
|
| 31 |
+
value = _text_value(row.get(field)).strip()
|
| 32 |
+
if value:
|
| 33 |
+
return value
|
| 34 |
+
return _text_value(row.get("event_id")).strip() or "Unnamed event"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def event_description(row: dict[str, Any]) -> str:
|
| 38 |
+
for field in DESCRIPTION_FIELDS:
|
| 39 |
+
value = _text_value(row.get(field)).strip()
|
| 40 |
+
if value:
|
| 41 |
+
return value
|
| 42 |
+
return ""
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def event_display_label(row: dict[str, Any]) -> str:
|
| 46 |
+
event_id = _text_value(row.get("event_id")).strip()
|
| 47 |
+
name = event_name(row)
|
| 48 |
+
return f"{event_id} · {name}" if event_id else name
|
| 49 |
|
| 50 |
|
| 51 |
def _contains_query(row: dict[str, Any], query: str) -> bool:
|
| 52 |
if not query:
|
| 53 |
return True
|
| 54 |
needle = query.casefold()
|
| 55 |
+
return any(needle in _text_value(row.get(field)).casefold() for field in SEARCH_FIELDS)
|
| 56 |
|
| 57 |
|
| 58 |
def filter_catalog(
|
|
|
|
| 80 |
continue
|
| 81 |
filtered.append(row)
|
| 82 |
return filtered
|
|
|