From 5e4f8f96a0ae9e2fd37eeb4f7647dc4825136262 Mon Sep 17 00:00:00 2001 From: Dan Birman Date: Wed, 23 Oct 2024 15:00:53 -0700 Subject: [PATCH] fix: improving failure handling --- src/aind_qc_portal/docdb/database.py | 4 ++++ src/aind_qc_portal/qc_asset_app.py | 25 ++++++++++++++++--------- src/aind_qc_portal/utils.py | 3 ++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/aind_qc_portal/docdb/database.py b/src/aind_qc_portal/docdb/database.py index 7baac1b..c1fd43f 100644 --- a/src/aind_qc_portal/docdb/database.py +++ b/src/aind_qc_portal/docdb/database.py @@ -22,6 +22,8 @@ def qc_from_id(id: str): response = client.retrieve_docdb_records(filter_query={"_id": id}, limit=1) + if len(response) == 0: + return None return response[0] @@ -49,6 +51,8 @@ def get_subj_from_id(id: str): response = client.aggregate_docdb_records( pipeline=[{"$match": {"_id": id}}, {"$project": {"subject": 1, "_id": 0}}] ) + if len(response) == 0: + return None return response[0]["subject"]["subject_id"] diff --git a/src/aind_qc_portal/qc_asset_app.py b/src/aind_qc_portal/qc_asset_app.py index 50928be..2fe8df0 100644 --- a/src/aind_qc_portal/qc_asset_app.py +++ b/src/aind_qc_portal/qc_asset_app.py @@ -41,13 +41,15 @@ def update(self): self.asset_name = get_subj_from_id(str(self.id)) - self._records = get_assets_by_subj(self.asset_name) - - self.parse_records() + if self.asset_name: + self._records = get_assets_by_subj(self.asset_name) + self.parse_records() + else: + self.df = None @property def records(self): - if self.has_id: + if self.has_id and self.df: return self._records else: return {} @@ -140,6 +142,8 @@ def asset_history_panel(self): """Create a plot showing the history of this asset, showing how assets were derived from each other""" if not self.has_id: return "No ID is set" + if not self.df: + return pn.widgets.StaticText(value=f"No data found for ID: {self.id}") # Calculate the time range to show on the x axis (min_range, max_range, range_unit, format) = df_timestamp_range(self.df) @@ -182,13 +186,16 @@ def asset_history_df(self, group: int = 0): ) return df.style.map(qc_color, subset=["Status"]) - + def panel(self): - panes = [] - for group in set(self.df["group"]): - panes.append(pn.pane.DataFrame(self.asset_history_df(group), index=False, escape=False, width=660)) + if self.df: + panes = [] + for group in set(self.df["group"]): + panes.append(pn.pane.DataFrame(self.asset_history_df(group), index=False, escape=False, width=660)) - return pn.Column(*panes) + return pn.Column(*panes) + else: + return pn.pane.Markdown("") asset_history = AssetHistory() diff --git a/src/aind_qc_portal/utils.py b/src/aind_qc_portal/utils.py index 6b83e4a..acbcb9f 100644 --- a/src/aind_qc_portal/utils.py +++ b/src/aind_qc_portal/utils.py @@ -136,7 +136,8 @@ def qc_color(v): color = AIND_COLORS['red'] elif v == "Pending": color = AIND_COLORS['light_blue'] - print(color) + else: + color = AIND_COLORS['grey'] return f"background-color: {color}"