dfg-topics-treemap #259
@@ -42,6 +42,11 @@ class DfgProjectStatusStatistics(BaseModel):
|
||||
completed: int
|
||||
|
||||
|
||||
class DfgProjectKeyword(BaseModel):
|
||||
name: str
|
||||
project_count: int
|
||||
|
||||
|
||||
class DfgProjectTopic(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
@@ -49,6 +54,7 @@ class DfgProjectTopic(BaseModel):
|
||||
field: str | None = None
|
||||
domain: str | None = None
|
||||
project_count: int
|
||||
keywords: list[DfgProjectKeyword]
|
||||
|
||||
|
||||
class DfgProjectTopics(BaseModel):
|
||||
|
||||
@@ -35,6 +35,7 @@ from .institute_helper import get_openalex_institution
|
||||
from .model import (
|
||||
BmbfProjectStatusStatistics,
|
||||
DashboardStatistics,
|
||||
DfgProjectKeyword,
|
||||
DashboardStatisticValue,
|
||||
DfgProjectStatusStatistics,
|
||||
DfgProjectTopic,
|
||||
@@ -660,6 +661,12 @@ async def get_dashboard_dfg_topics(
|
||||
from_year=from_year,
|
||||
to_year=to_year,
|
||||
)
|
||||
print(
|
||||
"Dashboard DFG project topics "
|
||||
f"for institution {normalized_id}: "
|
||||
f"{len(project_ids)} project IDs={project_ids}",
|
||||
flush=True,
|
||||
)
|
||||
topics: dict[str, dict[str, Any]] = {}
|
||||
matched_project_ids: set[str] = set()
|
||||
|
||||
@@ -667,7 +674,7 @@ async def get_dashboard_dfg_topics(
|
||||
async for hit in elasticsearch.scan(
|
||||
index=str(ESIndex.PROJECTS_DFG_OPENALEX_TOPICS),
|
||||
query={"terms": {"project_id": project_ids}},
|
||||
source=["project_id", "topic_matches"],
|
||||
source=["project_id", "keyword", "topic_matches"],
|
||||
page_size=1000,
|
||||
cluster=ESCluster.INSE,
|
||||
):
|
||||
@@ -675,6 +682,7 @@ async def get_dashboard_dfg_topics(
|
||||
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 "")
|
||||
@@ -689,9 +697,12 @@ async def get_dashboard_dfg_topics(
|
||||
"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)
|
||||
|
||||
topic_list = [
|
||||
DfgProjectTopic(
|
||||
@@ -701,6 +712,16 @@ async def get_dashboard_dfg_topics(
|
||||
field=topic["field"],
|
||||
domain=topic["domain"],
|
||||
project_count=len(topic["project_ids"]),
|
||||
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()
|
||||
]
|
||||
|
||||
@@ -59,6 +59,12 @@ export interface DfgProjectTopic {
|
||||
field?: string | null;
|
||||
domain?: string | null;
|
||||
project_count: number;
|
||||
keywords: DfgProjectKeyword[];
|
||||
}
|
||||
|
||||
export interface DfgProjectKeyword {
|
||||
name: string;
|
||||
project_count: number;
|
||||
}
|
||||
|
||||
export interface DfgProjectTopics {
|
||||
|
||||
@@ -280,8 +280,8 @@
|
||||
<div>
|
||||
<h2>DFG-Projekt-Topics</h2>
|
||||
<p>
|
||||
Verteilung der gematchten Topics aus den DFG-Projekten Ihrer
|
||||
Organisation.
|
||||
Gematchte DFG-Projekte nach Field, Subfield und Topic. Ein Klick
|
||||
auf ein Topic zeigt die zugehörigen Keywords.
|
||||
</p>
|
||||
</div>
|
||||
@if (dfgProjectTopics) {
|
||||
@@ -302,11 +302,17 @@
|
||||
</div>
|
||||
} @else if (dfgTopicsError) {
|
||||
<p class="statistics-error">
|
||||
Das DFG-Topic-Diagramm konnte nicht geladen werden.
|
||||
Die DFG-Topic-Treemap konnte nicht geladen werden.
|
||||
</p>
|
||||
} @else {
|
||||
<app-dfg-topic-donut
|
||||
[topics]="dfgProjectTopics?.topics ?? []"></app-dfg-topic-donut>
|
||||
<app-topic-treemap
|
||||
[data]="dfgTopicTreemap"
|
||||
[selectedNodeId]="selectedDfgTopicTreemapNode"
|
||||
countLabel="DFG-Projekte"
|
||||
[showCountInTooltip]="false"
|
||||
(selectedNodeIdChange)="onDfgTopicTreemapNodeChange($event)"
|
||||
(topicSelect)="onDfgTopicTreemapTopicSelect($event)">
|
||||
</app-topic-treemap>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import { MatIconModule } from '@angular/material/icon';
|
||||
import { Observable, finalize } from 'rxjs';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { DfgTopicDonutComponent } from './dfg-topic-donut/dfg-topic-donut.component';
|
||||
import { EuProjectStatusChartComponent } from './eu-project-status-chart/eu-project-status-chart.component';
|
||||
import { YearRangeSliderComponent } from '../../shared/ui/year-range-slider/year-range-slider.component';
|
||||
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
|
||||
@@ -24,6 +23,7 @@ import {
|
||||
DashboardStatistics,
|
||||
DashboardStatisticsService,
|
||||
DfgProjectStatusStatistics,
|
||||
DfgProjectTopic,
|
||||
DfgProjectTopics,
|
||||
EuProjectStatusStatistics,
|
||||
TopAuthor,
|
||||
@@ -58,7 +58,6 @@ type DashboardPeriodMode =
|
||||
MatIconModule,
|
||||
RouterLink,
|
||||
LoadingComponent,
|
||||
DfgTopicDonutComponent,
|
||||
EuProjectStatusChartComponent,
|
||||
TopicTreemapComponent,
|
||||
YearRangeSliderComponent,
|
||||
@@ -94,6 +93,7 @@ export class DashboardComponent implements OnInit {
|
||||
topicTreemapLoading = false;
|
||||
topicTreemapError = false;
|
||||
dfgProjectTopics?: DfgProjectTopics;
|
||||
dfgTopicTreemap?: TopicTreemapData;
|
||||
dfgTopicsLoading = false;
|
||||
dfgTopicsError = false;
|
||||
euProjectStatuses?: EuProjectStatusStatistics;
|
||||
@@ -111,6 +111,7 @@ export class DashboardComponent implements OnInit {
|
||||
dashboardFromYear = this.topicTreemapMaxYear - 4;
|
||||
dashboardToYear = this.topicTreemapMaxYear;
|
||||
selectedTopicTreemapNode?: string;
|
||||
selectedDfgTopicTreemapNode?: string;
|
||||
private topicTreemapReloadQueued = false;
|
||||
private topicTreemapRequestId = 0;
|
||||
|
||||
@@ -216,6 +217,61 @@ export class DashboardComponent implements OnInit {
|
||||
return (this.dfgProjectTopics?.topics.length ?? 0) > 0;
|
||||
}
|
||||
|
||||
private buildDfgTopicTreemapData(
|
||||
projectTopics: DfgProjectTopics,
|
||||
): TopicTreemapData {
|
||||
const fields = new Map<
|
||||
string,
|
||||
Map<string, { topics: DfgProjectTopic[] }>
|
||||
>();
|
||||
for (const topic of projectTopics.topics) {
|
||||
const fieldName = topic.field?.trim() || 'Ohne Field';
|
||||
const subfieldName = topic.subfield?.trim() || 'Ohne Subfield';
|
||||
const subfields =
|
||||
fields.get(fieldName) ??
|
||||
new Map<string, { topics: DfgProjectTopic[] }>();
|
||||
const subfield = subfields.get(subfieldName) ?? { topics: [] };
|
||||
subfield.topics.push(topic);
|
||||
subfields.set(subfieldName, subfield);
|
||||
fields.set(fieldName, subfields);
|
||||
}
|
||||
|
||||
return {
|
||||
institution_id: projectTopics.institution_id,
|
||||
organization_name: projectTopics.organization_name,
|
||||
years: [],
|
||||
fields: [...fields.entries()].map(([fieldName, subfields]) => {
|
||||
const mappedSubfields = [...subfields.entries()].map(
|
||||
([subfieldName, group]) => ({
|
||||
id: `${fieldName}::${subfieldName}`,
|
||||
name: subfieldName,
|
||||
total: group.topics.reduce(
|
||||
(sum, topic) => sum + topic.project_count,
|
||||
0,
|
||||
),
|
||||
values: [],
|
||||
topics: group.topics.map((topic) => ({
|
||||
id: topic.id,
|
||||
name: topic.name,
|
||||
total: topic.project_count,
|
||||
values: [],
|
||||
})),
|
||||
}),
|
||||
);
|
||||
return {
|
||||
id: fieldName,
|
||||
name: fieldName,
|
||||
total: mappedSubfields.reduce(
|
||||
(sum, subfield) => sum + subfield.total,
|
||||
0,
|
||||
),
|
||||
values: [],
|
||||
subfields: mappedSubfields,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
setDashboardPeriodMode(mode: DashboardPeriodMode): void {
|
||||
if (mode === this.dashboardPeriodMode) return;
|
||||
this.dashboardPeriodMode = mode;
|
||||
@@ -294,6 +350,34 @@ export class DashboardComponent implements OnInit {
|
||||
this.updateDashboardPeriodUrl();
|
||||
}
|
||||
|
||||
onDfgTopicTreemapNodeChange(nodeId: string | undefined): void {
|
||||
this.selectedDfgTopicTreemapNode = nodeId;
|
||||
}
|
||||
|
||||
onDfgTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void {
|
||||
const dfgTopic = this.dfgProjectTopics?.topics.find(
|
||||
(entry) => entry.id === topic.topicId,
|
||||
);
|
||||
if (!dfgTopic) return;
|
||||
|
||||
this.dialog.open<TopicWordCloudDialogComponent, TopicWordCloudDialogData>(
|
||||
TopicWordCloudDialogComponent,
|
||||
{
|
||||
width: '85vw',
|
||||
maxWidth: '92vw',
|
||||
data: {
|
||||
...topic,
|
||||
source: 'dfg',
|
||||
words: dfgTopic.keywords.map((keyword) => ({
|
||||
id: keyword.name,
|
||||
name: keyword.name,
|
||||
count: keyword.project_count,
|
||||
})),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
onTopicTreemapTopicSelect(topic: TopicTreemapTopicSelect): void {
|
||||
const period = this.selectedPeriodBounds();
|
||||
this.dialog.open<TopicWordCloudDialogComponent, TopicWordCloudDialogData>(
|
||||
@@ -460,6 +544,7 @@ export class DashboardComponent implements OnInit {
|
||||
.subscribe({
|
||||
next: (topics) => {
|
||||
this.dfgProjectTopics = topics;
|
||||
this.dfgTopicTreemap = this.buildDfgTopicTreemapData(topics);
|
||||
},
|
||||
error: () => {
|
||||
this.dfgTopicsError = true;
|
||||
|
||||
+22
-4
@@ -2,8 +2,18 @@
|
||||
<div class="dialog-heading">
|
||||
<div>
|
||||
<span class="dialog-eyebrow">Topic Insights</span>
|
||||
<h2>Keyword Wordcloud</h2>
|
||||
<p>Die wichtigsten Begriffe zum ausgewählten Forschungsthema</p>
|
||||
<h2>
|
||||
{{
|
||||
data.source === 'dfg' ? 'DFG-Keyword Wordcloud' : 'Keyword Wordcloud'
|
||||
}}
|
||||
</h2>
|
||||
<p>
|
||||
{{
|
||||
data.source === 'dfg'
|
||||
? 'Keywords der DFG-Projekte zum ausgewählten Topic'
|
||||
: 'Die wichtigsten Begriffe zum ausgewählten Forschungsthema'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@@ -67,7 +77,10 @@
|
||||
<div class="word-cloud-panel-header">
|
||||
<div>
|
||||
<h3 id="word-cloud-heading">Top Keywords</h3>
|
||||
<p>Die Schriftgröße entspricht der Anzahl der Publikationen.</p>
|
||||
<p>
|
||||
Die Schriftgröße entspricht der Anzahl der
|
||||
{{ data.source === 'dfg' ? 'DFG-Projekte' : 'Publikationen' }}.
|
||||
</p>
|
||||
</div>
|
||||
@if (!loading && !loadFailed && words.length) {
|
||||
<span class="word-count">{{ words.length }} Begriffe</span>
|
||||
@@ -181,7 +194,12 @@
|
||||
[style.color]="word.color"
|
||||
[style.fontSize.px]="word.fontSize"
|
||||
[style.fontWeight]="word.fontWeight"
|
||||
[title]="word.name + ': ' + word.count + ' Publikationen'"
|
||||
[title]="
|
||||
word.name +
|
||||
': ' +
|
||||
word.count +
|
||||
(data.source === 'dfg' ? ' DFG-Projekte' : ' Publikationen')
|
||||
"
|
||||
(click)="toggleWord(word)">
|
||||
{{ word.name }}
|
||||
</button>
|
||||
|
||||
+7
@@ -22,6 +22,8 @@ export interface TopicWordCloudDialogData {
|
||||
subfieldName?: string;
|
||||
fromYear?: number;
|
||||
toYear?: number;
|
||||
words?: TopicWordCloudWord[];
|
||||
source?: 'publications' | 'dfg';
|
||||
}
|
||||
|
||||
interface DisplayWord extends TopicWordCloudWord {
|
||||
@@ -70,6 +72,11 @@ export class TopicWordCloudDialogComponent {
|
||||
];
|
||||
|
||||
constructor() {
|
||||
if (this.data.words) {
|
||||
this.words = this.buildWords(this.data.words);
|
||||
this.loading = false;
|
||||
return;
|
||||
}
|
||||
this.statisticsService
|
||||
.getTopicWordCloud(
|
||||
this.data.topicId,
|
||||
|
||||
@@ -44,6 +44,8 @@ export class TopicTreemapComponent implements OnChanges {
|
||||
@Input() data?: TopicTreemapData;
|
||||
@Input() loading = false;
|
||||
@Input() selectedNodeId?: string;
|
||||
@Input() countLabel = 'Publikationen';
|
||||
@Input() showCountInTooltip = true;
|
||||
@Output() selectedNodeIdChange = new EventEmitter<string | undefined>();
|
||||
@Output() topicSelect = new EventEmitter<TopicTreemapTopicSelect>();
|
||||
|
||||
@@ -232,10 +234,14 @@ export class TopicTreemapComponent implements OnChanges {
|
||||
: ''
|
||||
}
|
||||
<div style="font-size:15px;font-weight:700;line-height:1.4;overflow-wrap:anywhere;">${name}</div>
|
||||
<div style="display:flex;align-items:baseline;gap:5px;margin-top:10px;font-size:12px;">
|
||||
<strong style="color:${this.chartTheme.colors().blueHighlight};font-size:16px;">${this.formatCount(count)}</strong>
|
||||
Publikationen
|
||||
</div>
|
||||
${
|
||||
this.showCountInTooltip
|
||||
? `<div style="display:flex;align-items:baseline;gap:5px;margin-top:10px;font-size:12px;">
|
||||
<strong style="color:${this.chartTheme.colors().blueHighlight};font-size:16px;">${this.formatCount(count)}</strong>
|
||||
${this.escapeHtml(this.countLabel)}
|
||||
</div>`
|
||||
: ''
|
||||
}
|
||||
<div style="margin-top:9px;padding-top:9px;border-top:1px solid ${tooltipBorder};opacity:0.75;font-size:11px;">
|
||||
Klicken, um diesen Bereich zu vergrößern
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user