fix organsaition id
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-07-20 22:50:31 +02:00
parent d3266ee50e
commit f4e0888ce2
2 changed files with 57 additions and 14 deletions
+19 -4
View File
@@ -346,7 +346,7 @@ async def get_top_authors(
eu_projects = await _safe_top_authors(
"eu_projects",
_top_eu_project_publication_authors(aliases),
_top_eu_project_publication_authors(normalized_id, aliases),
)
patents = await _safe_top_authors(
@@ -841,6 +841,7 @@ async def _top_patent_authors(institution_id: str) -> list[TopAuthor]:
async def _top_eu_project_publication_authors(
institution_id: str,
organization_names: list[str],
) -> list[TopAuthor]:
project_page = await get_eu_organization_project_contributions(
@@ -886,17 +887,25 @@ async def _top_eu_project_publication_authors(
"doi",
"authorships.author.id",
"authorships.author.display_name",
"authorships.institutions.id",
],
"query": {
"terms": {
"doi": sorted(doi_project_ids),
"bool": {
"filter": [
{"terms": {"doi": sorted(doi_project_ids)}},
_institution_works_query(institution_id),
]
}
},
},
cluster=ESCluster.NES,
)
return _openalex_work_authors_by_eu_projects(works_response, doi_project_ids)
return _openalex_work_authors_by_eu_projects(
works_response,
doi_project_ids,
institution_id,
)
def _cordis_publication_doi_project_ids(
@@ -932,6 +941,7 @@ def _normalize_doi(value: Any) -> str | None:
def _openalex_work_authors_by_eu_projects(
response: dict[str, Any],
doi_project_ids: dict[str, set[str]],
institution_id: str,
) -> list[TopAuthor]:
author_project_ids: dict[str, set[str]] = defaultdict(set)
author_names: dict[str, str] = {}
@@ -943,6 +953,11 @@ def _openalex_work_authors_by_eu_projects(
continue
for authorship in source.get("authorships") or []:
if not any(
institution.get("id") == institution_id
for institution in authorship.get("institutions") or []
):
continue
author = authorship.get("author") or {}
author_id = _normalize_author_id(author.get("id"))
author_name = str(author.get("display_name") or "").strip()
+38 -10
View File
@@ -208,13 +208,15 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
"author": {
"id": "https://openalex.org/A2",
"display_name": "Grace Example",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
},
{
"author": {
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
},
],
}
@@ -227,7 +229,8 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
"author": {
"id": "https://openalex.org/A2",
"display_name": "Grace Example",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
],
}
@@ -322,14 +325,25 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
]
assert len(works_calls) == 1
works_body = works_calls[0].kwargs["body"]
assert works_body["query"]["terms"]["doi"] == [
assert works_body["query"]["bool"]["filter"][0]["terms"]["doi"] == [
"https://doi.org/10.1234/p1",
"https://doi.org/10.1234/p2",
]
assert works_body["query"]["bool"]["filter"][1] == {
"nested": {
"path": "authorships.institutions",
"query": {
"term": {
"authorships.institutions.id": ORG_INSTITUTION_ID,
}
},
}
}
assert works_body["_source"] == [
"doi",
"authorships.author.id",
"authorships.author.display_name",
"authorships.institutions.id",
]
@@ -355,7 +369,7 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
}
if kwargs["index"] == config.settings.openalex_works_search_index:
assert kwargs["body"]["query"]["terms"]["doi"] == [
assert kwargs["body"]["query"]["bool"]["filter"][0]["terms"]["doi"] == [
"https://doi.org/10.1/p1-a",
"https://doi.org/10.1/p1-b",
"https://doi.org/10.1/p2",
@@ -371,13 +385,24 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
"author": {
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
},
{
"author": {
"id": "https://openalex.org/A2",
"display_name": "Grace Example",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
},
{
"author": {
"id": "https://openalex.org/A3",
"display_name": "External Author",
},
"institutions": [
{"id": "https://openalex.org/I999"}
],
},
],
}
@@ -390,7 +415,8 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
"author": {
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
],
}
@@ -403,7 +429,8 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
"author": {
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
],
}
@@ -416,7 +443,8 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
"author": {
"id": "https://openalex.org/A999",
"display_name": "Outside Author",
}
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
],
}