Skip to content

Commit

Permalink
fix: improving failure handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Oct 23, 2024
1 parent 9522011 commit 5e4f8f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/aind_qc_portal/docdb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down Expand Up @@ -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"]


Expand Down
25 changes: 16 additions & 9 deletions src/aind_qc_portal/qc_asset_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/aind_qc_portal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"


Expand Down

0 comments on commit 5e4f8f9

Please sign in to comment.