feat(work-classifications): optimized aggregation retrieval, moved chart to own component, and added chart for institution publications
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
Mats Paul Tončik
2026-07-20 21:11:17 +02:00
parent 9da17840ad
commit a5664e01fe
29 changed files with 980 additions and 667 deletions
@@ -103,6 +103,9 @@ export class CredentialService {
public readonly effectiveAccountId = computed(
() => this.accessToken()?.effective_account_id ?? '',
);
public readonly effectiveInstitutionId = computed(
() => this.accessToken()?.effective_institution_id ?? '',
);
public readonly isImpersonating = computed(
() => this.realAccountId() !== this.effectiveAccountId(),
);
@@ -0,0 +1,18 @@
<div>
<div
echarts
[options]="chartOption()"
style="height: 300px; width: 100%"></div>
<div class="info-cards">
@for (cardInput of this.cardInputs(); track $index) {
<app-info-card
[value]="cardInput.value"
[description]="cardInput.description"
[icon]="cardInput.icon" />
}
<app-info-card
[value]="this.totalCount() + ''"
description="Gesamtanzahl klassifizierter Publikationen"
icon="article" />
</div>
</div>
@@ -0,0 +1,7 @@
.info-cards {
width: 100%;
display: flex;
gap: 1rem;
flex-wrap: wrap;
margin-top: 1rem;
}
@@ -0,0 +1,184 @@
import { Component, computed, input } from '@angular/core';
import {
PrimaryCategoryYearAggregation,
PrimaryCategoryYearAggregationPage,
WorkPrimaryCategory,
} from '../../../api';
import { transformWorkPrimaryCategory } from '../../pipes/work-primary-category.pipe';
import { AppInfoCardComponent } from '../app-info-card/app-info-card.component';
import { EChartsCoreOption } from 'echarts';
import { NgxEchartsDirective } from 'ngx-echarts';
type CardInput = {
value: string;
description: string;
icon: string;
};
@Component({
selector: 'app-primary-category-year-aggregation-chart',
imports: [AppInfoCardComponent, NgxEchartsDirective],
templateUrl: './primary-category-year-aggregation-chart.component.html',
styleUrl: './primary-category-year-aggregation-chart.component.scss',
})
export class PrimaryCategoryYearAggregationChartComponent {
page = input.required<PrimaryCategoryYearAggregationPage>();
countPrimaryCategoryForAllYears(
page: PrimaryCategoryYearAggregationPage,
primaryCategory: WorkPrimaryCategory,
): number {
if (!page?.elements) {
return 0;
}
return page.elements.reduce((acc, element) => {
const count = element.categories?.[primaryCategory] || 0;
return acc + count;
}, 0);
}
basicResearchCount = computed(() => {
return this.countPrimaryCategoryForAllYears(
this.page(),
WorkPrimaryCategory.BasicResearch,
);
});
basicResearchLabel = transformWorkPrimaryCategory(
WorkPrimaryCategory.BasicResearch,
);
appliedResearchCount = computed(() => {
return this.countPrimaryCategoryForAllYears(
this.page(),
WorkPrimaryCategory.AppliedResearch,
);
});
appliedResearchLabel = transformWorkPrimaryCategory(
WorkPrimaryCategory.AppliedResearch,
);
nonResearchCount = computed(() => {
return this.countPrimaryCategoryForAllYears(
this.page(),
WorkPrimaryCategory.NonResearch,
);
});
nonResearchLabel = transformWorkPrimaryCategory(
WorkPrimaryCategory.NonResearch,
);
experimentalDevelopmentCount = computed(() => {
return this.countPrimaryCategoryForAllYears(
this.page(),
WorkPrimaryCategory.ExperimentalDevelopment,
);
});
experimentalDevelopmentLabel = transformWorkPrimaryCategory(
WorkPrimaryCategory.ExperimentalDevelopment,
);
totalCount = computed(() => {
return (
this.basicResearchCount() +
this.appliedResearchCount() +
this.nonResearchCount() +
this.experimentalDevelopmentCount()
);
});
cardInputs = computed<CardInput[]>(() => {
return [
{
value: this.basicResearchCount().toString(),
description: this.basicResearchLabel,
icon: 'science',
},
{
value: this.appliedResearchCount().toString(),
description: this.appliedResearchLabel,
icon: 'biotech',
},
{
value: this.nonResearchCount().toString(),
description: this.nonResearchLabel,
icon: 'work_outline',
},
{
value: this.experimentalDevelopmentCount().toString(),
description: this.experimentalDevelopmentLabel,
icon: 'build',
},
];
});
chartOption = computed(() => {
return this.buildChartOptions(this.page().elements ?? []);
});
buildChartOptions(data: PrimaryCategoryYearAggregation[]): EChartsCoreOption {
return {
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
legend: {
data: [
this.basicResearchLabel,
this.appliedResearchLabel,
this.nonResearchLabel,
this.experimentalDevelopmentLabel,
],
bottom: 0,
itemGap: 40,
},
grid: {
left: '3%',
right: '4%',
bottom: '10%',
top: '3%',
containLabel: true,
},
xAxis: {
type: 'category',
data: data.map((d) => d.publication_year.toString()),
},
yAxis: { type: 'value' },
series: [
{
name: this.basicResearchLabel,
type: 'bar',
stack: 'total',
emphasis: { focus: 'series' },
data: data.map(
(d) => d.categories?.[WorkPrimaryCategory.BasicResearch] || 0,
),
},
{
name: this.appliedResearchLabel,
type: 'bar',
stack: 'total',
emphasis: { focus: 'series' },
data: data.map(
(d) => d.categories?.[WorkPrimaryCategory.AppliedResearch] || 0,
),
},
{
name: this.nonResearchLabel,
type: 'bar',
stack: 'total',
emphasis: { focus: 'series' },
data: data.map(
(d) => d.categories?.[WorkPrimaryCategory.NonResearch] || 0,
),
},
{
name: this.experimentalDevelopmentLabel,
type: 'bar',
stack: 'total',
emphasis: { focus: 'series' },
data: data.map(
(d) =>
d.categories?.[WorkPrimaryCategory.ExperimentalDevelopment] || 0,
),
},
],
};
}
}