ziyuzhou02 commited on
Commit
720ae5b
·
verified ·
1 Parent(s): 82e0e89

Deploy Space: update src

Browse files
Files changed (1) hide show
  1. src/utils.py +70 -0
src/utils.py CHANGED
@@ -602,3 +602,73 @@ def make_rank_trend_plot(history_df: pd.DataFrame, metrics: list[str] | None = N
602
  yaxis=dict(gridcolor="rgba(0,0,0,0.08)"),
603
  )
604
  return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
  yaxis=dict(gridcolor="rgba(0,0,0,0.08)"),
603
  )
604
  return fig
605
+
606
+
607
+ DOMAIN_COLORS = {
608
+ "Finance": "#f97316",
609
+ "Climate": "#60a5fa",
610
+ "Ocean": "#34d399",
611
+ "Hydrology": "#818cf8",
612
+ "Transport": "#fbbf24",
613
+ "Hazards": "#fb7185",
614
+ "Web": "#a78bfa",
615
+ "Other": "#94a3b8",
616
+ }
617
+
618
+
619
+ def make_domain_pie_chart(root_dir: str = "results") -> object | None:
620
+ """Build a plotly Pie chart showing dataset count per domain.
621
+
622
+ Uses dataset_properties.csv for domain info, with display_domain mapping.
623
+ Returns None if plotly is unavailable or no data.
624
+ """
625
+ go = _get_plotly()
626
+ if go is None:
627
+ return None
628
+
629
+ props_path = Path(root_dir) / "dataset_properties.csv"
630
+ if not props_path.exists():
631
+ return None
632
+
633
+ try:
634
+ df = pd.read_csv(props_path)
635
+ except Exception:
636
+ return None
637
+
638
+ if df.empty or "domain" not in df.columns:
639
+ return None
640
+
641
+ df["display_domain"] = df["domain"].map(lambda d: display_domain(d))
642
+
643
+ # Build per-domain dataset list for hover text
644
+ domain_datasets: dict[str, list[str]] = {}
645
+ for _, row in df.iterrows():
646
+ dd = row["display_domain"]
647
+ ds_name = dataset_short_name(str(row.get("dataset", "")))
648
+ domain_datasets.setdefault(dd, []).append(ds_name)
649
+
650
+ labels = list(domain_datasets.keys())
651
+ values = [len(v) for v in domain_datasets.values()]
652
+ hover = [", ".join(ds_list) for ds_list in domain_datasets.values()]
653
+ colors = [DOMAIN_COLORS.get(label, "#94a3b8") for label in labels]
654
+
655
+ fig = go.Figure(data=[go.Pie(
656
+ labels=labels,
657
+ values=values,
658
+ hovertext=hover,
659
+ hoverinfo="label+percent+text",
660
+ textinfo="label+value",
661
+ marker=dict(colors=colors),
662
+ hole=0.35,
663
+ )])
664
+ fig.update_layout(
665
+ title=dict(text="Dataset coverage by domain", font=dict(size=14)),
666
+ margin=dict(l=20, r=20, t=50, b=20),
667
+ height=320,
668
+ paper_bgcolor="rgba(0,0,0,0)",
669
+ plot_bgcolor="rgba(0,0,0,0)",
670
+ font=dict(color="black"),
671
+ legend=dict(orientation="h", yanchor="bottom", y=-0.15, xanchor="center", x=0.5),
672
+ showlegend=True,
673
+ )
674
+ return fig