Skip to content

Commit

Permalink
fix: fixes to status() and font sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Nov 12, 2024
1 parent 509a8af commit cea4d70
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/aind_qc_portal/panel/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")}
"""

Expand Down
54 changes: 25 additions & 29 deletions src/aind_qc_portal/panel/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def metric_panel(self):
auto_value = True
elif isinstance(value, dict):
# first, check if every key/value pair has the same length, if so coerce to a dataframe
if all([len(v) == len(value[list(value.keys())[0]]) for v in value.values()]):
if all([isinstance(v, list) for v in value.values()]) and all([len(v) == len(value[list(value.keys())[0]]) for v in value.values()]):
df = pd.DataFrame(value)
value_widget = pn.pane.DataFrame(df)
else:
Expand Down Expand Up @@ -184,17 +184,10 @@ def _media_panel(reference, parent):
elif "s3" in reference:
bucket = reference.split("/")[2]
key = "/".join(reference.split("/")[3:])
media_data = _get_s3_asset(parent.s3_client, bucket, key)
# [TODO] this needs to handle different media types
return pn.pane.Image(media_data, sizing_mode='scale_width', max_width=1200, max_height=2000)
return _get_s3_asset(parent.s3_client, bucket, key)

elif "png" in reference:
if reference.startswith("/"):
reference = reference[reference.find("/", 1):]

image_data = _get_s3_asset(parent.s3_client, parent.s3_bucket, parent.s3_prefix + reference)
# [TODO] this needs to handle different media types
return pn.pane.Image(image_data, sizing_mode='scale_width', max_width=1200, max_height=2000)
return _get_s3_asset(parent.s3_client, parent.s3_bucket, parent.s3_prefix + reference)

elif reference == "ecephys-drift-map":
return ""
Expand All @@ -203,25 +196,27 @@ def _media_panel(reference, parent):
return f"Unable to parse {reference}"


# def _parse_type(reference, media_data):
# """Interpret the media type from the reference string
def _parse_type(reference, data):
"""Interpret the media type from the reference string
# Parameters
# ----------
# reference : _type_
# _description_
# media_data : _type_
# _description_
# """
# if parsed_url.path.endswith(".png") or parsed_url.path.endswith(".jpg"):
# return pn.pane.Image(reference, sizing_mode='scale_width', max_width=1200)
# elif parsed_url.path.endswith(".mp4"):
# return pn.pane.Video(reference, controls=True, sizing_mode='scale_width', max_width=1200)
# elif "neuroglancer" in reference:
# iframe_html = f'<iframe src="{reference}" style="height:100%; width:100%" frameborder="0"></iframe>'
# return pn.pane.HTML(iframe_html, sizing_mode='stretch_both')
# else:
# return pn.widgets.StaticText(value=f'Reference: <a target="_blank" href="{reference}">link</a>')
Parameters
----------
reference : _type_
_description_
data : _type_
_description_
"""
if reference.endswith(".png") or reference.endswith(".jpg"):
return pn.pane.Image(data, sizing_mode='scale_width', max_width=1200)
elif reference.endswith(".mp4"):
return pn.pane.Video(reference, controls=True, sizing_mode='scale_width', max_width=1200)
elif "neuroglancer" in reference:
iframe_html = f'<iframe src="{reference}" style="height:100%; width:100%" frameborder="0"></iframe>'
return pn.pane.HTML(iframe_html, sizing_mode='stretch_both')
elif "http" in reference:
return pn.widgets.StaticText(value=f'Reference: <a target="_blank" href="{reference}">link</a>')
else:
return pn.widgets.StaticText(value=data)


def _get_s3_asset(s3_client, bucket, key):
Expand All @@ -238,6 +233,7 @@ def _get_s3_asset(s3_client, bucket, key):
"""
try:
response = s3_client.get_object(Bucket=bucket, Key=key)
return BytesIO(response['Body'].read())
data = BytesIO(response['Body'].read())
return _parse_type(key, data)
except Exception as e:
return f"[ERROR] Failed to fetch asset {bucket}/{key}: {e}"
8 changes: 4 additions & 4 deletions src/aind_qc_portal/panel/quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def panel(self):

# build the header
md = f"""
# Quality control for {self.asset_name}
<span style="font-size:14pt">Quality control for {self.asset_name}</span>
"""
header = pn.pane.Markdown(md)

Expand All @@ -155,9 +155,9 @@ def panel(self):
failing_eval_str = ""

state_md = f"""
<span style="font-size:14pt">Current state:</span>
<span style="font-size:12pt">Status: **{status_html(self._data.status)}**</span>
<span style="font-size:12pt">Contains {len(self.evaluations)} evaluations. {failing_eval_str}</span>
<span style="font-size:12pt">Current state:</span>
<span style="font-size:10pt">Status: **{status_html((self._data.status()))}**</span>
<span style="font-size:10pt">Contains {len(self.evaluations)} evaluations. {failing_eval_str}</span>
"""

state_pane = pn.pane.Markdown(state_md)
Expand Down
2 changes: 1 addition & 1 deletion src/aind_qc_portal/qc_asset_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def parse_records(self):

if "quality_control" in record and record["quality_control"]:
qc = QualityControl.model_validate_json(json.dumps(record["quality_control"]))
status = qc.status.value
status = qc.status().value
else:
status = "No QC"

Expand Down
2 changes: 1 addition & 1 deletion src/aind_qc_portal/qc_portal_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit cea4d70

Please sign in to comment.