Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add city field to research_organizations table #34

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/alexandria3k/data_sources/ror.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ def __init__(self, name, **kwargs):
ColumnMeta("name", lambda row: row["name"]),
ColumnMeta("status", lambda row: row["status"]),
ColumnMeta("established", lambda row: row["established"]),
ColumnMeta(
"country_code", lambda row: row["country"]["country_code"]
),
# Although deprecated, we are adding it as an additional organization identifier, as
# it provides useful to determine the ground truth data. Some organizations may not
# have a GRID identifier, so we need to make sure it doesn't raise any errors.
Expand All @@ -202,6 +199,23 @@ def __init__(self, name, **kwargs):
.get("GRID", {})
.get("all"),
),
# Each research organization has only 1 address. They have been folded into this table.
# This is a simplified address schema. Add more field when ROR settles it.
ColumnMeta(
"address_city", lambda row: row["addresses"][0]["city"]
),
ColumnMeta(
"address_state", lambda row: row["addresses"][0]["state"]
),
ColumnMeta(
"address_postcode", lambda row: row["addresses"][0]["postcode"]
),
ColumnMeta(
"address_country_code",
lambda row: row["country"]["country_code"],
),
ColumnMeta("address_lat", lambda row: row["addresses"][0]["lat"]),
ColumnMeta("address_lng", lambda row: row["addresses"][0]["lng"]),
],
),
RorDetailsTableMeta(
Expand Down Expand Up @@ -240,19 +254,6 @@ def __init__(self, name, **kwargs):
ColumnMeta("ror_path", lambda row: row["id"][16:]),
],
),
RorDetailsTableMeta(
"ror_addresses",
extract_multiple=lambda row: row["addresses"],
columns=[
# ROR will simplify the current address schema.
# Add more fields when ROR settles it.
ColumnMeta("lat", lambda row: row["lat"]),
ColumnMeta("lng", lambda row: row["lng"]),
ColumnMeta("city", lambda row: row["city"]),
ColumnMeta("state", lambda row: row["state"]),
ColumnMeta("postcode", lambda row: row["postcode"]),
],
),
# OrgRef is deprecated, so we are not supporting this field
RorDetailsTableMeta(
"ror_funder_ids",
Expand Down
49 changes: 24 additions & 25 deletions tests/data_sources/test_ror.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,26 @@ def test_organization(self):
name,
status,
established,
country_code,
grid,
city,
state,
postcode,
country_code,
latitude,
longitude,
) = result.fetchone()
self.assertEqual(id, 0)
self.assertEqual(ror_path, "019wvm592")
self.assertEqual(name, "Australian National University")
self.assertEqual(status, "active")
self.assertEqual(established, 1946)
self.assertEqual(country_code, "AU")
self.assertEqual(grid, "grid.1001.0")
self.assertEqual(city, "Canberra")
self.assertEqual(state, "Australian Capital Territory")
self.assertEqual(postcode, None)
self.assertEqual(country_code, "AU")
self.assertEqual(latitude, -35.2778)
self.assertEqual(longitude, 149.1205)

def test_blank_external_ids(self):
result = TestRorPopulate.cursor.execute(
Expand All @@ -92,16 +102,26 @@ def test_blank_external_ids(self):
name,
status,
established,
country_code,
grid,
city,
state,
postcode,
country_code,
latitude,
longitude,
) = result.fetchone()
self.assertEqual(id, 28)
self.assertEqual(ror_path, "02f4ks689")
self.assertEqual(name, "Axiom Data Science")
self.assertEqual(status, "active")
self.assertEqual(established, 2007)
self.assertEqual(country_code, "US")
self.assertEqual(grid, None)
self.assertEqual(city, "Anchorage")
self.assertEqual(state, None)
self.assertEqual(postcode, None)
self.assertEqual(country_code, "US")
self.assertEqual(latitude, 61.21806)
self.assertEqual(longitude, -149.90028)

def test_funder_ids(self):
result = TestRorPopulate.cursor.execute(
Expand Down Expand Up @@ -179,27 +199,6 @@ def test_ror_relationships(self):
in rows
)

def test_ror_addresses(self):
result = TestRorPopulate.cursor.execute(
"""SELECT * FROM ror_addresses WHERE ror_id=(
SELECT id FROM research_organizations WHERE
ror_path='02bfwt286')"""
)
rows = list(result)
self.assertEqual(len(rows), 1)
self.assertTrue(
(
16384,
1,
-37.9083,
145.138,
"Melbourne",
"Victoria",
None,
)
in rows
)

def test_ror_wikidata_ids(self):
result = TestRorPopulate.cursor.execute(
"""SELECT wikidata_id FROM ror_wikidata_ids WHERE ror_id=(
Expand Down