diff --git a/service/src/main/inse/dashboard/model.py b/service/src/main/inse/dashboard/model.py index eae2251a..ada6c020 100644 --- a/service/src/main/inse/dashboard/model.py +++ b/service/src/main/inse/dashboard/model.py @@ -54,6 +54,8 @@ class DfgProjectTopic(BaseModel): field: str | None = None domain: str | None = None project_count: int + field_project_count: int + subfield_project_count: int keywords: list[DfgProjectKeyword] @@ -65,6 +67,22 @@ class DfgProjectTopics(BaseModel): topics: list[DfgProjectTopic] +class EuProjectTopics(BaseModel): + institution_id: str + organization_name: str + project_count: int + matched_project_count: int + topics: list[DfgProjectTopic] + + +class BundProjectTopics(BaseModel): + institution_id: str + organization_name: str + project_count: int + matched_project_count: int + topics: list[DfgProjectTopic] + + class TopAuthor(BaseModel): id: str | None = None name: str diff --git a/service/src/main/inse/dashboard/router.py b/service/src/main/inse/dashboard/router.py index bd5ad49b..fb01a93a 100644 --- a/service/src/main/inse/dashboard/router.py +++ b/service/src/main/inse/dashboard/router.py @@ -10,10 +10,12 @@ from inse.tags import Tags from .model import ( BmbfProjectStatusStatistics, + BundProjectTopics, DashboardStatistics, DashboardStatisticValue, DfgProjectStatusStatistics, DfgProjectTopics, + EuProjectTopics, EuProjectStatusStatistics, TopAuthorStatistics, TopicHeatmap, @@ -22,9 +24,11 @@ from .model import ( from .service import ( get_dashboard_bmbf_project_statuses, get_dashboard_bmbf_projects, + get_dashboard_bund_topics, get_dashboard_dfg_project_statuses, get_dashboard_dfg_projects, get_dashboard_dfg_topics, + get_dashboard_eu_topics, get_dashboard_eu_project_statuses, get_dashboard_eu_projects, get_dashboard_organization, @@ -256,6 +260,46 @@ async def dashboard_dfg_project_topics( ) +@router.get( + "/projects/eu/topics", + operation_id="getDashboardEuProjectTopics", + response_model=EuProjectTopics, +) +async def dashboard_eu_project_topics( + from_year: int | None = Query(default=None, ge=1900, le=2100), + to_year: int | None = Query(default=None, ge=1900, le=2100), + session: Session = Depends(get_session), + access_token: AccessToken = auth_service.CurrentUserAccessTokenPayloadDep, +) -> EuProjectTopics: + organization = get_dashboard_organization(session, access_token) + return await get_dashboard_eu_topics( + organization.openalex_institution_id, + organization.name, + from_year=from_year, + to_year=to_year, + ) + + +@router.get( + "/projects/bund/topics", + operation_id="getDashboardBundProjectTopics", + response_model=BundProjectTopics, +) +async def dashboard_bund_project_topics( + from_year: int | None = Query(default=None, ge=1900, le=2100), + to_year: int | None = Query(default=None, ge=1900, le=2100), + session: Session = Depends(get_session), + access_token: AccessToken = auth_service.CurrentUserAccessTokenPayloadDep, +) -> BundProjectTopics: + organization = get_dashboard_organization(session, access_token) + return await get_dashboard_bund_topics( + organization.openalex_institution_id, + organization.name, + from_year=from_year, + to_year=to_year, + ) + + @router.get( "/top-authors", operation_id="getDashboardTopAuthors", diff --git a/service/src/main/inse/dashboard/service.py b/service/src/main/inse/dashboard/service.py index a0f15733..f09939ab 100644 --- a/service/src/main/inse/dashboard/service.py +++ b/service/src/main/inse/dashboard/service.py @@ -1,4 +1,5 @@ import asyncio +import hashlib import logging import re from collections import defaultdict @@ -34,12 +35,14 @@ from inse.projects.model import ( from .institute_helper import get_openalex_institution from .model import ( BmbfProjectStatusStatistics, + BundProjectTopics, DashboardStatistics, DfgProjectKeyword, DashboardStatisticValue, DfgProjectStatusStatistics, DfgProjectTopic, DfgProjectTopics, + EuProjectTopics, EuProjectStatusStatistics, TopAuthor, TopAuthorStatistics, @@ -860,6 +863,14 @@ async def get_dashboard_dfg_topics( if keyword: topic["keywords"].setdefault(keyword, set()).add(project_id) + field_project_ids: dict[str, set[str]] = defaultdict(set) + subfield_project_ids: dict[tuple[str, str], set[str]] = defaultdict(set) + for topic in topics.values(): + field_name = str(topic["field"] or "") + subfield_name = str(topic["subfield"] or "") + field_project_ids[field_name].update(topic["project_ids"]) + subfield_project_ids[(field_name, subfield_name)].update(topic["project_ids"]) + topic_list = [ DfgProjectTopic( id=topic["id"], @@ -868,6 +879,12 @@ async def get_dashboard_dfg_topics( field=topic["field"], domain=topic["domain"], project_count=len(topic["project_ids"]), + field_project_count=len(field_project_ids[str(topic["field"] or "")]), + subfield_project_count=len( + subfield_project_ids[ + (str(topic["field"] or ""), str(topic["subfield"] or "")) + ] + ), keywords=sorted( [ DfgProjectKeyword( @@ -891,6 +908,233 @@ async def get_dashboard_dfg_topics( ) +async def get_dashboard_eu_topics( + institution_id: str, + organization_name: str, + from_year: int | None = None, + to_year: int | None = None, +) -> EuProjectTopics: + normalized_id = _normalize_institution_id(institution_id) + project_ids = await _get_eu_project_ids_from_projects_service( + normalized_id, + from_year=from_year, + to_year=to_year, + ) + topics: dict[str, dict[str, Any]] = {} + matched_project_ids: set[str] = set() + + if project_ids: + mapping_indices = ( + ESIndex.PROJECTS_CORDIS_EU_FP7_TOPICS_MAPPING, + ESIndex.PROJECTS_CORDIS_EU_H2020_TOPICS, + ESIndex.PROJECTS_CORDIS_EU_HEUROPE_TOPICS, + ) + for mapping_index in mapping_indices: + async for hit in elasticsearch.scan( + index=str(mapping_index), + query={"terms": {"project_id": project_ids}}, + source=["project_id", "keyword", "topic_matches"], + page_size=1000, + cluster=ESCluster.INSE, + ): + source = hit.get("_source", {}) + project_id = str(source.get("project_id") or "") + if not project_id: + continue + keyword = str(source.get("keyword") or "").strip() + matched_project_ids.add(project_id) + for match in source.get("topic_matches", []): + topic_id = str(match.get("topic_id") or "") + if not topic_id: + continue + topic = topics.setdefault( + topic_id, + { + "id": topic_id, + "name": str(match.get("topic_display_name") or topic_id), + "subfield": match.get("subfield"), + "field": match.get("field"), + "domain": match.get("domain"), + "project_ids": set(), + "keywords": {}, + }, + ) + topic["project_ids"].add(project_id) + if keyword: + topic["keywords"].setdefault(keyword, set()).add(project_id) + + field_project_ids: dict[str, set[str]] = defaultdict(set) + subfield_project_ids: dict[tuple[str, str], set[str]] = defaultdict(set) + for topic in topics.values(): + field_name = str(topic["field"] or "") + subfield_name = str(topic["subfield"] or "") + field_project_ids[field_name].update(topic["project_ids"]) + subfield_project_ids[(field_name, subfield_name)].update(topic["project_ids"]) + + topic_list = [ + DfgProjectTopic( + id=topic["id"], + name=topic["name"], + subfield=topic["subfield"], + field=topic["field"], + domain=topic["domain"], + project_count=len(topic["project_ids"]), + field_project_count=len(field_project_ids[str(topic["field"] or "")]), + subfield_project_count=len( + subfield_project_ids[ + (str(topic["field"] or ""), str(topic["subfield"] or "")) + ] + ), + keywords=sorted( + [ + DfgProjectKeyword( + name=keyword, + project_count=len(keyword_project_ids), + ) + for keyword, keyword_project_ids in topic["keywords"].items() + ], + key=lambda entry: (-entry.project_count, entry.name), + ), + ) + for topic in topics.values() + ] + topic_list.sort(key=lambda topic: (-topic.project_count, topic.name, topic.id)) + return EuProjectTopics( + institution_id=normalized_id, + organization_name=organization_name, + project_count=len(project_ids), + matched_project_count=len(matched_project_ids), + topics=topic_list, + ) + + +async def get_dashboard_bund_topics( + institution_id: str, + organization_name: str, + from_year: int | None = None, + to_year: int | None = None, +) -> BundProjectTopics: + normalized_id = _normalize_institution_id(institution_id) + period = _dashboard_period(from_year, to_year) + page_size = 1000 + page_number = 0 + project_ids: set[str] = set() + + while True: + projects = await projects_service.search_bund_projects_with_filters( + institutions_search_client=InstitutionsSearchClient(), + executing_agency=None, + raw_oa_institution_id=_raw_institution_id(normalized_id), + title=None, + keywords=None, + funding_arts=None, + topic_ids=None, + filter_topic_ids=None, + funding_start_years=None, + funding_end_years=None, + active_from_year=period[0], + active_to_year=period[1], + countries=None, + page=page_number, + size=page_size, + sort_by="id", + sort_direction="asc", + fuzzy=False, + ) + project_ids.update( + project.funding_code + for project in projects.elements + if project.funding_code + ) + if len(project_ids) >= projects.total or not projects.elements: + break + page_number += 1 + + topics: dict[str, dict[str, Any]] = {} + matched_project_ids: set[str] = set() + if project_ids: + mapping_project_ids = sorted( + hashlib.sha256(project_id.encode("utf-8")).hexdigest() + for project_id in project_ids + ) + async for hit in elasticsearch.scan( + index=str(ESIndex.PROJECTS_BUND_TOPICS), + query={"terms": {"project_id": mapping_project_ids}}, + source=["project_id", "keyword", "topic_matches"], + page_size=1000, + cluster=ESCluster.INSE, + ): + source = hit.get("_source", {}) + project_id = str(source.get("project_id") or "") + if not project_id: + continue + keyword = str(source.get("keyword") or "").strip() + matched_project_ids.add(project_id) + for match in source.get("topic_matches", []): + topic_id = str(match.get("topic_id") or "") + if not topic_id: + continue + topic = topics.setdefault( + topic_id, + { + "id": topic_id, + "name": str(match.get("topic_display_name") or topic_id), + "subfield": match.get("subfield"), + "field": match.get("field"), + "domain": match.get("domain"), + "project_ids": set(), + "keywords": {}, + }, + ) + topic["project_ids"].add(project_id) + if keyword: + topic["keywords"].setdefault(keyword, set()).add(project_id) + + field_project_ids: dict[str, set[str]] = defaultdict(set) + subfield_project_ids: dict[tuple[str, str], set[str]] = defaultdict(set) + for topic in topics.values(): + field_name = str(topic["field"] or "") + subfield_name = str(topic["subfield"] or "") + field_project_ids[field_name].update(topic["project_ids"]) + subfield_project_ids[(field_name, subfield_name)].update(topic["project_ids"]) + + topic_list = [ + DfgProjectTopic( + id=topic["id"], + name=topic["name"], + subfield=topic["subfield"], + field=topic["field"], + domain=topic["domain"], + project_count=len(topic["project_ids"]), + field_project_count=len(field_project_ids[str(topic["field"] or "")]), + subfield_project_count=len( + subfield_project_ids[ + (str(topic["field"] or ""), str(topic["subfield"] or "")) + ] + ), + keywords=sorted( + [ + DfgProjectKeyword( + name=keyword, + project_count=len(keyword_project_ids), + ) + for keyword, keyword_project_ids in topic["keywords"].items() + ], + key=lambda entry: (-entry.project_count, entry.name), + ), + ) + for topic in topics.values() + ] + topic_list.sort(key=lambda topic: (-topic.project_count, topic.name, topic.id)) + return BundProjectTopics( + institution_id=normalized_id, + organization_name=organization_name, + project_count=len(project_ids), + matched_project_count=len(matched_project_ids), + topics=topic_list, + ) + + async def _get_dfg_project_ids_from_projects_service( institution_id: str, from_year: int | None = None, diff --git a/service/src/main/inse/dashboard/test_service.py b/service/src/main/inse/dashboard/test_service.py index effb15c5..4574fa80 100644 --- a/service/src/main/inse/dashboard/test_service.py +++ b/service/src/main/inse/dashboard/test_service.py @@ -1,4 +1,5 @@ from datetime import datetime +import hashlib from types import SimpleNamespace from unittest.mock import AsyncMock, patch @@ -15,8 +16,10 @@ from inse.dashboard.service import ( _reconcile_project_status_counts, _top_news_authors, get_dashboard_bmbf_projects, + get_dashboard_bund_topics, get_dashboard_dfg_projects, get_dashboard_eu_projects, + get_dashboard_eu_topics, get_dashboard_organization, get_dashboard_persons, get_dashboard_publications, @@ -31,6 +34,7 @@ from inse.models.openalex.meta import Meta from inse.persons.model import CustomAuthorsListResponse from inse.projects.model import ( BundProjectPage, + BundProjectSummary, DfgProjectPage, DfgProjectSummary, EuCordisProjectSearchPage, @@ -154,6 +158,155 @@ async def test_dfg_topic_project_ids_use_paginated_projects_service(): assert first_call.kwargs["funding_end_years"][0] == "2020" +@pytest.mark.anyio +async def test_eu_topics_scan_all_programme_indices_and_deduplicate_projects(): + scanned_indices: list[str] = [] + + async def scan(**kwargs): + scanned_indices.append(kwargs["index"]) + if kwargs["index"] == str(ESIndex.PROJECTS_CORDIS_EU_FP7_TOPICS_MAPPING): + yield { + "_source": { + "project_id": "P1", + "keyword": "AI", + "topic_matches": [ + { + "topic_id": "T1", + "topic_display_name": "Artificial Intelligence", + "field": "Computer Science", + "subfield": "AI", + "domain": "Physical Sciences", + } + ], + } + } + yield { + "_source": { + "project_id": "P1", + "keyword": "Robotics", + "topic_matches": [ + { + "topic_id": "T2", + "topic_display_name": "Robotics", + "field": "Computer Science", + "subfield": "Robotics", + "domain": "Physical Sciences", + } + ], + } + } + if kwargs["index"] == str(ESIndex.PROJECTS_CORDIS_EU_H2020_TOPICS): + yield { + "_source": { + "project_id": "P2", + "keyword": "AI", + "topic_matches": [ + { + "topic_id": "T1", + "topic_display_name": "Artificial Intelligence", + "field": "Computer Science", + "subfield": "AI", + "domain": "Physical Sciences", + } + ], + } + } + + with patch( + "inse.dashboard.service._get_eu_project_ids_from_projects_service", + new=AsyncMock(return_value=["P1", "P2", "P3"]), + ), patch("inse.dashboard.service.elasticsearch.scan", new=scan): + result = await get_dashboard_eu_topics( + ORG_INSTITUTION_ID, + "Example Org", + from_year=2022, + to_year=2026, + ) + + assert scanned_indices == [ + str(ESIndex.PROJECTS_CORDIS_EU_FP7_TOPICS_MAPPING), + str(ESIndex.PROJECTS_CORDIS_EU_H2020_TOPICS), + str(ESIndex.PROJECTS_CORDIS_EU_HEUROPE_TOPICS), + ] + assert result.project_count == 3 + assert result.matched_project_count == 2 + assert result.topics[0].project_count == 2 + assert result.topics[0].keywords[0].project_count == 2 + assert {topic.field_project_count for topic in result.topics} == {2} + assert {topic.name: topic.subfield_project_count for topic in result.topics} == { + "Artificial Intelligence": 2, + "Robotics": 1, + } + + +@pytest.mark.anyio +async def test_bund_topics_use_mapping_index_and_unique_hierarchy_counts(): + project_page = BundProjectPage( + elements=[ + BundProjectSummary(funding_code="B1"), + BundProjectSummary(funding_code="B2"), + ], + total=2, + page=0, + size=1000, + ) + + async def scan(**kwargs): + assert kwargs["index"] == str(ESIndex.PROJECTS_BUND_TOPICS) + mapping_ids = { + funding_code: hashlib.sha256(funding_code.encode("utf-8")).hexdigest() + for funding_code in ("B1", "B2") + } + assert kwargs["query"] == { + "terms": {"project_id": sorted(mapping_ids.values())} + } + for project_id, topic_id, topic_name, subfield in ( + (mapping_ids["B1"], "T1", "Artificial Intelligence", "AI"), + (mapping_ids["B1"], "T2", "Robotics", "Robotics"), + (mapping_ids["B2"], "T1", "Artificial Intelligence", "AI"), + ): + yield { + "_source": { + "project_id": project_id, + "keyword": topic_name, + "topic_matches": [ + { + "topic_id": topic_id, + "topic_display_name": topic_name, + "field": "Computer Science", + "subfield": subfield, + "domain": "Physical Sciences", + } + ], + } + } + + with patch( + "inse.dashboard.service.projects_service.search_bund_projects_with_filters", + new=AsyncMock(return_value=project_page), + ) as mocked_projects, patch( + "inse.dashboard.service.elasticsearch.scan", + new=scan, + ): + result = await get_dashboard_bund_topics( + ORG_INSTITUTION_ID, + "Example Org", + from_year=2022, + to_year=2026, + ) + + project_call = mocked_projects.await_args + assert project_call.kwargs["active_from_year"] == 2022 + assert project_call.kwargs["active_to_year"] == 2026 + assert result.project_count == 2 + assert result.matched_project_count == 2 + assert {topic.field_project_count for topic in result.topics} == {2} + assert {topic.name: topic.subfield_project_count for topic in result.topics} == { + "Artificial Intelligence": 2, + "Robotics": 1, + } + + @pytest.mark.anyio async def test_dashboard_statistics_counts_organization_data_and_all_projects(): async def search(**kwargs): diff --git a/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts b/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts index 6f406f0b..894da8a3 100644 --- a/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts +++ b/webapp/src/app/modules/dashboard/dashboard-statistics.service.ts @@ -59,6 +59,8 @@ export interface DfgProjectTopic { field?: string | null; domain?: string | null; project_count: number; + field_project_count: number; + subfield_project_count: number; keywords: DfgProjectKeyword[]; } @@ -75,6 +77,9 @@ export interface DfgProjectTopics { topics: DfgProjectTopic[]; } +export interface EuProjectTopics extends DfgProjectTopics {} +export interface BundProjectTopics extends DfgProjectTopics {} + export interface TopAuthor { id?: string | null; name: string; @@ -202,6 +207,24 @@ export class DashboardStatisticsService { ); } + getEuProjectTopics( + period: DashboardPeriodBounds = {}, + ): Observable { + return this.httpClient.get( + `${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/eu/topics`, + { params: this.periodParams(period) }, + ); + } + + getBundProjectTopics( + period: DashboardPeriodBounds = {}, + ): Observable { + return this.httpClient.get( + `${this.apiConfiguration?.basePath ?? ''}/api/dashboard/projects/bund/topics`, + { params: this.periodParams(period) }, + ); + } + getTopAuthors( period: DashboardPeriodBounds = {}, ): Observable { diff --git a/webapp/src/app/modules/dashboard/dashboard.component.html b/webapp/src/app/modules/dashboard/dashboard.component.html index 7cf8b2bc..5b95c4a7 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.html +++ b/webapp/src/app/modules/dashboard/dashboard.component.html @@ -317,6 +317,92 @@ } + @if (euTopicsLoading || euTopicsError || euProjectTopics) { +
+
+
+

EU-Projekt-Topics

+

+ Gematchte EU-Projekte nach Field, Subfield und Topic. Ein Klick + auf ein Topic zeigt die zugehörigen Keywords. +

+
+ @if (euProjectTopics) { +

+ {{ euProjectTopics.matched_project_count | number }} von + {{ euProjectTopics.project_count | number }} Projekten gematcht +

+ } +
+ + @if (euTopicsLoading) { +
+ +
+ } @else if (euTopicsError) { +

+ Die EU-Topic-Treemap konnte nicht geladen werden. +

+ } @else { + + + } +
+ } + + @if (bundTopicsLoading || bundTopicsError || bundProjectTopics) { +
+
+
+

BUND-Projekt-Topics

+

+ Gematchte BUND-Projekte nach Field, Subfield und Topic. Ein Klick + auf ein Topic zeigt die zugehörigen Keywords. +

+
+ @if (bundProjectTopics) { +

+ {{ bundProjectTopics.matched_project_count | number }} von + {{ bundProjectTopics.project_count | number }} Projekten gematcht +

+ } +
+ + @if (bundTopicsLoading) { +
+ +
+ } @else if (bundTopicsError) { +

+ Die BUND-Topic-Treemap konnte nicht geladen werden. +

+ } @else { + + + } +
+ } + @if (topAuthorsLoading || topAuthorsError || hasTopAuthorData()) {
diff --git a/webapp/src/app/modules/dashboard/dashboard.component.ts b/webapp/src/app/modules/dashboard/dashboard.component.ts index cb9982c5..a2638a4b 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.ts +++ b/webapp/src/app/modules/dashboard/dashboard.component.ts @@ -18,6 +18,7 @@ import { } from './topic-wordcloud-dialog/topic-wordcloud-dialog.component'; import { BmbfProjectStatusStatistics, + BundProjectTopics, DashboardPeriodBounds, DashboardStatisticValue, DashboardStatistics, @@ -26,6 +27,7 @@ import { DfgProjectTopic, DfgProjectTopics, EuProjectStatusStatistics, + EuProjectTopics, TopAuthor, TopAuthorStatistics, } from './dashboard-statistics.service'; @@ -96,6 +98,14 @@ export class DashboardComponent implements OnInit { dfgTopicTreemap?: TopicTreemapData; dfgTopicsLoading = false; dfgTopicsError = false; + euProjectTopics?: EuProjectTopics; + euTopicTreemap?: TopicTreemapData; + euTopicsLoading = false; + euTopicsError = false; + bundProjectTopics?: BundProjectTopics; + bundTopicTreemap?: TopicTreemapData; + bundTopicsLoading = false; + bundTopicsError = false; euProjectStatuses?: EuProjectStatusStatistics; euProjectStatusesLoading = false; euProjectStatusesError = false; @@ -112,6 +122,8 @@ export class DashboardComponent implements OnInit { dashboardToYear = this.topicTreemapMaxYear; selectedTopicTreemapNode?: string; selectedDfgTopicTreemapNode?: string; + selectedEuTopicTreemapNode?: string; + selectedBundTopicTreemapNode?: string; private topicTreemapReloadQueued = false; private topicTreemapRequestId = 0; @@ -128,6 +140,8 @@ export class DashboardComponent implements OnInit { this.loadTopAuthors(); this.loadTopicTreemap(); this.loadDfgProjectTopics(); + this.loadEuProjectTopics(); + this.loadBundProjectTopics(); this.loadEuProjectStatuses(); this.loadBmbfProjectStatuses(); this.loadDfgProjectStatuses(); @@ -245,10 +259,12 @@ export class DashboardComponent implements OnInit { ([subfieldName, group]) => ({ id: `${fieldName}::${subfieldName}`, name: subfieldName, - total: group.topics.reduce( - (sum, topic) => sum + topic.project_count, - 0, - ), + total: + group.topics[0]?.subfield_project_count ?? + group.topics.reduce( + (sum, topic) => sum + topic.project_count, + 0, + ), values: [], topics: group.topics.map((topic) => ({ id: topic.id, @@ -261,10 +277,12 @@ export class DashboardComponent implements OnInit { return { id: fieldName, name: fieldName, - total: mappedSubfields.reduce( - (sum, subfield) => sum + subfield.total, - 0, - ), + total: + [...subfields.values()][0]?.topics[0]?.field_project_count ?? + mappedSubfields.reduce( + (sum, subfield) => sum + subfield.total, + 0, + ), values: [], subfields: mappedSubfields, }; @@ -378,6 +396,62 @@ export class DashboardComponent implements OnInit { ); } + onEuTopicTreemapNodeChange(nodeId: string | undefined): void { + this.selectedEuTopicTreemapNode = nodeId; + } + + onEuTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { + const euTopic = this.euProjectTopics?.topics.find( + (entry) => entry.id === topic.topicId, + ); + if (!euTopic) return; + + this.dialog.open( + TopicWordCloudDialogComponent, + { + width: '85vw', + maxWidth: '92vw', + data: { + ...topic, + source: 'eu', + words: euTopic.keywords.map((keyword) => ({ + id: keyword.name, + name: keyword.name, + count: keyword.project_count, + })), + }, + }, + ); + } + + onBundTopicTreemapNodeChange(nodeId: string | undefined): void { + this.selectedBundTopicTreemapNode = nodeId; + } + + onBundTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { + const bundTopic = this.bundProjectTopics?.topics.find( + (entry) => entry.id === topic.topicId, + ); + if (!bundTopic) return; + + this.dialog.open( + TopicWordCloudDialogComponent, + { + width: '85vw', + maxWidth: '92vw', + data: { + ...topic, + source: 'bund', + words: bundTopic.keywords.map((keyword) => ({ + id: keyword.name, + name: keyword.name, + count: keyword.project_count, + })), + }, + }, + ); + } + onTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void { const period = this.selectedPeriodBounds(); this.dialog.open( @@ -469,6 +543,8 @@ export class DashboardComponent implements OnInit { this.loadTopAuthors(); this.loadTopicTreemap(); this.loadDfgProjectTopics(); + this.loadEuProjectTopics(); + this.loadBundProjectTopics(); this.loadEuProjectStatuses(); this.loadBmbfProjectStatuses(); this.loadDfgProjectStatuses(); @@ -552,6 +628,40 @@ export class DashboardComponent implements OnInit { }); } + private loadEuProjectTopics(): void { + this.euTopicsLoading = true; + this.euTopicsError = false; + this.statisticsService + .getEuProjectTopics(this.selectedPeriodBounds()) + .pipe(finalize(() => (this.euTopicsLoading = false))) + .subscribe({ + next: (topics) => { + this.euProjectTopics = topics; + this.euTopicTreemap = this.buildDfgTopicTreemapData(topics); + }, + error: () => { + this.euTopicsError = true; + }, + }); + } + + private loadBundProjectTopics(): void { + this.bundTopicsLoading = true; + this.bundTopicsError = false; + this.statisticsService + .getBundProjectTopics(this.selectedPeriodBounds()) + .pipe(finalize(() => (this.bundTopicsLoading = false))) + .subscribe({ + next: (topics) => { + this.bundProjectTopics = topics; + this.bundTopicTreemap = this.buildDfgTopicTreemapData(topics); + }, + error: () => { + this.bundTopicsError = true; + }, + }); + } + private loadEuProjectStatuses(): void { this.euProjectStatusesLoading = true; this.euProjectStatusesError = false; diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts index 6639bbf4..a8b75dc0 100644 --- a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts +++ b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.ts @@ -23,7 +23,7 @@ export interface TopicWordCloudDialogData { fromYear?: number; toYear?: number; words?: TopicWordCloudWord[]; - source?: 'publications' | 'dfg'; + source?: 'publications' | 'dfg' | 'eu' | 'bund'; } interface DisplayWord extends TopicWordCloudWord {