fix(dashboard): support multiple institutions and improve project analytics
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-08-17 16:32:50 +02:00
parent a6c4668d13
commit c8e5a65f5d
2 changed files with 3 additions and 21 deletions
@@ -1081,11 +1081,11 @@ def test_eu_author_count_groups_multiple_publications_by_project_id():
works_response,
doi_project_ids,
ORG_INSTITUTION_ID,
{"https://openalex.org/A5007170803"},
)
assert [author.model_dump() for author in result] == [
{"id": "A5007170803", "name": "Marcus Example", "count": 1}
{"id": "A999", "name": "External Example", "count": 1},
{"id": "A5007170803", "name": "Marcus Example", "count": 1},
]
@@ -79,7 +79,6 @@ async def get_top_authors(
"eu_projects",
_top_eu_project_publication_authors(
normalized_id,
authors,
from_year=period[0],
to_year=period[1],
),
@@ -152,12 +151,10 @@ async def get_top_eu_project_authors(
) -> TopAuthorAnalysis:
normalized_id = _normalize_institution_id(institution_id)
period = _period(from_year=from_year, to_year=to_year)
authors = await _safe_institution_authors(normalized_id)
return TopAuthorAnalysis(
institution_id=normalized_id,
authors=await _top_eu_project_publication_authors(
normalized_id,
authors,
from_year=period[0],
to_year=period[1],
),
@@ -825,18 +822,9 @@ async def _top_patent_authors(
async def _top_eu_project_publication_authors(
institution_id: str,
institution_authors: list[dict[str, Any]],
from_year: int | None = None,
to_year: int | None = None,
) -> list[TopAuthor]:
institution_author_ids = {
author_id
for author in institution_authors
if (author_id := _normalize_author_id(author.get("id")))
}
if not institution_author_ids:
return []
# Candidate discovery is deliberately all-time. The selected period is
# applied to each person's authoritative project count below. Otherwise a
# person can disappear merely because their recent projects have no linked
@@ -889,7 +877,6 @@ async def _top_eu_project_publication_authors(
works_response,
doi_project_ids,
institution_id,
institution_author_ids,
limit=None,
)
ranked = await _count_eu_projects_for_candidates(
@@ -976,7 +963,6 @@ def _openalex_work_authors_by_eu_projects(
response: dict[str, Any],
doi_project_ids: dict[str, set[str]],
institution_id: str,
institution_author_ids: set[str],
limit: int | None = TOP_AUTHOR_LIMIT,
) -> list[TopAuthor]:
# Count unique CORDIS projects per author, not publications. Multiple works
@@ -999,11 +985,7 @@ def _openalex_work_authors_by_eu_projects(
author = authorship.get("author") or {}
author_id = _normalize_author_id(author.get("id"))
author_name = str(author.get("display_name") or "").strip()
if (
not author_id
or author_id not in institution_author_ids
or not author_name
):
if not author_id or not author_name:
continue
author_project_ids[author_id].update(project_ids)
author_names.setdefault(author_id, author_name)