feature/person-interesting #97

Merged
kuzko merged 2 commits from feature/person-interesting into dev 2026-05-29 17:05:44 +02:00
9 changed files with 272 additions and 56 deletions
+2 -1
View File
@@ -152,7 +152,8 @@ def get_topics_from_cache(topic_names: List[str]) -> List[model.Topic]:
continue
topics.append(model.Topic(
id=data.get("topic_id", ""),
name=name,
display_name=name,
count=data.get("count", 1),
subfield=data.get("subfield", ""),
field=data.get("field", ""),
domain=data.get("domain", "")
+5 -1
View File
@@ -38,11 +38,15 @@ class ItemPage(Page[Item]):
class Topic(BaseModel):
id: str = Field(description="The openalex topic id.")
name: str = Field(description="The topic name.")
display_name: str = Field(description="The topic name.")
count: int = Field(description="The number of works associated with the topic.")
subfield: str = Field(description="The subfield of the topic.")
field: str = Field(description="The field of the topic.")
domain: str = Field(description="The domain of the topic.")
class TopicShare(Topic):
count: float = Field(description="Share value (0..1) for this topic.")
class PersonBio(BaseModel):
bio: str = Field(description="The generated biography.")
@@ -0,0 +1,12 @@
<aside class="interest-card">
<h3>Interessant für</h3>
<div class="interest-tags">
@if (tags().length > 0) {
@for (tag of tags(); track tag.label) {
<button type="button" class="interest-tag-button">{{ tag.label }}</button>
}
} @else {
<span class="interest-empty">Keine Themen gefunden</span>
}
</div>
</aside>
@@ -0,0 +1,59 @@
:host {
display: block;
}
.interest-card {
align-self: center;
padding: 24px 28px;
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-muted);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.interest-card h3 {
margin: 0 0 18px;
font-size: 14px;
font-weight: 700;
}
.interest-tags {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.interest-tag-button {
padding: 9px 16px;
border: 1px solid #a8c0ff;
border-radius: 7px;
background: #ffffff;
color: var(--sg-primary);
font-size: 13px;
font-weight: 600;
cursor: pointer;
outline: none;
transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
&:hover {
background-color: var(--sg-primary-light, #f0f4ff);
border-color: var(--sg-primary);
}
&:active {
transform: scale(0.96);
}
&:focus-visible {
box-shadow: 0 0 0 2px var(--sg-primary-light, #f0f4ff), 0 0 0 4px var(--sg-primary);
}
}
.interest-tags .interest-empty {
padding: 9px 16px;
border: 1px solid #e2e8f0;
border-style: dashed;
border-radius: 7px;
color: var(--sg-text-muted);
font-size: 13px;
font-weight: 600;
}
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PersonInterestingComponent } from './person-interesting.component';
describe('PersonInterestingComponent', () => {
let component: PersonInterestingComponent;
let fixture: ComponentFixture<PersonInterestingComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PersonInterestingComponent]
})
.compileComponents();
fixture = TestBed.createComponent(PersonInterestingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,36 @@
import { Component, input, computed } from '@angular/core';
import { Topic } from '../../api';
interface InterestTag {
label: string;
score: number;
}
@Component({
selector: 'app-person-interesting',
imports: [],
templateUrl: './person-interesting.component.html',
styleUrl: './person-interesting.component.scss',
})
export class PersonInterestingComponent {
readonly topics = input<Topic[] | null>(null);
readonly tags = computed<InterestTag[]>(() => {
const topicsList = this.topics() ?? [];
const grouped = new Map<string, number>();
for (const topic of topicsList) {
const label = (topic.subfield?.display_name ?? '').trim();
if (!label) continue;
const score = typeof topic.score === 'number' ? topic.score : 0;
grouped.set(label, (grouped.get(label) ?? 0) + score);
}
return Array.from(grouped.entries())
.map(([label, score]) => ({ label, score }))
.sort((a, b) => b.score - a.score)
.slice(0, 8);
});
}
@@ -1,41 +1,56 @@
<section class="person-hero">
<div class="profile-card">
<div class="profile-avatar">AB</div>
<div class="profile-avatar">{{ initials() }}</div>
<div class="profile-main">
<div class="name-line">
<span>Prof. Dr.</span>
<h1>Anna Becker</h1>
<span>Person</span>
<h1>{{ displayName() }}</h1>
</div>
<p>Universität Duisburg-Essen</p>
<span>Fakultät für Ingenieurwissenschaften</span>
<span>Lehrstuhl für Datenanalyse</span>
<p>{{ institution() }}</p>
@if (countryCode()) {
<span>{{ countryCode() }}</span>
}
@if (worksCount() !== null || citedByCount() !== null) {
<span>
@if (worksCount() !== null) {
{{ worksCount() }} Publikationen
}
@if (worksCount() !== null && citedByCount() !== null) {
·
}
@if (citedByCount() !== null) {
{{ citedByCount() }} Zitationen
}
</span>
}
</div>
<div class="profile-contact">
<div>
<mat-icon>mail</mat-icon>
<span>anna.becker@uni-due.de</span>
</div>
<div>
<mat-icon class="orcid">verified</mat-icon>
<span>0000-0002-1234-5678</span>
</div>
@if (openAlexId()) {
<div>
<mat-icon>person</mat-icon>
<span>{{ openAlexId() }}</span>
</div>
}
@if (orcid()) {
<div>
<mat-icon class="orcid">verified</mat-icon>
<a [href]="orcidUrl()" target="_blank" rel="noopener">{{ orcid() }}</a>
</div>
}
<div>
<mat-icon>language</mat-icon>
<a href="https://ude.de/anna-becker" target="_blank" rel="noopener">ude.de/anna-becker</a>
<a href="https://ude.de/anna-becker" target="_blank" rel="noopener">
ude.de/anna-becker
</a>
</div>
</div>
</div>
<aside class="interest-card">
<h3>Interessant für</h3>
<div class="interest-tags">
<span>KI & Machine Learning</span>
<span>Datenanalyse</span>
<span>Industrie 4.0</span>
<span>Nachhaltigkeit</span>
<span>Smart Systems</span>
</div>
</aside>
<app-person-interesting [topics]="topicsFull()"></app-person-interesting>
</section>
<nav class="person-tabs" mat-tab-nav-bar [tabPanel]="tabPanel">
@@ -97,35 +97,6 @@
font-weight: 600;
}
.interest-card {
align-self: center;
padding: 24px 28px;
border-radius: var(--sg-radius-sm);
background: var(--sg-surface-muted);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.interest-card h3 {
margin: 0 0 18px;
font-size: 14px;
font-weight: 700;
}
.interest-tags {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.interest-tags span {
padding: 9px 16px;
border: 1px solid #a8c0ff;
border-radius: 7px;
background: #ffffff;
color: var(--sg-primary);
font-size: 13px;
font-weight: 600;
}
.person-tabs {
padding: 0 32px;
@@ -1,15 +1,76 @@
import { Component } from '@angular/core';
import { Component, OnDestroy, OnInit, computed, inject, signal } from '@angular/core';
import { toSignal, toObservable } from '@angular/core/rxjs-interop';
import { MatIconModule } from '@angular/material/icon';
import { MatTabsModule } from '@angular/material/tabs';
import { RouterModule, RouterOutlet } from '@angular/router';
import { ActivatedRoute, RouterModule, RouterOutlet } from '@angular/router';
import { Subscription, map, of, switchMap } from 'rxjs';
import { Person, PersonsOpenApiService, Topic } from '../../api';
import { PersonInterestingComponent } from '../person-interesting/person-interesting.component';
const PERSON_INCLUDE_TAGS =
'topics_full,topic_share,summary_stats,ids,last_known_institutions,' +
'sources,counts_by_year,works_api_url,dates,cited_by_count_boost';
@Component({
selector: 'app-person',
imports: [MatIconModule, MatTabsModule, RouterOutlet, RouterModule],
imports: [
MatIconModule,
MatTabsModule,
PersonInterestingComponent,
RouterOutlet,
RouterModule,
],
templateUrl: './person.component.html',
styleUrl: './person.component.scss',
})
export class PersonComponent {
export class PersonComponent implements OnInit, OnDestroy {
private route = inject(ActivatedRoute);
private readonly personsApi = inject(PersonsOpenApiService);
private routeSub?: Subscription;
private readonly authorId = signal<string | null>(null);
readonly person = toSignal(
toObservable(this.authorId).pipe(
switchMap((id) => {
if (!id) {
return of(null);
}
return this.personsApi.searchPersons(id, undefined, PERSON_INCLUDE_TAGS).pipe(
map((result) => result.persons?.[0] ?? null),
);
}),
),
{ initialValue: null },
);
readonly displayName = computed(
() => this.person()?.name ?? 'Unbekannte Person',
);
readonly initials = computed(() => this.buildInitials(this.displayName()));
readonly primaryAffiliation = computed(
() => this.person()?.affiliations?.[0] ?? null,
);
readonly institution = computed(
() => this.primaryAffiliation()?.institution ?? 'Unbekannte Institution',
);
readonly countryCode = computed(
() => this.primaryAffiliation()?.country_code ?? null,
);
readonly worksCount = computed(() => this.person()?.works_count ?? null);
readonly citedByCount = computed(() => this.person()?.cited_by_count ?? null);
readonly orcid = computed(() => this.getId('orcid'));
readonly orcidUrl = computed(() =>
this.orcid() ? `https://orcid.org/${this.orcid()}` : null,
);
readonly worksApiUrl = computed(() => this.person()?.works_api_url ?? null);
readonly openAlexId = computed(() => this.person()?.id ?? null);
readonly topicsFull = computed(
() => (this.person()?.topics_full ?? []) as Topic[],
);
links = [
{ label: 'Übersicht', path: 'overview', disabled: false },
{ label: 'Projekte', path: 'projects', disabled: true },
@@ -17,4 +78,38 @@ export class PersonComponent {
{ label: 'Netzwerk', path: 'network', disabled: false },
{ label: 'Gründungen', path: 'foundings', disabled: true },
];
ngOnInit(): void {
this.routeSub = this.route.paramMap.subscribe((params) => {
const authorId = params.get('id') ?? '';
this.authorId.set(authorId ? authorId : null);
});
}
ngOnDestroy(): void {
this.routeSub?.unsubscribe();
}
private getId(key: string): string | null {
const ids = this.person()?.ids as Record<string, string> | undefined;
if (!ids) {
return null;
}
const value = ids[key];
return value ? String(value) : null;
}
private buildInitials(name: string): string {
const parts = name.trim().split(/\s+/).filter(Boolean);
if (parts.length === 0) {
return '??';
}
if (parts.length === 1) {
return parts[0].slice(0, 2).toUpperCase();
}
return `${parts[0][0]}${parts[1][0]}`.toUpperCase();
}
}