add author comparison feature with yearly works visualization
This commit is contained in:
@@ -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,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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.",
|
||||
)
|
||||
|
||||
@@ -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<Array<AuthorYearlyWorks>>;
|
||||
public rankSelectedAuthor(
|
||||
rankSelectedAuthorRequest: RankSelectedAuthorRequest,
|
||||
observe?: 'response',
|
||||
reportProgress?: boolean,
|
||||
options?: {
|
||||
httpHeaderAccept?: 'application/json';
|
||||
context?: HttpContext;
|
||||
transferCache?: boolean;
|
||||
},
|
||||
): Observable<HttpResponse<Array<AuthorYearlyWorks>>>;
|
||||
public rankSelectedAuthor(
|
||||
rankSelectedAuthorRequest: RankSelectedAuthorRequest,
|
||||
observe?: 'events',
|
||||
reportProgress?: boolean,
|
||||
options?: {
|
||||
httpHeaderAccept?: 'application/json';
|
||||
context?: HttpContext;
|
||||
transferCache?: boolean;
|
||||
},
|
||||
): Observable<HttpEvent<Array<AuthorYearlyWorks>>>;
|
||||
public rankSelectedAuthor(
|
||||
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 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<Array<AuthorYearlyWorks>>(
|
||||
'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,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 }>;
|
||||
}
|
||||
@@ -197,3 +197,5 @@ export * from './yearlyData';
|
||||
export * from './rankingWeights';
|
||||
export * from './rankedAuthor';
|
||||
export * from './keywordToAuthorRequest';
|
||||
export * from './rankSelectedAuthorRequest';
|
||||
export * from './authorYearlyWorks';
|
||||
|
||||
@@ -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<string>;
|
||||
/**
|
||||
* One or more keywords defining the topic.
|
||||
*/
|
||||
keywords: Array<string>;
|
||||
/**
|
||||
* How to combine the keywords: \'and\' or \'or\'. Defaults to \'and\'.
|
||||
*/
|
||||
operator?: string;
|
||||
}
|
||||
@@ -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],
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<div class="compare-layout">
|
||||
<h1>Autoren-Vergleich</h1>
|
||||
|
||||
@if (keywords().length > 0) {
|
||||
<p class="compare-keywords">Thema: {{ keywords().join(', ') }}</p>
|
||||
}
|
||||
|
||||
@if (loading()) {
|
||||
<p class="compare-hint">Lädt…</p>
|
||||
} @else if (data().length === 0) {
|
||||
<p class="compare-hint">Keine Daten für die ausgewählten Autoren.</p>
|
||||
} @else {
|
||||
<mat-card>
|
||||
<mat-card-content>
|
||||
<div
|
||||
echarts
|
||||
[options]="chartOption()"
|
||||
[autoResize]="true"
|
||||
class="chart-container"></div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
@@ -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%;
|
||||
}
|
||||
@@ -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<string[]>([]);
|
||||
readonly data = signal<AuthorYearlyWorks[]>([]);
|
||||
readonly loading = signal(false);
|
||||
|
||||
readonly chartOption = computed<EChartsOption>(() => {
|
||||
const authors = this.data();
|
||||
if (authors.length === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// shared, ascending list of every year that appears for any author
|
||||
const yearSet = new Set<number>();
|
||||
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<number, number>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
+17
@@ -10,9 +10,26 @@
|
||||
<p>Passe die Keywords oder die Gewichtung an.</p>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="results-toolbar">
|
||||
<span class="selected-hint">
|
||||
{{ selectedIds().length }} / {{ MAX_SELECTED }} ausgewählt
|
||||
</span>
|
||||
<button
|
||||
mat-flat-button
|
||||
color="primary"
|
||||
[disabled]="!canCompare()"
|
||||
(click)="compare()">
|
||||
<mat-icon>insights</mat-icon>
|
||||
Vergleichen
|
||||
</button>
|
||||
</div>
|
||||
<ul class="author-list">
|
||||
@for (author of authors(); track author.author_id) {
|
||||
<li class="author-item">
|
||||
<mat-checkbox
|
||||
class="author-select"
|
||||
[checked]="isSelected(author)"
|
||||
(change)="toggleSelect(author)" />
|
||||
<a
|
||||
class="author-name"
|
||||
[routerLink]="['/person', authorProfileId(author), 'overview']">
|
||||
|
||||
+16
-2
@@ -46,16 +46,30 @@
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.results-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 0.75rem;
|
||||
padding: 0.25rem;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.selected-hint {
|
||||
color: var(--sg-text-secondary, rgba(0, 0, 0, 0.6));
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.author-item {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.5rem 0.25rem;
|
||||
border-bottom: 1px solid var(--sg-divider, rgba(0, 0, 0, 0.08));
|
||||
}
|
||||
|
||||
.author-name {
|
||||
flex: 1;
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
color: var(--sg-primary, #1565c0);
|
||||
|
||||
+51
-1
@@ -1,10 +1,13 @@
|
||||
import { Component, OnInit, inject, signal } from '@angular/core';
|
||||
import { Component, OnInit, computed, inject, signal } from '@angular/core';
|
||||
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSliderModule } from '@angular/material/slider';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
|
||||
import {
|
||||
WeightMap,
|
||||
@@ -27,7 +30,9 @@ import { SearchResultsStateService } from '../search-results-state.service';
|
||||
imports: [
|
||||
DecimalPipe,
|
||||
RouterLink,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatCheckboxModule,
|
||||
MatIconModule,
|
||||
MatSliderModule,
|
||||
WeightsSlidersComponent,
|
||||
@@ -41,6 +46,12 @@ export class KeywordsToPersonsResultsComponent implements OnInit {
|
||||
private readonly rankingService = inject(RankingService);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly router = inject(Router);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
|
||||
// author selection for the compare view (max 4)
|
||||
readonly MAX_SELECTED = 4;
|
||||
readonly selectedIds = signal<string[]>([]);
|
||||
readonly canCompare = computed(() => this.selectedIds().length >= 1);
|
||||
|
||||
// for now only works and citations are used as metrics/weights
|
||||
readonly defaultWeights: WeightMap = {
|
||||
@@ -171,6 +182,45 @@ export class KeywordsToPersonsResultsComponent implements OnInit {
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
isSelected(author: RankedAuthor): boolean {
|
||||
return this.selectedIds().includes(this.authorProfileId(author));
|
||||
}
|
||||
|
||||
toggleSelect(author: RankedAuthor): void {
|
||||
const id = this.authorProfileId(author);
|
||||
const current = this.selectedIds();
|
||||
|
||||
if (current.includes(id)) {
|
||||
this.selectedIds.set(current.filter((existing) => existing !== id));
|
||||
return;
|
||||
}
|
||||
|
||||
if (current.length >= this.MAX_SELECTED) {
|
||||
this.snackBar.open(
|
||||
`Es können maximal ${this.MAX_SELECTED} Autoren verglichen werden.`,
|
||||
'OK',
|
||||
{ duration: 3000 },
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedIds.set([...current, id]);
|
||||
}
|
||||
|
||||
// opens the compare page; everything needed is encoded in the URL so the link is shareable
|
||||
compare(): void {
|
||||
if (!this.canCompare()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.router.navigate(['/compare'], {
|
||||
queryParams: {
|
||||
authors: this.selectedIds().join(','),
|
||||
keywords: this.state.keywords().join(','),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private loadAuthors(): void {
|
||||
const keywords = this.state.keywords();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user