feat(collaboration-graph-v2): moved graph size validation to backend
This commit is contained in:
@@ -612,13 +612,59 @@ def get_collaboration_graph_status(
|
||||
job.status,
|
||||
)
|
||||
|
||||
return CollaborationGraphStatusResponse(
|
||||
status=job.status,
|
||||
result=job.get_result()
|
||||
if job.status == CollaborationGraphStatus.COMPLETED
|
||||
else None,
|
||||
error_message=job.error_message,
|
||||
status = job.status
|
||||
result = (
|
||||
job.get_result() if job.status == CollaborationGraphStatus.COMPLETED else None
|
||||
)
|
||||
error_message = job.error_message
|
||||
if result and job.status == CollaborationGraphStatus.COMPLETED:
|
||||
if _is_graph_empty(result):
|
||||
status = CollaborationGraphStatus.FAILED
|
||||
result = None
|
||||
error_message = "Der generierte Kollaborationsgraph ist leer. Bitte versuchen Sie es mit anderen Filtereinstellungen."
|
||||
logger.debug(
|
||||
"Collaboration graph for graph ID: %s is empty, marking as failed.",
|
||||
graph_id,
|
||||
)
|
||||
elif _is_graph_too_large(result):
|
||||
status = CollaborationGraphStatus.FAILED
|
||||
result = None
|
||||
error_message = "Der generierte Kollaborationsgraph ist zu groß, um ihn anzuzeigen. Bitte versuchen Sie es mit anderen Filtereinstellungen."
|
||||
logger.debug(
|
||||
"Collaboration graph for graph ID: %s is too large, marking as failed.",
|
||||
graph_id,
|
||||
)
|
||||
|
||||
return CollaborationGraphStatusResponse(
|
||||
status=status,
|
||||
result=result,
|
||||
error_message=error_message,
|
||||
)
|
||||
|
||||
|
||||
def _is_graph_empty(graph: CollaborationGraph) -> bool:
|
||||
"""Returns True if the collaboration graph has no authors, works, or institutions.
|
||||
|
||||
Args:
|
||||
graph (CollaborationGraph): The collaboration graph to check.
|
||||
|
||||
Returns:
|
||||
bool: True if the graph is empty, False otherwise.
|
||||
"""
|
||||
return not (graph.authors or graph.works or graph.institutions)
|
||||
|
||||
|
||||
def _is_graph_too_large(graph: CollaborationGraph, max_nodes: int = 1000) -> bool:
|
||||
"""Returns True if the total number of nodes (authors, works, and institutions) in the graph exceeds the specified max_nodes limit.
|
||||
|
||||
Args:
|
||||
graph (CollaborationGraph): The collaboration graph to check.
|
||||
max_nodes (int, optional): The maximum number of nodes allowed. Defaults to 1000.
|
||||
|
||||
Returns:
|
||||
bool: True if the graph is too large, False otherwise.
|
||||
"""
|
||||
return len(graph.authors + graph.works + graph.institutions) > max_nodes
|
||||
|
||||
|
||||
def _prefix_id(raw_oa_id: str) -> str:
|
||||
|
||||
@@ -4,8 +4,27 @@
|
||||
<p>Zusammenarbeit und Verbindungen im wissenschaftlichen Netzwerk.</p>
|
||||
</div>
|
||||
|
||||
@if (!collaborationGraph()) {
|
||||
<span>Laden...</span>
|
||||
@if (this.isPending()) {
|
||||
<app-loading
|
||||
text="Das Netzwerk wird gebaut, kleinen Moment..."
|
||||
icon="graph_3"
|
||||
[size]="150"
|
||||
[diameter]="150" />
|
||||
} @else if (this.isFailed()) {
|
||||
<div class="error">
|
||||
<mat-icon>error</mat-icon>
|
||||
<span class="error-message">{{
|
||||
this.collaborationGraphError()
|
||||
? this.collaborationGraphError()
|
||||
: 'Fehler beim Laden des Netzwerks. Bitte versuchen Sie es später erneut.'
|
||||
}}</span>
|
||||
|
||||
<app-selected-filters [observers]="observers" />
|
||||
<button matButton="outlined" type="button" (click)="openFilterDialog()">
|
||||
<mat-icon>filter_alt</mat-icon>
|
||||
Filter
|
||||
</button>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="cards">
|
||||
<mat-card appearance="outlined" style="width: 50%">
|
||||
@@ -22,15 +41,15 @@
|
||||
class="mat-button-toggle-group"
|
||||
aria-label="Select view"
|
||||
(change)="onToggleChange($event)"
|
||||
[formField]="filterForm2.displayedTable"
|
||||
[value]="displayedTable()"
|
||||
style="width: 100%">
|
||||
<mat-button-toggle value="collaborators">
|
||||
<mat-button-toggle value="collaborator">
|
||||
Kollaborierende
|
||||
</mat-button-toggle>
|
||||
<mat-button-toggle value="publications"
|
||||
<mat-button-toggle value="publication"
|
||||
>Publikationen</mat-button-toggle
|
||||
>
|
||||
<mat-button-toggle value="institutions">
|
||||
<mat-button-toggle value="institution">
|
||||
Institutionen
|
||||
</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
@@ -53,21 +72,21 @@
|
||||
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-content class="scroll-viewport-container">
|
||||
@if (this.displayedTable() === 'collaborators') {
|
||||
@if (this.displayedTable() === 'collaborator') {
|
||||
<app-data-table
|
||||
[columns]="collaboratorsColumns"
|
||||
[data]="collaboratorsData()"
|
||||
[filterTerm]="searchTerm()"
|
||||
[detailTemplate]="collaboratorsDetailRow"
|
||||
[maxHeight]="'100%'" />
|
||||
} @else if (this.displayedTable() === 'publications') {
|
||||
} @else if (this.displayedTable() === 'publication') {
|
||||
<app-data-table
|
||||
[columns]="publicationsColumns"
|
||||
[data]="publicationsData()"
|
||||
[filterTerm]="searchTerm()"
|
||||
[detailTemplate]="publicationsDetailRow"
|
||||
[maxHeight]="'100%'" />
|
||||
} @else if (this.displayedTable() === 'institutions') {
|
||||
} @else if (this.displayedTable() === 'institution') {
|
||||
<app-data-table
|
||||
[columns]="institutionsColumns"
|
||||
[data]="institutionsData()"
|
||||
|
||||
@@ -31,15 +31,9 @@
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.filter-button {
|
||||
border-radius: var(--sg-radius-sm);
|
||||
color: var(--sg-text);
|
||||
}
|
||||
|
||||
.mat-button-toggle-group {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: var(--sg-radius-sm);
|
||||
color: var(--sg-text);
|
||||
text-transform: none;
|
||||
}
|
||||
@@ -64,6 +58,7 @@
|
||||
}
|
||||
|
||||
mat-card {
|
||||
border: 1px solid var(--sg-border);
|
||||
background-color: var(--sg-background);
|
||||
}
|
||||
|
||||
@@ -74,3 +69,18 @@ mat-card {
|
||||
.link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.error {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
color: var(--sg-error);
|
||||
min-height: 25vh;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: var(--sg-error);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ import {
|
||||
} from '../../shared/ui/selected-filters/selected-filters.component';
|
||||
import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component';
|
||||
import { from, interval, startWith, switchMap, takeWhile, tap } from 'rxjs';
|
||||
import { LoadingComponent } from '../../shared/ui/loading/loading.component';
|
||||
|
||||
type DetailedWorkNode = WorkNode & {
|
||||
authors: AuthorNode[];
|
||||
@@ -78,7 +79,6 @@ type DetailedInstitutionNode = InstitutionNode & {
|
||||
};
|
||||
|
||||
interface FilterData {
|
||||
displayedTable: string;
|
||||
startYear: number;
|
||||
endYear: number;
|
||||
minContributors: number;
|
||||
@@ -109,6 +109,7 @@ interface FilterData {
|
||||
FormField,
|
||||
SelectedFiltersComponent,
|
||||
QueryParamInputComponent,
|
||||
LoadingComponent,
|
||||
],
|
||||
templateUrl: './person-network.component.html',
|
||||
styleUrl: './person-network.component.scss',
|
||||
@@ -117,12 +118,17 @@ interface FilterData {
|
||||
export class PersonNetworkComponent implements OnInit {
|
||||
startCollaborationGraphResponse =
|
||||
input.required<StartCollaborationGraphResponse>();
|
||||
|
||||
collaborationGraph = signal<CollaborationGraph | undefined>(undefined);
|
||||
collaborationGraphStatus = signal<CollaborationGraphStatus>(
|
||||
CollaborationGraphStatus.Pending,
|
||||
);
|
||||
collaborationGraphError = signal<string | undefined>(undefined);
|
||||
|
||||
selectedTopics = input.required<TopicPageV2>();
|
||||
selectedInstitutions = input.required<InstitutionPageV2>();
|
||||
|
||||
filterModel = signal<FilterData>({
|
||||
displayedTable: 'collaborators',
|
||||
startYear: 2020,
|
||||
endYear: new Date().getFullYear(),
|
||||
minContributors: 2,
|
||||
@@ -131,10 +137,23 @@ export class PersonNetworkComponent implements OnInit {
|
||||
institutions: [],
|
||||
});
|
||||
|
||||
displayedTable = computed(() => this.filterForm2.displayedTable().value());
|
||||
displayedTable = computed(
|
||||
() => this.queryParamMap().get('table') || 'collaborator',
|
||||
);
|
||||
|
||||
filterForm2 = form(this.filterModel);
|
||||
|
||||
isPending = computed(
|
||||
() => this.collaborationGraphStatus() === CollaborationGraphStatus.Pending,
|
||||
);
|
||||
isCompleted = computed(
|
||||
() =>
|
||||
this.collaborationGraphStatus() === CollaborationGraphStatus.Completed,
|
||||
);
|
||||
isFailed = computed(
|
||||
() => this.collaborationGraphStatus() === CollaborationGraphStatus.Failed,
|
||||
);
|
||||
|
||||
observers: FilterObserver[] = [
|
||||
{
|
||||
id: 'searchTerm',
|
||||
@@ -281,13 +300,13 @@ export class PersonNetworkComponent implements OnInit {
|
||||
connections = computed(() => this.collaborationGraph()?.edges?.length ?? 0);
|
||||
|
||||
searchTermLabel = computed(() => {
|
||||
const displayedTable = this.filterForm2.displayedTable().value();
|
||||
const displayedTable = this.displayedTable();
|
||||
switch (displayedTable) {
|
||||
case 'collaborators':
|
||||
case 'collaborator':
|
||||
return 'Suche Kollaborierende nach Name';
|
||||
case 'publications':
|
||||
case 'publication':
|
||||
return 'Suche Publikationen nach Titel';
|
||||
case 'institutions':
|
||||
case 'institution':
|
||||
return 'Suche Institutionen nach Name';
|
||||
default:
|
||||
return 'Suchbegriff';
|
||||
@@ -295,10 +314,10 @@ export class PersonNetworkComponent implements OnInit {
|
||||
});
|
||||
|
||||
private readonly categoryTableMap: Record<NodeCategory, string> = {
|
||||
author: 'collaborators',
|
||||
collaborator: 'collaborators',
|
||||
work: 'publications',
|
||||
institution: 'institutions',
|
||||
author: 'collaborator',
|
||||
collaborator: 'collaborator',
|
||||
work: 'publication',
|
||||
institution: 'institution',
|
||||
};
|
||||
|
||||
latestNodeId = signal<string | null>(null);
|
||||
@@ -357,6 +376,7 @@ export class PersonNetworkComponent implements OnInit {
|
||||
}
|
||||
|
||||
handleNodeClick = ({ id, name, category }: NodeClickEvent): void => {
|
||||
console.log('Node clicked:', { id, name, category });
|
||||
if (this.latestNodeId() === id) {
|
||||
this.clearSearch();
|
||||
return;
|
||||
@@ -371,7 +391,7 @@ export class PersonNetworkComponent implements OnInit {
|
||||
relativeTo: this.activatedRoute,
|
||||
queryParams: {
|
||||
search_term: name,
|
||||
table: this.categoryTableMap[category] || 'collaborators',
|
||||
table: this.categoryTableMap[category] || 'collaborator',
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
@@ -439,9 +459,13 @@ export class PersonNetworkComponent implements OnInit {
|
||||
),
|
||||
),
|
||||
tap((statusResponse) => {
|
||||
this.collaborationGraphStatus.set(statusResponse.status);
|
||||
this.collaborationGraphError.set(
|
||||
statusResponse.error_message ?? undefined,
|
||||
);
|
||||
if (
|
||||
statusResponse.status === CollaborationGraphStatus.Completed &&
|
||||
statusResponse.result
|
||||
statusResponse.result &&
|
||||
statusResponse.status === CollaborationGraphStatus.Completed
|
||||
) {
|
||||
this.collaborationGraph.set(
|
||||
this.rebuildCollaborationGraph(statusResponse.result),
|
||||
@@ -449,9 +473,7 @@ export class PersonNetworkComponent implements OnInit {
|
||||
}
|
||||
}),
|
||||
takeWhile((statusResponse) => {
|
||||
return (
|
||||
statusResponse.status !== CollaborationGraphStatus.Completed
|
||||
);
|
||||
return statusResponse.status === CollaborationGraphStatus.Pending;
|
||||
}, true),
|
||||
),
|
||||
),
|
||||
@@ -464,7 +486,6 @@ export class PersonNetworkComponent implements OnInit {
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.activatedRoute,
|
||||
queryParams: {
|
||||
table: filters.displayedTable || null,
|
||||
[collaborationGraphQueryParamKeys.yearFrom]:
|
||||
filters.startYear || null,
|
||||
[collaborationGraphQueryParamKeys.yearTo]: filters.endYear || null,
|
||||
@@ -474,11 +495,11 @@ export class PersonNetworkComponent implements OnInit {
|
||||
filters.maxContributors || null,
|
||||
[collaborationGraphQueryParamKeys.topicId]:
|
||||
filters.topics.length > 0
|
||||
? filters.topics.map((topic) => topic.id).join(',')
|
||||
? filters.topics.map((topic) => topic.id)
|
||||
: null,
|
||||
[collaborationGraphQueryParamKeys.institutionId]:
|
||||
filters.institutions.length > 0
|
||||
? filters.institutions.map((inst) => inst.id).join(',')
|
||||
? filters.institutions.map((inst) => inst.id)
|
||||
: null,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
@@ -503,7 +524,6 @@ export class PersonNetworkComponent implements OnInit {
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
if (result) {
|
||||
this.filterModel.set({
|
||||
displayedTable: this.filterForm2.displayedTable().value(),
|
||||
startYear: result.startYear,
|
||||
endYear: result.endYear,
|
||||
minContributors: result.minContributors,
|
||||
@@ -518,7 +538,6 @@ export class PersonNetworkComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
const queryParamMap = this.queryParamMap();
|
||||
this.filterModel.set({
|
||||
displayedTable: queryParamMap.get('table') || 'collaborators',
|
||||
startYear:
|
||||
Number(queryParamMap.get(collaborationGraphQueryParamKeys.yearFrom)) ||
|
||||
2020,
|
||||
@@ -604,7 +623,13 @@ export class PersonNetworkComponent implements OnInit {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
this.filterForm2.displayedTable().value.set(value);
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.activatedRoute,
|
||||
queryParams: {
|
||||
table: value,
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
stripOpenAlexIdPrefix(id: string): string {
|
||||
|
||||
@@ -163,20 +163,12 @@
|
||||
}
|
||||
</nav>
|
||||
} @else {
|
||||
<div class="loading">
|
||||
<mat-progress-spinner diameter="40">
|
||||
<span>Person wird geladen...</span>
|
||||
</mat-progress-spinner>
|
||||
</div>
|
||||
<app-loading
|
||||
text="Person wird geladen..."
|
||||
icon="person"
|
||||
[size]="150"
|
||||
[diameter]="150"></app-loading>
|
||||
}
|
||||
<mat-tab-nav-panel #tabPanel class="person-panel">
|
||||
@if (isNetworkResolving()) {
|
||||
<app-loading
|
||||
text="Das Netzwerk wird gebaut, kleinen Moment..."
|
||||
icon="graph_3"
|
||||
[size]="150"
|
||||
[diameter]="150" />
|
||||
} @else {
|
||||
<router-outlet></router-outlet>
|
||||
}
|
||||
<router-outlet></router-outlet>
|
||||
</mat-tab-nav-panel>
|
||||
|
||||
@@ -6,15 +6,11 @@ import {
|
||||
takeUntilDestroyed,
|
||||
} from '@angular/core/rxjs-interop';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import {
|
||||
ActivatedRoute,
|
||||
ResolveEnd,
|
||||
ResolveStart,
|
||||
Router,
|
||||
RouterEvent,
|
||||
RouterModule,
|
||||
RouterOutlet,
|
||||
} from '@angular/router';
|
||||
@@ -38,7 +34,6 @@ import { collaborationGraphQueryParamKeys } from '../../resolvers/collaboration-
|
||||
PersonInterestingComponent,
|
||||
RouterOutlet,
|
||||
RouterModule,
|
||||
MatProgressSpinner,
|
||||
LoadingComponent,
|
||||
],
|
||||
templateUrl: './person.component.html',
|
||||
@@ -72,32 +67,6 @@ export class PersonComponent {
|
||||
),
|
||||
);
|
||||
|
||||
readonly isNetworkResolving = computed(() => {
|
||||
const event = this.routerEvents();
|
||||
|
||||
if (
|
||||
!(event instanceof RouterEvent) ||
|
||||
!this.isResolverEvent(event) ||
|
||||
!this.isNetworkRouterEvent(event)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (event instanceof ResolveStart) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
isResolverEvent(event: RouterEvent): boolean {
|
||||
return event instanceof ResolveStart || event instanceof ResolveEnd;
|
||||
}
|
||||
|
||||
isNetworkRouterEvent(event: RouterEvent): boolean {
|
||||
return event.url.startsWith(`/person/${this.authorId()}/network`);
|
||||
}
|
||||
|
||||
readonly isPersonLoading = signal(false);
|
||||
readonly isBioLoading = signal(false);
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
.info-card {
|
||||
--info-card-icon-size: 40px;
|
||||
|
||||
background-color: var(--sg-background);
|
||||
padding: 10px 20px;
|
||||
padding: 0.5rem 1rem;
|
||||
text-wrap: break-word;
|
||||
}
|
||||
.info-card mat-card-content {
|
||||
display: flex;
|
||||
align-items: start;
|
||||
gap: 10px;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.info-card mat-icon {
|
||||
@@ -20,15 +20,15 @@
|
||||
.info-card div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.info-card .number {
|
||||
font-weight: var(--sg-default-bold-weight);
|
||||
font-size: 1.5em;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.info-card .description {
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 0.9em;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,46 @@ body {
|
||||
|
||||
--sg-blue-highlight: #3d7cff;
|
||||
--sg-default-bold-weight: 900;
|
||||
|
||||
@include mat.button-toggle-overrides(
|
||||
(
|
||||
shape: var(--sg-radius-sm),
|
||||
divider-color: var(--sg-border),
|
||||
)
|
||||
);
|
||||
|
||||
@include mat.form-field-overrides(
|
||||
(
|
||||
outlined-container-shape: var(--sg-radius-sm),
|
||||
outlined-outline-color: var(--sg-border),
|
||||
)
|
||||
);
|
||||
|
||||
@include mat.card-overrides(
|
||||
(
|
||||
outlined-container-color: var(--sg-background),
|
||||
outlined-outline-color: var(--sg-border),
|
||||
)
|
||||
);
|
||||
|
||||
@include mat.divider-overrides(
|
||||
(
|
||||
color: var(--sg-border),
|
||||
)
|
||||
);
|
||||
|
||||
@include mat.select-overrides(
|
||||
(
|
||||
panel-background-color: var(--sg-surface),
|
||||
)
|
||||
);
|
||||
|
||||
@include mat.button-overrides(
|
||||
(
|
||||
outlined-container-shape: var(--sg-radius-sm),
|
||||
outlined-outline-color: var(--sg-border),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
* {
|
||||
|
||||
Reference in New Issue
Block a user