Skip to content

Commit

Permalink
Merge pull request #686 from NeurodataWithoutBorders/add_json_encodin…
Browse files Browse the repository at this point in the history
…g_fstring

Add json encoding to fstring autocompletion
  • Loading branch information
CodyCBakerPhD authored Mar 18, 2024
2 parents 2792495 + 09018a6 commit 83a1407
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 9 additions & 8 deletions pyflask/apis/neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -93,12 +93,13 @@ 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")
Expand Down
6 changes: 4 additions & 2 deletions pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,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"]
Expand Down Expand Up @@ -162,12 +163,13 @@ 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.loads(json.dumps(obj=dict(matched=all_matched, format_string=format_string), cls=NWBMetaDataEncoder))


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()

Expand All @@ -191,7 +193,7 @@ def locate_data(info: dict) -> dict:

organized_output[subject_id][session_id] = item

return organized_output
return json.loads(json.dumps(obj=organized_output, cls=NWBMetaDataEncoder))


def module_to_dict(my_module):
Expand Down

0 comments on commit 83a1407

Please sign in to comment.