From f384820370802f7e605610c7d13e999833a8d98e Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:38:41 -0400 Subject: [PATCH 1/5] Update neuroconv.py --- pyflask/apis/neuroconv.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pyflask/apis/neuroconv.py b/pyflask/apis/neuroconv.py index 62028e365..cdd4de17e 100644 --- a/pyflask/apis/neuroconv.py +++ b/pyflask/apis/neuroconv.py @@ -68,7 +68,7 @@ def post(self): @neuroconv_api.route("/locate") -class Locate(Resource): +class LocateData(Resource): @neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) def post(self): try: @@ -79,7 +79,7 @@ def post(self): @neuroconv_api.route("/locate/autocomplete") -class Locate(Resource): +class AutoCompleteFormatString(Resource): @neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) def post(self): try: @@ -93,12 +93,11 @@ def post(self): class Metadata(Resource): @neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) def post(self): - # try: - return get_metadata_schema(neuroconv_api.payload.get("source_data"), neuroconv_api.payload.get("interfaces")) - - # except Exception as exception: - # if notBadRequestException(exception): - # neuroconv_api.abort(500, str(exception)) + try: + return get_metadata_schema(neuroconv_api.payload.get("source_data"), neuroconv_api.payload.get("interfaces")) + except Exception as exception: + if notBadRequestException(exception): + neuroconv_api.abort(500, str(exception)) @neuroconv_api.route("/convert") From 78b220df1b189309a68fae25d285256841c5b286 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:39:44 -0400 Subject: [PATCH 2/5] add encoder --- pyflask/manageNeuroconv/manage_neuroconv.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyflask/manageNeuroconv/manage_neuroconv.py b/pyflask/manageNeuroconv/manage_neuroconv.py index 8dadce731..d31977d90 100644 --- a/pyflask/manageNeuroconv/manage_neuroconv.py +++ b/pyflask/manageNeuroconv/manage_neuroconv.py @@ -134,7 +134,8 @@ def coerce_schema_compliance_recursive(obj, schema): def autocomplete_format_string(info: dict) -> str: from neuroconv.tools.path_expansion import construct_path_template - + from neuroconv.utils.json_schema import NWBMetaDataEncoder + base_directory = info["base_directory"] filesystem_entry_path = info["path"] @@ -162,7 +163,7 @@ def autocomplete_format_string(info: dict) -> str: all_matched = locate_data(dict(autocomplete=to_locate_info)) - return dict(matched=all_matched, format_string=format_string) + return json.dumps(obj=dict(matched=all_matched, format_string=format_string), cls=NWBMetaDataEncoder) def locate_data(info: dict) -> dict: From 28af76520be0f07cf72497d15d16360144ea19c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:41:17 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pyflask/apis/neuroconv.py | 4 +++- pyflask/manageNeuroconv/manage_neuroconv.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyflask/apis/neuroconv.py b/pyflask/apis/neuroconv.py index cdd4de17e..abbb20fc4 100644 --- a/pyflask/apis/neuroconv.py +++ b/pyflask/apis/neuroconv.py @@ -94,7 +94,9 @@ class Metadata(Resource): @neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) def post(self): try: - return get_metadata_schema(neuroconv_api.payload.get("source_data"), neuroconv_api.payload.get("interfaces")) + return get_metadata_schema( + neuroconv_api.payload.get("source_data"), neuroconv_api.payload.get("interfaces") + ) except Exception as exception: if notBadRequestException(exception): neuroconv_api.abort(500, str(exception)) diff --git a/pyflask/manageNeuroconv/manage_neuroconv.py b/pyflask/manageNeuroconv/manage_neuroconv.py index d31977d90..21791cd57 100644 --- a/pyflask/manageNeuroconv/manage_neuroconv.py +++ b/pyflask/manageNeuroconv/manage_neuroconv.py @@ -135,7 +135,7 @@ def coerce_schema_compliance_recursive(obj, schema): def autocomplete_format_string(info: dict) -> str: from neuroconv.tools.path_expansion import construct_path_template from neuroconv.utils.json_schema import NWBMetaDataEncoder - + base_directory = info["base_directory"] filesystem_entry_path = info["path"] From fc522631a33e1ec3f8d007a00c69b434243fb364 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:05:09 -0400 Subject: [PATCH 4/5] try here too --- pyflask/manageNeuroconv/manage_neuroconv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyflask/manageNeuroconv/manage_neuroconv.py b/pyflask/manageNeuroconv/manage_neuroconv.py index 21791cd57..73708eab7 100644 --- a/pyflask/manageNeuroconv/manage_neuroconv.py +++ b/pyflask/manageNeuroconv/manage_neuroconv.py @@ -169,6 +169,7 @@ def autocomplete_format_string(info: dict) -> str: def locate_data(info: dict) -> dict: """Locate data from the specifies directories using fstrings.""" from neuroconv.tools import LocalPathExpander + from neuroconv.utils.json_schema import NWBMetaDataEncoder expander = LocalPathExpander() @@ -192,7 +193,7 @@ def locate_data(info: dict) -> dict: organized_output[subject_id][session_id] = item - return organized_output + return json.dumps(obj=organized_output, cls=NWBMetaDataEncoder) def module_to_dict(my_module): From 44374180d277b0dabf04f1ed7f941e7825f81f53 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Mon, 18 Mar 2024 08:33:24 -0700 Subject: [PATCH 5/5] Ensure json is reloaded --- pyflask/manageNeuroconv/manage_neuroconv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyflask/manageNeuroconv/manage_neuroconv.py b/pyflask/manageNeuroconv/manage_neuroconv.py index 73708eab7..ee137a943 100644 --- a/pyflask/manageNeuroconv/manage_neuroconv.py +++ b/pyflask/manageNeuroconv/manage_neuroconv.py @@ -163,7 +163,7 @@ def autocomplete_format_string(info: dict) -> str: all_matched = locate_data(dict(autocomplete=to_locate_info)) - return json.dumps(obj=dict(matched=all_matched, format_string=format_string), cls=NWBMetaDataEncoder) + return json.loads(json.dumps(obj=dict(matched=all_matched, format_string=format_string), cls=NWBMetaDataEncoder)) def locate_data(info: dict) -> dict: @@ -193,7 +193,7 @@ def locate_data(info: dict) -> dict: organized_output[subject_id][session_id] = item - return json.dumps(obj=organized_output, cls=NWBMetaDataEncoder) + return json.loads(json.dumps(obj=organized_output, cls=NWBMetaDataEncoder)) def module_to_dict(my_module):