From 7775400a3f1dda24e36fd6ea3c804fd41c091bec Mon Sep 17 00:00:00 2001 From: Steven Tischer Date: Mon, 13 Jul 2026 07:19:33 +0200 Subject: [PATCH] add author comparison feature with yearly works visualization --- service/src/main/inse/ranking/logic.py | 8 ++ service/src/main/inse/ranking/model.py | 1 + webapp/src/app/api/api/ranking.service.ts | 121 ++++++++++++++++++ webapp/src/app/api/model/authorYearlyWorks.ts | 24 ++++ webapp/src/app/api/model/models.ts | 2 + .../api/model/rankSelectedAuthorRequest.ts | 24 ++++ webapp/src/app/app.routes.ts | 8 ++ .../compare-authors.component.html | 23 ++++ .../compare-authors.component.scss | 18 +++ .../compare-authors.component.ts | 108 ++++++++++++++++ .../persons-results.component.html | 17 +++ .../persons-results.component.scss | 18 ++- .../persons-results.component.ts | 52 +++++++- 13 files changed, 421 insertions(+), 3 deletions(-) create mode 100644 webapp/src/app/api/model/authorYearlyWorks.ts create mode 100644 webapp/src/app/api/model/rankSelectedAuthorRequest.ts create mode 100644 webapp/src/app/modules/compare-authors/compare-authors.component.html create mode 100644 webapp/src/app/modules/compare-authors/compare-authors.component.scss create mode 100644 webapp/src/app/modules/compare-authors/compare-authors.component.ts diff --git a/service/src/main/inse/ranking/logic.py b/service/src/main/inse/ranking/logic.py index 464f7ea5..c3728a0e 100644 --- a/service/src/main/inse/ranking/logic.py +++ b/service/src/main/inse/ranking/logic.py @@ -141,6 +141,13 @@ def _yearly_works_query( "execution_hint": "map", }, "aggs": { + "author_name": { + "terms": { + "field": "authorships.author.display_name.keyword", + "size": 1, + "execution_hint": "map", + }, + }, "to_work": { "reverse_nested": {}, "aggs": { @@ -207,6 +214,7 @@ async def yearly_works_for_authors( results.append( AuthorYearlyWorks( author_id=author_bucket.get("key", ""), + display_name=_display_name_from_bucket(author_bucket), years=years, ) ) diff --git a/service/src/main/inse/ranking/model.py b/service/src/main/inse/ranking/model.py index 6ceb7e34..76db4e91 100644 --- a/service/src/main/inse/ranking/model.py +++ b/service/src/main/inse/ranking/model.py @@ -137,6 +137,7 @@ class YearCount(BaseModel): class AuthorYearlyWorks(BaseModel): author_id: str = Field(description="The OpenAlex ID of the author.") + display_name: str = Field(description="The name of the author.") years: List[YearCount] = Field( description="Per-year count of the author's works on the topic, newest year first.", ) diff --git a/webapp/src/app/api/api/ranking.service.ts b/webapp/src/app/api/api/ranking.service.ts index de2439c0..8316fee7 100644 --- a/webapp/src/app/api/api/ranking.service.ts +++ b/webapp/src/app/api/api/ranking.service.ts @@ -26,6 +26,10 @@ import { Observable } from 'rxjs'; import { KeywordToAuthorRequest } from '../model/keywordToAuthorRequest'; // @ts-ignore import { RankedAuthor } from '../model/rankedAuthor'; +// @ts-ignore +import { RankSelectedAuthorRequest } from '../model/rankSelectedAuthorRequest'; +// @ts-ignore +import { AuthorYearlyWorks } from '../model/authorYearlyWorks'; // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; @@ -160,4 +164,121 @@ export class RankingService extends BaseService { }, ); } + + /** + * Returns, per selected author, the per-year count of their works on the topic. + * @endpoint post /api/rank/rank-selected-author + * @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 rankSelectedAuthor( + rankSelectedAuthorRequest: RankSelectedAuthorRequest, + observe?: 'body', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public rankSelectedAuthor( + rankSelectedAuthorRequest: RankSelectedAuthorRequest, + observe?: 'response', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>>; + public rankSelectedAuthor( + rankSelectedAuthorRequest: RankSelectedAuthorRequest, + observe?: 'events', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>>; + public rankSelectedAuthor( + rankSelectedAuthorRequest: RankSelectedAuthorRequest, + observe: any = 'body', + reportProgress: boolean = false, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable { + if ( + rankSelectedAuthorRequest === null || + rankSelectedAuthorRequest === undefined + ) { + throw new Error( + 'Required parameter rankSelectedAuthorRequest was null or undefined when calling rankSelectedAuthor.', + ); + } + + 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; + + // to determine the Content-Type header + 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/rank-selected-author`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request>( + 'post', + `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + body: rankSelectedAuthorRequest, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined + ? { transferCache: localVarTransferCache } + : {}), + reportProgress: reportProgress, + }, + ); + } } diff --git a/webapp/src/app/api/model/authorYearlyWorks.ts b/webapp/src/app/api/model/authorYearlyWorks.ts new file mode 100644 index 00000000..e744734e --- /dev/null +++ b/webapp/src/app/api/model/authorYearlyWorks.ts @@ -0,0 +1,24 @@ +/** + * 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 AuthorYearlyWorks { + /** + * The OpenAlex ID of the author. + */ + author_id: string; + /** + * The name of the author. + */ + display_name: string; + /** + * Per-year count of the author\'s works on the topic, newest year first. + */ + years: Array<{ year: number; count: number }>; +} diff --git a/webapp/src/app/api/model/models.ts b/webapp/src/app/api/model/models.ts index 7e0cf593..5a549e5d 100644 --- a/webapp/src/app/api/model/models.ts +++ b/webapp/src/app/api/model/models.ts @@ -197,3 +197,5 @@ export * from './yearlyData'; export * from './rankingWeights'; export * from './rankedAuthor'; export * from './keywordToAuthorRequest'; +export * from './rankSelectedAuthorRequest'; +export * from './authorYearlyWorks'; diff --git a/webapp/src/app/api/model/rankSelectedAuthorRequest.ts b/webapp/src/app/api/model/rankSelectedAuthorRequest.ts new file mode 100644 index 00000000..9b966c2a --- /dev/null +++ b/webapp/src/app/api/model/rankSelectedAuthorRequest.ts @@ -0,0 +1,24 @@ +/** + * 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 RankSelectedAuthorRequest { + /** + * OpenAlex IDs of the authors to rank. + */ + author_ids: Array; + /** + * One or more keywords defining the topic. + */ + keywords: Array; + /** + * How to combine the keywords: \'and\' or \'or\'. Defaults to \'and\'. + */ + operator?: string; +} diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index 21a8b833..1a8f9e18 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -68,6 +68,14 @@ export const routes: Routes = [ (mod) => mod.DashboardComponent, ), }, + { + path: 'compare', + canActivate: [userGuard], + loadComponent: () => + import('./modules/compare-authors/compare-authors.component').then( + (mod) => mod.CompareAuthorsComponent, + ), + }, { path: 'persons', canActivate: [userGuard], diff --git a/webapp/src/app/modules/compare-authors/compare-authors.component.html b/webapp/src/app/modules/compare-authors/compare-authors.component.html new file mode 100644 index 00000000..133c693a --- /dev/null +++ b/webapp/src/app/modules/compare-authors/compare-authors.component.html @@ -0,0 +1,23 @@ +
+

Autoren-Vergleich

+ + @if (keywords().length > 0) { +

Thema: {{ keywords().join(', ') }}

+ } + + @if (loading()) { +

Lädt…

+ } @else if (data().length === 0) { +

Keine Daten für die ausgewählten Autoren.

+ } @else { + + +
+
+
+ } +
diff --git a/webapp/src/app/modules/compare-authors/compare-authors.component.scss b/webapp/src/app/modules/compare-authors/compare-authors.component.scss new file mode 100644 index 00000000..b19374e6 --- /dev/null +++ b/webapp/src/app/modules/compare-authors/compare-authors.component.scss @@ -0,0 +1,18 @@ +.compare-layout { + padding: 1rem; +} + +.compare-keywords { + color: var(--sg-text-secondary, rgba(0, 0, 0, 0.6)); + margin-bottom: 1rem; +} + +.compare-hint { + padding: 0.5rem 0.25rem; +} + +/* echarts needs an explicit height or it won't render */ +.chart-container { + height: 500px; + width: 100%; +} diff --git a/webapp/src/app/modules/compare-authors/compare-authors.component.ts b/webapp/src/app/modules/compare-authors/compare-authors.component.ts new file mode 100644 index 00000000..5edb6497 --- /dev/null +++ b/webapp/src/app/modules/compare-authors/compare-authors.component.ts @@ -0,0 +1,108 @@ +import { Component, OnInit, computed, inject, signal } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { MatCardModule } from '@angular/material/card'; +import { EChartsOption } from 'echarts'; +import { NgxEchartsDirective } from 'ngx-echarts'; + +import { AuthorYearlyWorks, RankingService } from '../../api'; + +const LINE_COLORS = ['#1565c0', '#e6550d', '#2ca02c', '#9467bd']; + +@Component({ + selector: 'app-compare-authors', + standalone: true, + imports: [MatCardModule, NgxEchartsDirective], + templateUrl: './compare-authors.component.html', + styleUrl: './compare-authors.component.scss', +}) +export class CompareAuthorsComponent implements OnInit { + private readonly route = inject(ActivatedRoute); + private readonly rankingService = inject(RankingService); + + readonly keywords = signal([]); + readonly data = signal([]); + readonly loading = signal(false); + + readonly chartOption = computed(() => { + const authors = this.data(); + if (authors.length === 0) { + return {}; + } + + // shared, ascending list of every year that appears for any author + const yearSet = new Set(); + for (const author of authors) { + 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, index) => { + const countByYear = new Map(); + for (const entry of author.years) { + countByYear.set(entry.year, entry.count); + } + + const color = LINE_COLORS[index % LINE_COLORS.length]; + return { + name: author.display_name, + type: 'line', + smooth: true, + emphasis: { focus: 'series' }, + lineStyle: { color }, + itemStyle: { color }, + // align every author to the shared year axis, filling gaps with 0 + data: years.map((year) => countByYear.get(year) ?? 0), + }; + }); + + return { + tooltip: { trigger: 'axis' }, + legend: { bottom: 0, type: 'scroll' }, + grid: { left: '3%', right: '4%', bottom: '15%', containLabel: true }, + xAxis: { type: 'category', boundaryGap: false, data: years.map(String) }, + yAxis: { type: 'value', name: 'Werke' }, + series: series as unknown as EChartsOption['series'], + }; + }); + + 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 authorIds = this.parseList(rawAuthors); + const keywords = this.parseList(rawKeywords); + this.keywords.set(keywords); + + if (authorIds.length === 0 || keywords.length === 0) { + return; + } + + // ids in the url are bare (A5036...); the endpoint expects full OpenAlex urls + const fullIds = authorIds.map((id) => `https://openalex.org/${id}`); + + this.loading.set(true); + this.rankingService + .rankSelectedAuthor({ author_ids: fullIds, keywords: keywords }) + .subscribe({ + next: (results) => { + this.data.set(results); + this.loading.set(false); + }, + error: (error) => { + console.error(error); + this.data.set([]); + this.loading.set(false); + }, + }); + } + + private parseList(raw: string): string[] { + return raw + .split(',') + .map((value) => value.trim()) + .filter(Boolean); + } +} diff --git a/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html index fa2c9511..123b67ab 100644 --- a/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html +++ b/webapp/src/app/modules/keywords-search/search-results/persons-results/persons-results.component.html @@ -10,9 +10,26 @@

Passe die Keywords oder die Gewichtung an.

} @else { +
+ + {{ selectedIds().length }} / {{ MAX_SELECTED }} ausgewählt + + +