Skip to content

Commit

Permalink
feat: adding option for missing/present
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Aug 20, 2024
1 parent 0638dcd commit 5e1bbd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/aind_metadata_viz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,20 @@ def build_top():
return pane


missing_selector = pn.widgets.Select(name='Value state', options=['Missing', 'Present'])


def build_csv(file, field):
# For everybody who is missing the currently active file/field
id_fields = ["name", "_id", "location", "creation"]

get_present = missing_selector.value == 'Present'

df_data = []
for data in data_list:
if not data[file] is None:
if mid_selector.value == " " or check_present(field, data[file]):
if mid_selector.value == " " or check_present(field, data[file], check_present=get_present):
# This file/field combo is present/missing, get all the id information
id_data = {}
for id_field in id_fields:
if id_field in data:
Expand All @@ -134,13 +140,15 @@ def build_csv_jscode(event):
'"', '\\"'
) # Escape newlines and double quotes

get_missing = missing_selector.value == 'Missing'
missing_text = 'missing' if get_missing else 'present'

if not mid_selector.value == " ":
filename = f"{top_selector.value}-{mid_selector.value}-missing.csv"
filename = f"{top_selector.value}-{mid_selector.value}-{missing_text}.csv"
else:
filename = f"{top_selector.value}-missing.csv"
filename = f"{top_selector.value}-{missing_text}.csv"

js_code = f"""
console.log('here');
var text = "{csv_escaped}";
var blob = new Blob([text], {{ type: 'text/plain' }});
Expand Down Expand Up @@ -210,7 +218,7 @@ def build_mid(selected):
option_list = [" "] + list(mid_list[0].keys())
mid_selector.options = option_list

return pn.panel(chart)
return pn.pane.Vega(chart)


header = """
Expand All @@ -223,7 +231,7 @@ def build_mid(selected):

# Left column (controls)
left_col = pn.Column(
header_pane, top_selector, mid_selector, download_button, width=400
header_pane, top_selector, mid_selector, missing_selector, download_button, width=400
)

mid_plot = pn.bind(build_mid, selected=top_selector)
Expand Down
5 changes: 3 additions & 2 deletions src/aind_metadata_viz/metadata_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def check_present(key: str, object: dict):
def check_present(key: str, object: dict, check_present: bool = True):
"""Return true if the value of a key exists and is not None, or any of
'' [] {} in a JSON object
Expand All @@ -9,14 +9,15 @@ def check_present(key: str, object: dict):
object : dict
Dictionary
"""
return (
present = (
object[key] is not None
and object[key] != ""
and object[key] != []
and object[key] != {}
if key in object
else False
)
return present if check_present else not present


def process_present_dict(data: dict, expected_fields: list):
Expand Down

0 comments on commit 5e1bbd1

Please sign in to comment.