Verify EU author counts by unique project

This commit is contained in:
2026-07-21 09:20:07 +02:00
parent 9ac618ebec
commit a7ced052dd
2 changed files with 74 additions and 12 deletions
@@ -943,6 +943,8 @@ def _openalex_work_authors_by_eu_projects(
doi_project_ids: dict[str, set[str]],
institution_id: str,
) -> list[TopAuthor]:
# Count unique CORDIS projects per author, not publications. Multiple works
# (and therefore multiple DOIs) can belong to the same project ID.
author_project_ids: dict[str, set[str]] = defaultdict(set)
author_names: dict[str, str] = {}
+72 -12
View File
@@ -9,6 +9,7 @@ from sqlmodel import Session, SQLModel, create_engine
from inse import config
from inse.auth.model import AccessToken, Organization, UserRole
from inse.dashboard.service import (
_openalex_work_authors_by_eu_projects,
get_dashboard_organization,
get_dashboard_statistics,
get_top_authors,
@@ -174,7 +175,7 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
}
}
}
if kwargs["index"] == ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD:
if kwargs["index"] == ESIndex.CORDIS_EU_FP7_PUBLICATIONS:
return {
"hits": {
"hits": [
@@ -215,13 +216,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}],
},
],
}
@@ -234,7 +237,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}],
}
],
}
@@ -306,7 +310,7 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
eu_calls = [
call
for call in mocked_search.await_args_list
if call.kwargs["index"] == ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD
if call.kwargs["index"] == ESIndex.CORDIS_EU_FP7_PUBLICATIONS
]
assert len(eu_calls) == 1
@@ -326,7 +330,7 @@ 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",
]
@@ -334,6 +338,58 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
"doi",
"authorships.author.id",
"authorships.author.display_name",
"authorships.institutions.id",
]
def test_eu_author_count_groups_multiple_publications_by_project_id():
works_response = {
"hits": {
"hits": [
{
"_source": {
"doi": "https://doi.org/10.1/marcus-a",
"authorships": [
{
"author": {
"id": "https://openalex.org/A5007170803",
"display_name": "Marcus Example",
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
],
}
},
{
"_source": {
"doi": "https://doi.org/10.1/marcus-b",
"authorships": [
{
"author": {
"id": "https://openalex.org/A5007170803",
"display_name": "Marcus Example",
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
],
}
},
]
}
}
doi_project_ids = {
"https://doi.org/10.1/marcus-a": {"P1"},
"https://doi.org/10.1/marcus-b": {"P1"},
}
result = _openalex_work_authors_by_eu_projects(
works_response,
doi_project_ids,
ORG_INSTITUTION_ID,
)
assert [author.model_dump() for author in result] == [
{"id": "A5007170803", "name": "Marcus Example", "count": 1}
]
@@ -342,7 +398,7 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
async def search(**kwargs):
if kwargs["index"] == ESIndex.OPENALEX_AUTHORS:
return {"hits": {"hits": []}}
if kwargs["index"] == ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD:
if kwargs["index"] == ESIndex.CORDIS_EU_FP7_PUBLICATIONS:
assert kwargs["body"]["query"] == {
"terms": {"projectID": ["P1", "P2"]}
}
@@ -358,7 +414,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",
@@ -374,13 +430,15 @@ 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}],
},
],
}
@@ -393,7 +451,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}],
}
],
}
@@ -406,7 +465,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}],
}
],
}