From 60c195984027b91b087fbffd4fd6009ee5b8fc19 Mon Sep 17 00:00:00 2001 From: Dan Birman Date: Mon, 9 Dec 2024 14:58:03 -0800 Subject: [PATCH] fix: allow fields to be missing --- src/aind_qc_portal/qc_project_app.py | 31 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/aind_qc_portal/qc_project_app.py b/src/aind_qc_portal/qc_project_app.py index b199b22..9fd1661 100644 --- a/src/aind_qc_portal/qc_project_app.py +++ b/src/aind_qc_portal/qc_project_app.py @@ -41,20 +41,22 @@ def _get_assets(self): groups[raw_name] = len(groups) record_data = { - '_id': record['_id'], - 'raw': record['data_description']['data_level'] == 'raw', - 'project_name': record['data_description']['project_name'], - 'location': record['location'], - 'name': record['name'], - 'session_start_time': record['session']['session_start_time'], - 'session_type': record['session']['session_type'], - 'subject_id': record['subject']['subject_id'], - 'genotype': record['subject']['genotype'], - 'group': groups[raw_name], + '_id': record.get('_id'), + 'raw': record.get('data_description', {}).get('data_level') == 'raw', + 'project_name': record.get('data_description', {}).get('project_name'), + 'location': record.get('location'), + 'name': record.get('name'), + 'session_start_time': record.get('session', {}).get('session_start_time'), + 'session_type': record.get('session', {}).get('session_type'), + 'subject_id': record.get('subject', {}).get('subject_id'), + 'genotype': record.get('subject', {}).get('genotype'), + 'group': groups.get(raw_name), } data.append(record_data) - # Parse the asset history + if len(data) == 0: + self.data = None + return self.data = pd.DataFrame(data) self.data["timestamp"] = pd.to_datetime(self.data["session_start_time"]) @@ -74,10 +76,16 @@ def _get_assets(self): self.data.sort_values(by="group", ascending=True, inplace=True) def get_data(self): + if self.data is None: + return None return self.data[["subject_id", "Date", "S3 link", "Subject view", "QC view", "genotype", "session_type", "raw"]] def history_panel(self): """Create a plot showing the history of this asset, showing how assets were derived from each other""" + if self.data is None: + return pn.widgets.StaticText( + value=f"No data found for project: {settings.project_name}" + ) # Calculate the time range to show on the x axis (min_range, max_range, range_unit, format) = df_timestamp_range( @@ -108,6 +116,7 @@ def history_panel(self): return pn.pane.Vega(chart, sizing_mode="stretch_width", styles=OUTER_STYLE) + md = f"""

QC Portal - Project View