diff --git a/service/src/main/inse/dashboard/model.py b/service/src/main/inse/dashboard/model.py index 272125ba..426c1402 100644 --- a/service/src/main/inse/dashboard/model.py +++ b/service/src/main/inse/dashboard/model.py @@ -28,7 +28,6 @@ class TopAuthorStatistics(BaseModel): institution_id: str works: list[TopAuthor] eu_projects: list[TopAuthor] - projects: list[TopAuthor] patents: list[TopAuthor] news: list[TopAuthor] diff --git a/service/src/main/inse/dashboard/service.py b/service/src/main/inse/dashboard/service.py index 8d6da399..6eed3b80 100644 --- a/service/src/main/inse/dashboard/service.py +++ b/service/src/main/inse/dashboard/service.py @@ -349,11 +349,6 @@ async def get_top_authors( _top_eu_project_publication_authors(normalized_id, aliases), ) - projects = await _safe_top_authors( - "projects", - _top_project_authors(authors, aliases), - ) - patents = await _safe_top_authors( "patents", _top_patent_authors(normalized_id), @@ -368,7 +363,6 @@ async def get_top_authors( institution_id=normalized_id, works=works, eu_projects=eu_projects, - projects=projects, patents=patents, news=news, ) @@ -830,92 +824,6 @@ async def _institution_authors(institution_id: str) -> list[dict[str, Any]]: ] -async def _top_project_authors( - authors: list[dict[str, Any]], - aliases: list[str], -) -> list[TopAuthor]: - if not aliases: - return [] - counts: dict[str, int] = {} - names: dict[str, str] = {} - for bucket in await _top_dfg_project_author_buckets(aliases): - key = str(bucket.get("key", "")).strip() - if key: - normalized_key = key.casefold() - names[normalized_key] = key - counts[normalized_key] = counts.get(normalized_key, 0) + int( - bucket.get("doc_count", 0) - ) - - institution_authors = {author["name"].casefold(): author for author in authors} - ranked = sorted( - ( - (name, count) - for name, count in counts.items() - if count > 0 - ), - key=lambda item: (-item[1], names[item[0]].casefold()), - ) - return [ - TopAuthor( - id=( - _short_author_id(institution_authors[name]["id"]) - if name in institution_authors - else None - ), - name=( - institution_authors[name]["name"] - if name in institution_authors - else names[name] - ), - count=count, - ) - for name, count in ranked[:TOP_AUTHOR_LIMIT] - ] - - -async def _top_dfg_project_author_buckets( - aliases: list[str], -) -> list[dict[str, Any]]: - response = await elasticsearch.search( - index=ESIndex.DFG_PROJECTS, - body={ - "size": 0, - "query": _dfg_institution_query(aliases), - "aggs": { - "people": { - "terms": { - "script": { - "lang": "painless", - "source": _dfg_involved_persons_script(), - }, - "size": 10000, - } - } - }, - }, - cluster=ESCluster.INSE, - ) - return ( - response.get("aggregations", {}).get("people", {}).get("buckets", []) - ) - - -def _dfg_involved_persons_script() -> str: - return ( - "def names = new HashSet(); " - "def value = params['_source'].containsKey('Beteiligte Personen') " - " ? params['_source']['Beteiligte Personen'] : null; " - "if (value instanceof String && value.length() > 0) { " - " for (name in value.splitOnToken(';')) { " - " def trimmed = name.trim(); " - " if (trimmed.length() > 0) { names.add(trimmed); } " - " } " - "} " - "return new ArrayList(names);" - ) - - async def _top_patent_authors(institution_id: str) -> list[TopAuthor]: client = OrgPatentsSearchClient() authors = await client.top_authors_by_institution( diff --git a/service/src/main/inse/dashboard/test_service.py b/service/src/main/inse/dashboard/test_service.py index 855b1b0a..6f6977a9 100644 --- a/service/src/main/inse/dashboard/test_service.py +++ b/service/src/main/inse/dashboard/test_service.py @@ -292,11 +292,6 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects(): {"id": "A2", "name": "Grace Example", "count": 2}, {"id": "A1", "name": "Ada Example", "count": 1}, ] - assert result.projects[0].model_dump() == { - "id": "A2", - "name": "Grace Example", - "count": 3, - } assert result.news[0].model_dump() == { "id": "A1", "name": "Ada Example", @@ -309,14 +304,7 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects(): if call.kwargs["index"] in {ESIndex.DFG_PROJECTS, ESIndex.PROJECTS_BUND_V1} ] - assert len(project_calls) == 1 - assert project_calls[0].kwargs["index"] == ESIndex.DFG_PROJECTS - assert project_calls[0].kwargs["body"]["query"]["bool"][ - "minimum_should_match" - ] == 1 - assert "Beteiligte Personen" in project_calls[0].kwargs["body"]["aggs"][ - "people" - ]["terms"]["script"]["source"] + assert project_calls == [] eu_calls = [ call @@ -492,134 +480,6 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i ] -@pytest.mark.anyio -async def test_top_authors_keeps_dfg_project_authors_without_openalex_match(): - async def search(**kwargs): - if kwargs["index"] == ESIndex.OPENALEX_AUTHORS: - return {"hits": {"hits": []}} - if kwargs["index"] == ESIndex.DFG_PROJECTS: - return { - "aggregations": { - "people": { - "buckets": [{"key": "Project Person", "doc_count": 9}] - } - } - } - return {"aggregations": {"people": {"buckets": []}}} - - with patch( - "inse.dashboard.service.elasticsearch.search", - new=AsyncMock(side_effect=search), - ), patch( - "inse.dashboard.service.InstitutionsSearchClient.get_institution_aliases_by_oa_institution_id", - new=AsyncMock(return_value=["Example University"]), - ), patch( - "inse.dashboard.service.get_eu_organization_project_contributions", - new=AsyncMock(return_value=SimpleNamespace(elements=[])), - ), patch( - "inse.dashboard.service.OrgPatentsSearchClient.top_authors_by_institution", - new=AsyncMock(return_value=[]), - ): - result = await get_top_authors(ORG_INSTITUTION_ID, "Example Org") - - assert result.projects[0].model_dump() == { - "id": None, - "name": "Project Person", - "count": 9, - } - - -@pytest.mark.anyio -async def test_top_authors_returns_top_ten_dfg_project_people_by_project_count(): - async def search(**kwargs): - if kwargs["index"] == ESIndex.OPENALEX_AUTHORS: - return {"hits": {"hits": []}} - if kwargs["index"] == ESIndex.DFG_PROJECTS: - return { - "aggregations": { - "people": { - "buckets": [ - {"key": f"Project Person {count}", "doc_count": count} - for count in range(1, 12) - ] - } - } - } - return {"aggregations": {"people": {"buckets": []}}} - - with patch( - "inse.dashboard.service.elasticsearch.search", - new=AsyncMock(side_effect=search), - ), patch( - "inse.dashboard.service.InstitutionsSearchClient.get_institution_aliases_by_oa_institution_id", - new=AsyncMock(return_value=["Example University"]), - ), patch( - "inse.dashboard.service.get_eu_organization_project_contributions", - new=AsyncMock(return_value=SimpleNamespace(elements=[])), - ), patch( - "inse.dashboard.service.OrgPatentsSearchClient.top_authors_by_institution", - new=AsyncMock(return_value=[]), - ): - result = await get_top_authors(ORG_INSTITUTION_ID, "Example Org") - - assert [author.count for author in result.projects] == list(range(11, 1, -1)) - assert result.projects[0].name == "Project Person 11" - assert len(result.projects) == 10 - - -@pytest.mark.anyio -async def test_top_authors_combines_dfg_involved_people_case_insensitively(): - async def search(**kwargs): - if kwargs["index"] == ESIndex.OPENALEX_AUTHORS: - return { - "hits": { - "hits": [ - { - "_source": { - "id": "https://openalex.org/A1", - "display_name": "Ada Example", - "works_count": 1, - "counts_by_year": [], - } - } - ] - } - } - if kwargs["index"] == ESIndex.DFG_PROJECTS: - return { - "aggregations": { - "people": { - "buckets": [ - {"key": "Ada Example", "doc_count": 2}, - {"key": "ada example", "doc_count": 3}, - {"key": "DFG Person", "doc_count": 4}, - ] - } - } - } - return {"aggregations": {"authors": {"buckets": []}}} - - with patch( - "inse.dashboard.service.elasticsearch.search", - new=AsyncMock(side_effect=search), - ), patch( - "inse.dashboard.service.InstitutionsSearchClient.get_institution_aliases_by_oa_institution_id", - new=AsyncMock(return_value=["Example University"]), - ), patch( - "inse.dashboard.service.get_eu_organization_project_contributions", - new=AsyncMock(return_value=SimpleNamespace(elements=[])), - ), patch( - "inse.dashboard.service.OrgPatentsSearchClient.top_authors_by_institution", - new=AsyncMock(return_value=[]), - ): - result = await get_top_authors(ORG_INSTITUTION_ID, "Example Org") - - assert [author.model_dump() for author in result.projects] == [ - {"id": "A1", "name": "Ada Example", "count": 5}, - {"id": None, "name": "DFG Person", "count": 4}, - ] - - @pytest.mark.anyio async def test_top_authors_returns_partial_response_when_one_source_fails(): async def search(**kwargs): diff --git a/webapp/src/app/api/model/topAuthorStatistics.ts b/webapp/src/app/api/model/topAuthorStatistics.ts index 5437d1be..3d06243b 100644 --- a/webapp/src/app/api/model/topAuthorStatistics.ts +++ b/webapp/src/app/api/model/topAuthorStatistics.ts @@ -13,7 +13,6 @@ export interface TopAuthorStatistics { institution_id: string; works: Array; eu_projects: Array; - projects: Array; patents: Array; news: Array; } diff --git a/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts b/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts index df6588ad..aa23dd73 100644 --- a/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts +++ b/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts @@ -33,7 +33,6 @@ export interface TopAuthorStatistics { institution_id: string; works: TopAuthor[]; eu_projects: TopAuthor[]; - projects: TopAuthor[]; patents: TopAuthor[]; news: TopAuthor[]; } diff --git a/webapp/src/app/modules/dashboard/dashboard.component.ts b/webapp/src/app/modules/dashboard/dashboard.component.ts index 96c29d51..b91ee6df 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.ts +++ b/webapp/src/app/modules/dashboard/dashboard.component.ts @@ -110,11 +110,6 @@ export class DashboardComponent implements OnInit { icon: 'public', entries: this.topAuthors?.eu_projects ?? [], }, - { - title: 'DFG-Projekte', - icon: 'account_balance', - entries: this.topAuthors?.projects ?? [], - }, { title: 'Patente', icon: 'description',