Skip to content

Commit

Permalink
fix: parses latest funding schema (#226)
Browse files Browse the repository at this point in the history
* fix: parses latest funding schema

* build: adds upper bound to aind-data-schema
  • Loading branch information
jtyoung84 authored Jan 12, 2025
1 parent 8f39da9 commit 2da7148
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ all = [
]

schema = [
"aind-data-schema>=1.2.0,<2.0",
"aind-data-schema>=1.2.0,<1.3.0",
]

bergamo = [
Expand Down
21 changes: 13 additions & 8 deletions src/aind_metadata_mapper/gather_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,28 @@ def get_funding_info(domain: str, url_path: str, project_name: str):
else:
funding_info = []
investigators = set()
parsed_funding_info = []
for f in funding_info:
project_fundees = (
project_investigators = (
""
if f.get("fundee", None) is None
else f.get("fundee", "").split(",")
if f.get("investigators", None) is None
else f.get("investigators", "").split(",")
)
pid_names = [
investigators_pid_names = [
PIDName(name=p.strip()).model_dump_json()
for p in project_fundees
for p in project_investigators
]
if project_fundees is not [""]:
investigators.update(pid_names)
if project_investigators is not [""]:
investigators.update(investigators_pid_names)
funding_info_without_investigators = {
k: v for k, v in f.items() if k != "investigators"
}
parsed_funding_info.append(funding_info_without_investigators)
investigators = [
PIDName.model_validate_json(i) for i in investigators
]
investigators.sort(key=lambda x: x.name)
return funding_info, investigators
return parsed_funding_info, investigators

# Returns a dict with platform, subject_id, and acq_datetime
file_name = RawDataDescription.default_filename()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"registry_identifier": "03cpe7c52"
},
"grant_number": null,
"fundee": "Anna Apple, John Smith"
"fundee": "Anna Apple, John Smith",
"investigators": "Anna Apple"
},
{
"funder": {
Expand All @@ -25,7 +26,8 @@
"registry_identifier": "01s5ya894"
},
"grant_number": "1U01NS133760",
"fundee": "Anna Apple, John Smith, Don Key"
"fundee": "Anna Apple, John Smith, Don Key",
"investigators": null
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"registry_identifier": "03cpe7c52"
},
"grant_number": null,
"fundee": "Anna Apple, John Smith"
"fundee": "Anna Apple, John Smith",
"investigators": "Anna Apple"
}
}
8 changes: 5 additions & 3 deletions tests/test_gather_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_get_raw_data_description(self, mock_get: MagicMock):
)
metadata_job = GatherMetadataJob(settings=job_settings)
contents = metadata_job.get_raw_data_description()
expected_investigators = ["Anna Apple", "John Smith"]
expected_investigators = ["Anna Apple"]
actual_investigators = [i["name"] for i in contents["investigators"]]
self.assertEqual(expected_investigators, actual_investigators)
self.assertEqual("ecephys", contents["platform"]["abbreviation"])
Expand Down Expand Up @@ -360,7 +360,7 @@ def test_get_raw_data_description_multi_response(
)
metadata_job = GatherMetadataJob(settings=job_settings)
contents = metadata_job.get_raw_data_description()
expected_investigators = ["Anna Apple", "Don Key", "John Smith"]
expected_investigators = ["Anna Apple"]
actual_investigators = [i["name"] for i in contents["investigators"]]
self.assertEqual(2, len(contents["funding_source"]))
self.assertEqual(expected_investigators, actual_investigators)
Expand Down Expand Up @@ -782,7 +782,8 @@ def test_gather_non_automated_metadata_with_ser_issues(
metadata_job._gather_non_automated_metadata()
mock_write_file.assert_called()

def test_get_main_metadata_with_warnings(self):
@patch("logging.warning")
def test_get_main_metadata_with_warnings(self, mock_warn: MagicMock):
"""Tests get_main_metadata method raises validation warnings"""
job_settings = JobSettings(
directory_to_write_to=RESOURCES_DIR,
Expand Down Expand Up @@ -812,6 +813,7 @@ def test_get_main_metadata_with_warnings(self):
)
self.assertEqual("Missing", main_metadata["metadata_status"])
self.assertEqual("632269", main_metadata["subject"]["subject_id"])
mock_warn.assert_called_once()

@patch("logging.warning")
def test_get_main_metadata_with_ser_issues(self, mock_log: MagicMock):
Expand Down

0 comments on commit 2da7148

Please sign in to comment.