From f265942b22ad87d76200a194bffb4cf58b23b8c7 Mon Sep 17 00:00:00 2001 From: Dan Birman Date: Mon, 11 Nov 2024 10:38:24 -0800 Subject: [PATCH] feat: adding status_panel which shows status across stages/modality --- src/aind_qc_portal/panel/evaluation.py | 2 +- src/aind_qc_portal/panel/quality_control.py | 32 ++++++++++++++++++--- src/aind_qc_portal/qc_app.py | 2 +- src/aind_qc_portal/qc_portal_app.py | 2 +- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/aind_qc_portal/panel/evaluation.py b/src/aind_qc_portal/panel/evaluation.py index 19c0928..9ba6757 100644 --- a/src/aind_qc_portal/panel/evaluation.py +++ b/src/aind_qc_portal/panel/evaluation.py @@ -46,7 +46,7 @@ def panel(self): md = f""" {md_style(12, self._data.description if self._data.description else "*no description provided*")} -{md_style(8, f"Current state: **{status_html(self._data.status)}**")} +{md_style(8, f"Current state: **{status_html(self._data.status())}**")} {md_style(8, f"Contains **{len(self._data.metrics)}** metrics. {allow_failing_str}")} """ diff --git a/src/aind_qc_portal/panel/quality_control.py b/src/aind_qc_portal/panel/quality_control.py index 487e750..83a165f 100644 --- a/src/aind_qc_portal/panel/quality_control.py +++ b/src/aind_qc_portal/panel/quality_control.py @@ -3,6 +3,7 @@ import boto3 import panel as pn +import pandas as pd import param from aind_data_schema.core.quality_control import QualityControl @@ -139,6 +140,30 @@ def update_objects(self): self.tabs.objects = objects + def status_panel(self): + """Build a Panel table that shows the current status of all evaluations""" + # We'll loop over stage and modality to build a table + + data = [] + for modality in self.modalities: + for stage in self.stages: + data.append({ + "Modality": modality, + "Stage": stage, + "Status": status_html(self._data.status(modality=modality, stage=stage)) + }) + + df = pd.DataFrame(data, columns=["Modality", "Stage", "Status"]) + + # Reshape the DataFrame using pivot_table + df_squashed = df.pivot_table(index="Stage", columns="Modality", values="Status", aggfunc="first") + + # Optional: Clean up column names by flattening the MultiIndex if needed + df_squashed.columns.name = None + df_squashed.reset_index(inplace=True) + + return pn.pane.DataFrame(df_squashed, index=False, escape=False) + def panel(self): """Build a Panel object representing this QC action""" if not self._has_data or not self._data: @@ -156,7 +181,7 @@ def panel(self): state_md = f""" Current state: -Status: **{status_html(self._data.status)}** +Status: **{status_html(self._data.status())}** Contains {len(self.evaluations)} evaluations. {failing_eval_str} """ @@ -166,9 +191,8 @@ def panel(self): notes_box.param.watch(self.set_dirty, "value") # state row - state_row = pn.Row(state_pane, notes_box) - quality_control_pane = pn.Column(header, state_row) - + state_row = pn.Row(state_pane, notes_box, self.status_panel()) + quality_control_pane = pn.Column(header, state_row) # button header_row = pn.Row( diff --git a/src/aind_qc_portal/qc_app.py b/src/aind_qc_portal/qc_app.py index 5b70e5b..e18f3d4 100644 --- a/src/aind_qc_portal/qc_app.py +++ b/src/aind_qc_portal/qc_app.py @@ -17,7 +17,7 @@ # State sync class Settings(param.Parameterized): - id = param.String(default="4ceba2a9-ecb0-458e-b874-9923762d7725") + id = param.String(default="a61f285e-c79b-46cd-b554-991d711b6e53") settings = Settings() diff --git a/src/aind_qc_portal/qc_portal_app.py b/src/aind_qc_portal/qc_portal_app.py index bc3a566..71c08d4 100644 --- a/src/aind_qc_portal/qc_portal_app.py +++ b/src/aind_qc_portal/qc_portal_app.py @@ -37,7 +37,7 @@ def __init__(self): try: qc = QualityControl.model_validate_json(json.dumps(record["quality_control"])) - status = qc.status.value + status = qc.status().value except Exception as e: print(f"QC object failed to validate: {e}") status = "Invalid QC"