add new endpoint for section to frontend

This commit is contained in:
Steven Tischer
2026-07-19 16:55:37 +02:00
parent aead21ceb2
commit 504809e473
7 changed files with 181 additions and 294 deletions
+118
View File
@@ -34,6 +34,8 @@ import { AuthorYearlyWorks } from '../model/authorYearlyWorks';
import { AuthorCorrespondingCount } from '../model/authorCorrespondingCount';
// @ts-ignore
import { AuthorImpactStats } from '../model/authorImpactStats';
// @ts-ignore
import { AuthorTopicStats } from '../model/authorTopicStats';
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
@@ -517,4 +519,120 @@ export class RankingService extends BaseService {
},
);
}
/**
* Section 1: combined stats over each selected author\'s topic-filtered works.
* @endpoint post /api/rank/topic-stats
* @param rankSelectedAuthorRequest
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public topicStats(
rankSelectedAuthorRequest: RankSelectedAuthorRequest,
observe?: 'body',
reportProgress?: boolean,
options?: {
httpHeaderAccept?: 'application/json';
context?: HttpContext;
transferCache?: boolean;
},
): Observable<Array<AuthorTopicStats>>;
public topicStats(
rankSelectedAuthorRequest: RankSelectedAuthorRequest,
observe?: 'response',
reportProgress?: boolean,
options?: {
httpHeaderAccept?: 'application/json';
context?: HttpContext;
transferCache?: boolean;
},
): Observable<HttpResponse<Array<AuthorTopicStats>>>;
public topicStats(
rankSelectedAuthorRequest: RankSelectedAuthorRequest,
observe?: 'events',
reportProgress?: boolean,
options?: {
httpHeaderAccept?: 'application/json';
context?: HttpContext;
transferCache?: boolean;
},
): Observable<HttpEvent<Array<AuthorTopicStats>>>;
public topicStats(
rankSelectedAuthorRequest: RankSelectedAuthorRequest,
observe: any = 'body',
reportProgress: boolean = false,
options?: {
httpHeaderAccept?: 'application/json';
context?: HttpContext;
transferCache?: boolean;
},
): Observable<any> {
if (
rankSelectedAuthorRequest === null ||
rankSelectedAuthorRequest === undefined
) {
throw new Error(
'Required parameter rankSelectedAuthorRequest was null or undefined when calling topicStats.',
);
}
let localVarHeaders = this.defaultHeaders;
const localVarHttpHeaderAcceptSelected: string | undefined =
options?.httpHeaderAccept ??
this.configuration.selectHeaderAccept(['application/json']);
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set(
'Accept',
localVarHttpHeaderAcceptSelected,
);
}
const localVarHttpContext: HttpContext =
options?.context ?? new HttpContext();
const localVarTransferCache: boolean = options?.transferCache ?? true;
const consumes: string[] = ['application/json'];
const httpContentTypeSelected: string | undefined =
this.configuration.selectHeaderContentType(consumes);
if (httpContentTypeSelected !== undefined) {
localVarHeaders = localVarHeaders.set(
'Content-Type',
httpContentTypeSelected,
);
}
let responseType_: 'text' | 'json' | 'blob' = 'json';
if (localVarHttpHeaderAcceptSelected) {
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
} else if (
this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)
) {
responseType_ = 'json';
} else {
responseType_ = 'blob';
}
}
let localVarPath = `/api/rank/topic-stats`;
const { basePath, withCredentials } = this.configuration;
return this.httpClient.request<Array<AuthorTopicStats>>(
'post',
`${basePath}${localVarPath}`,
{
context: localVarHttpContext,
body: rankSelectedAuthorRequest,
responseType: <any>responseType_,
...(withCredentials ? { withCredentials } : {}),
headers: localVarHeaders,
observe: observe,
...(localVarTransferCache !== undefined
? { transferCache: localVarTransferCache }
: {}),
reportProgress: reportProgress,
},
);
}
}
@@ -0,0 +1,40 @@
/**
* Innovation Search Engine API
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
export interface AuthorTopicStats {
/**
* The OpenAlex ID of the author.
*/
author_id: string;
/**
* The name of the author.
*/
display_name: string;
/**
* Number of the author\'s works matching the topic filter.
*/
works_total: number;
/**
* Number of the author\'s topic works where they are the corresponding author.
*/
corresponding_count: number;
/**
* Average field-normalized citation percentile (0-1) over the author\'s topic works.
*/
avg_percentile: number;
/**
* Number of the author\'s topic works in the top 1% most-cited.
*/
top1_count: number;
/**
* Number of the author\'s topic works in the top 10% most-cited.
*/
top10_count: number;
}
+1
View File
@@ -223,3 +223,4 @@ export * from './rankSelectedAuthorRequest';
export * from './authorYearlyWorks';
export * from './authorCorrespondingCount';
export * from './authorImpactStats';
export * from './authorTopicStats';
@@ -36,9 +36,9 @@
} @else if (!hasData()) {
<p class="compare-hint">Keine Daten für die ausgewählten Autoren.</p>
} @else {
<!-- all scalar values the backend returns, side by side -->
<!-- section 1: topic stats side by side -->
<section class="card">
<h2 class="card-title">Kennzahlen im Vergleich</h2>
<h2 class="card-title">Kennzahlen zu den Keywords</h2>
<p class="card-sub">
Bester Wert je Zeile ist hervorgehoben. „–“ bedeutet, dass der Wert für
diese:n Autor:in nicht vorliegt.
@@ -85,54 +85,5 @@
</table>
</div>
</section>
<!-- works over time -->
<section class="card">
<h2 class="card-title">Werke pro Jahr</h2>
<div
echarts
[options]="chartOption()"
[autoResize]="true"
class="chart-container"></div>
</section>
<!-- per-metric magnitude comparison -->
<div class="chart-grid">
<section class="card">
<h2 class="card-title">Werke gesamt (Thema)</h2>
<div
echarts
[options]="totalWorksOption()"
[autoResize]="true"
class="chart-container chart-container--sm"></div>
</section>
<section class="card">
<h2 class="card-title">Corresponding-Author-Werke</h2>
<div
echarts
[options]="correspondingOption()"
[autoResize]="true"
class="chart-container chart-container--sm"></div>
</section>
<section class="card">
<h2 class="card-title">Ø Impact-Perzentil (0–1)</h2>
<div
echarts
[options]="percentileOption()"
[autoResize]="true"
class="chart-container chart-container--sm"></div>
</section>
<section class="card">
<h2 class="card-title">Hoch zitierte Werke</h2>
<div
echarts
[options]="topCitedOption()"
[autoResize]="true"
class="chart-container chart-container--sm"></div>
</section>
</div>
}
</div>
@@ -176,28 +176,8 @@
color: var(--sg-text-soft, #8a95b3);
}
/* ---- charts ---- */
.chart-container {
height: 420px;
width: 100%;
}
.chart-container--sm {
height: 300px;
}
.chart-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18px;
}
@media (max-width: 900px) {
.compare-layout {
padding: 20px 16px 32px;
}
.chart-grid {
grid-template-columns: 1fr;
}
}
@@ -2,36 +2,11 @@ import { Component, OnInit, computed, inject, signal } from '@angular/core';
import { DecimalPipe } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { EChartsOption } from 'echarts';
import { NgxEchartsDirective } from 'ngx-echarts';
import {
AuthorCorrespondingCount,
AuthorImpactStats,
AuthorYearlyWorks,
RankingService,
} from '../../api';
import { AuthorTopicStats, RankingService } from '../../api';
const AUTHOR_COLORS = ['#1565c0', '#e6550d', '#2ca02c', '#9467bd'];
const AXIS_LABEL = { color: '#4b5563', fontFamily: 'Open Sans' };
const AXIS_LINE = { lineStyle: { color: '#e5e7eb' } };
const SPLIT_LINE = { lineStyle: { color: '#f3f4f6' } };
const TOOLTIP = {
backgroundColor: 'rgba(255,255,255,0.98)',
borderColor: '#e5e7eb',
borderWidth: 1,
textStyle: { color: '#374151', fontFamily: 'Open Sans' },
extraCssText: 'border-radius:8px;box-shadow:0 4px 12px rgba(0,0,0,0.15);',
};
const BAR_LABEL = {
show: true,
position: 'top' as const,
color: '#374151',
fontFamily: 'Open Sans',
fontWeight: 600,
};
interface AuthorSummary {
authorId: string;
name: string;
@@ -58,7 +33,7 @@ interface MetricRow {
@Component({
selector: 'app-compare-authors',
standalone: true,
imports: [DecimalPipe, MatIconModule, NgxEchartsDirective],
imports: [DecimalPipe, MatIconModule],
templateUrl: './compare-authors.component.html',
styleUrl: './compare-authors.component.scss',
})
@@ -71,37 +46,27 @@ export class CompareAuthorsComponent implements OnInit {
// full OpenAlex ids in the requested order — the source of truth for colour + order
readonly authorIds = signal<string[]>([]);
readonly data = signal<AuthorYearlyWorks[]>([]);
readonly corresponding = signal<AuthorCorrespondingCount[]>([]);
readonly impact = signal<AuthorImpactStats[]>([]);
// section 1: combined topic stats, one entry per author
readonly topic = signal<AuthorTopicStats[]>([]);
readonly loading = signal(false);
// merges the three endpoints into one row per author, in the requested order
// maps the topic stats onto one row per author, in the requested order
readonly summary = computed<AuthorSummary[]>(() => {
const yearly = new Map(this.data().map((a) => [a.author_id, a]));
const corr = new Map(this.corresponding().map((a) => [a.author_id, a]));
const imp = new Map(this.impact().map((a) => [a.author_id, a]));
const stats = new Map(this.topic().map((a) => [a.author_id, a]));
return this.authorIds().map((id, index) => {
const y = yearly.get(id);
const c = corr.get(id);
const im = imp.get(id);
const name =
y?.display_name ??
c?.display_name ??
im?.display_name ??
id.split('/').pop() ??
id;
const s = stats.get(id);
const name = s?.display_name ?? id.split('/').pop() ?? id;
return {
authorId: id,
name,
color: AUTHOR_COLORS[index % AUTHOR_COLORS.length],
totalWorks: y ? y.years.reduce((sum, e) => sum + e.count, 0) : 0,
corresponding: c ? c.value : null,
avgPercentile: im ? im.avg_percentile : null,
top10: im ? im.top10_count : null,
top1: im ? im.top1_count : null,
totalWorks: s ? s.works_total : 0,
corresponding: s ? s.corresponding_count : null,
avgPercentile: s ? s.avg_percentile : null,
top10: s ? s.top10_count : null,
top1: s ? s.top1_count : null,
};
});
});
@@ -158,162 +123,11 @@ export class CompareAuthorsComponent implements OnInit {
];
});
// line chart: works per year, one line per author
readonly chartOption = computed<EChartsOption>(() => {
const authors = this.summary();
const yearly = new Map(this.data().map((a) => [a.author_id, a]));
if (authors.length === 0) {
return {};
}
const yearSet = new Set<number>();
for (const author of this.data()) {
for (const entry of author.years) {
yearSet.add(entry.year);
}
}
const years = Array.from(yearSet).sort((a, b) => a - b);
const series = authors.map((author) => {
const source = yearly.get(author.authorId);
const countByYear = new Map<number, number>();
for (const entry of source?.years ?? []) {
countByYear.set(entry.year, entry.count);
}
return {
name: author.name,
type: 'line',
smooth: true,
symbolSize: 8,
emphasis: { focus: 'series' },
lineStyle: { color: author.color, width: 2.5 },
itemStyle: { color: author.color },
data: years.map((year) => countByYear.get(year) ?? 0),
};
});
return {
color: authors.map((a) => a.color),
tooltip: { trigger: 'axis', ...TOOLTIP },
grid: { left: '3%', right: '4%', top: 16, bottom: 8, containLabel: true },
xAxis: {
type: 'category',
boundaryGap: false,
data: years.map(String),
axisLabel: AXIS_LABEL,
axisLine: AXIS_LINE,
axisTick: { show: false },
},
yAxis: {
type: 'value',
name: 'Werke',
nameTextStyle: AXIS_LABEL,
axisLabel: AXIS_LABEL,
splitLine: SPLIT_LINE,
},
series: series as unknown as EChartsOption['series'],
};
});
readonly totalWorksOption = computed<EChartsOption>(() =>
this.singleMetricBar((a) => a.totalWorks),
);
readonly correspondingOption = computed<EChartsOption>(() =>
this.singleMetricBar((a) => a.corresponding),
);
readonly percentileOption = computed<EChartsOption>(() =>
this.singleMetricBar((a) => a.avgPercentile, { max: 1, decimals: true }),
);
// grouped bars: top-10% vs top-1% works, one coloured bar per author in each group
readonly topCitedOption = computed<EChartsOption>(() => {
const authors = this.summary();
if (authors.length === 0) {
return {};
}
const series = authors.map((author) => ({
name: author.name,
type: 'bar',
itemStyle: { color: author.color, borderRadius: [4, 4, 0, 0] },
label: BAR_LABEL,
data: [author.top10 ?? 0, author.top1 ?? 0],
}));
return {
color: authors.map((a) => a.color),
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, ...TOOLTIP },
grid: { left: '3%', right: '4%', top: 24, bottom: 8, containLabel: true },
xAxis: {
type: 'category',
data: ['Top 10%', 'Top 1%'],
axisLabel: AXIS_LABEL,
axisLine: AXIS_LINE,
axisTick: { show: false },
},
yAxis: {
type: 'value',
axisLabel: AXIS_LABEL,
splitLine: SPLIT_LINE,
},
series: series as unknown as EChartsOption['series'],
};
});
private singleMetricBar(
select: (a: AuthorSummary) => number | null,
opts: { max?: number; decimals?: boolean } = {},
): EChartsOption {
const authors = this.summary();
if (authors.length === 0) {
return {};
}
const bars = authors.map((author) => ({
value: select(author) ?? 0,
itemStyle: { color: author.color, borderRadius: [4, 4, 0, 0] },
}));
return {
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, ...TOOLTIP },
grid: { left: '3%', right: '4%', top: 24, bottom: 8, containLabel: true },
xAxis: {
type: 'category',
data: authors.map((a) => this.truncate(a.name)),
axisLabel: { ...AXIS_LABEL, interval: 0, hideOverlap: true },
axisLine: AXIS_LINE,
axisTick: { show: false },
},
yAxis: {
type: 'value',
max: opts.max,
axisLabel: AXIS_LABEL,
splitLine: SPLIT_LINE,
},
series: [
{
type: 'bar',
barMaxWidth: 72,
data: bars,
label: {
...BAR_LABEL,
formatter: opts.decimals
? (p: { value: number }) => p.value.toFixed(2)
: undefined,
},
},
] as unknown as EChartsOption['series'],
};
}
private truncate(name: string): string {
return name.length > 18 ? `${name.slice(0, 17)}…` : name;
}
ngOnInit(): void {
// everything is read from the URL so a shared link lands on the same view
const rawAuthors = this.route.snapshot.queryParamMap.get('authors') ?? '';
const rawKeywords = this.route.snapshot.queryParamMap.get('keywords') ?? '';
const rawOperator = this.route.snapshot.queryParamMap.get('operator');
const rawPubType = this.route.snapshot.queryParamMap.get('pubType');
const rawTFrom = this.route.snapshot.queryParamMap.get('tFrom');
const rawTTo = this.route.snapshot.queryParamMap.get('tTo');
@@ -326,6 +140,7 @@ export class CompareAuthorsComponent implements OnInit {
return;
}
const operator = rawOperator === 'or' ? 'or' : 'and';
const publication_types = rawPubType
? this.parseList(rawPubType)
: undefined;
@@ -340,42 +155,23 @@ export class CompareAuthorsComponent implements OnInit {
const requestPayload = {
author_ids: fullIds,
keywords: keywords,
operator: operator,
publication_types: publication_types,
timespan: timespan,
};
this.loading.set(true);
this.rankingService.rankSelectedAuthor(requestPayload).subscribe({
this.rankingService.topicStats(requestPayload).subscribe({
next: (results) => {
this.data.set(results);
this.topic.set(results);
this.loading.set(false);
},
error: (error) => {
console.error(error);
this.data.set([]);
this.topic.set([]);
this.loading.set(false);
},
});
this.rankingService.correspondingAuthors(requestPayload).subscribe({
next: (results) => {
this.corresponding.set(results);
},
error: (error) => {
console.error(error);
this.corresponding.set([]);
},
});
this.rankingService.impactStats(requestPayload).subscribe({
next: (results) => {
this.impact.set(results);
},
error: (error) => {
console.error(error);
this.impact.set([]);
},
});
}
private parseList(raw: string): string[] {
@@ -423,6 +423,7 @@ export class KeywordsToPersonsResultsComponent implements OnInit {
queryParams: {
authors: this.selectedIds().join(','),
keywords: this.state.keywords().join(','),
operator: this.keywordOperator() === 'or' ? 'or' : null,
pubType:
this.selectedPubTypes().length > 0
? this.selectedPubTypes().join(',')