attempt to optimize backend search time and small modeltype changes
This commit is contained in:
+12
-2
@@ -147,9 +147,13 @@
|
||||
@for (result of searchResults(); track result.id) {
|
||||
<li>
|
||||
<button
|
||||
(click)="addInstitution(result.id, result.display_name)">
|
||||
(click)="
|
||||
addInstitution(result.id || '', result.display_name || '')
|
||||
">
|
||||
<span class="name">{{ result.display_name }}</span>
|
||||
<span class="hint">{{ result.hint || result.type }}</span>
|
||||
<span class="hint">{{
|
||||
result.hint || result.entity_type
|
||||
}}</span>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
@@ -217,6 +221,12 @@
|
||||
title="Shows total absolute publication counts.">
|
||||
📊 Total Volume
|
||||
</button>
|
||||
<button
|
||||
[class.active]="chartMode() === 'cumulative'"
|
||||
(click)="setChartMode('cumulative')"
|
||||
title="Shows normalized cumulative publications growth (S-Curve).">
|
||||
📈 S-Curve (Normalized)
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+158
-59
@@ -12,6 +12,15 @@ import {
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { forkJoin } from 'rxjs';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { UniTrendChartComponent } from '../uni-trend-chart/uni-trend-chart.component';
|
||||
import {
|
||||
TrendResponse,
|
||||
@@ -20,14 +29,32 @@ import {
|
||||
TopInstitutionItem,
|
||||
AutocompleteLocationItem,
|
||||
AutocompleteResponse,
|
||||
AutocompleteResponseResultsInner,
|
||||
UniversityRankingsService,
|
||||
InstitutionsService,
|
||||
} from '../../../api';
|
||||
|
||||
export interface CompareItem {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-uni-trend-parent',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule, UniTrendChartComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
UniTrendChartComponent,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
MatCheckboxModule,
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatAutocompleteModule,
|
||||
],
|
||||
templateUrl: './uni-trend-parent.component.html',
|
||||
styleUrl: './uni-trend-parent.component.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
@@ -47,19 +74,23 @@ export class UniTrendParentComponent implements OnInit {
|
||||
readonly primaryInstitutionName = signal<string>(
|
||||
'University of Duisburg-Essen',
|
||||
);
|
||||
readonly comparisonInstitutions = signal<{ id: string; name: string }[]>([]);
|
||||
readonly comparisonCountries = signal<{ id: string; name: string }[]>([]);
|
||||
readonly comparisonRegions = signal<{ id: string; name: string }[]>([]);
|
||||
readonly startYear = signal<number>(2015);
|
||||
readonly endYear = signal<number>(new Date().getFullYear() - 1);
|
||||
readonly chartMode = signal<'normalized' | 'total'>('total');
|
||||
readonly comparisonInstitutions = signal<CompareItem[]>([]);
|
||||
readonly comparisonCountries = signal<CompareItem[]>([
|
||||
{ id: 'DE', name: 'Germany' },
|
||||
]);
|
||||
readonly comparisonRegions = signal<CompareItem[]>([]);
|
||||
readonly startYear = signal<number>(2010);
|
||||
readonly endYear = signal<number>(2025);
|
||||
readonly chartMode = signal<'normalized' | 'total' | 'cumulative'>(
|
||||
'normalized',
|
||||
);
|
||||
readonly activeChartTopic = signal<string>('');
|
||||
|
||||
// Cached parameters of the last active search request to track "isDirty"
|
||||
readonly fetchedTopics = signal<string[]>([]);
|
||||
readonly fetchedInstitutions = signal<{ id: string; name: string }[]>([]);
|
||||
readonly fetchedCountries = signal<{ id: string; name: string }[]>([]);
|
||||
readonly fetchedRegions = signal<{ id: string; name: string }[]>([]);
|
||||
readonly fetchedInstitutions = signal<CompareItem[]>([]);
|
||||
readonly fetchedCountries = signal<CompareItem[]>([]);
|
||||
readonly fetchedRegions = signal<CompareItem[]>([]);
|
||||
|
||||
// Results & Loading signals
|
||||
readonly rawTrendResponse = signal<TrendResponse | null>(null);
|
||||
@@ -69,7 +100,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
|
||||
// Autocomplete UI state
|
||||
readonly searchQuery = signal<string>('');
|
||||
readonly searchResults = signal<any[]>([]);
|
||||
readonly searchResults = signal<AutocompleteResponseResultsInner[]>([]);
|
||||
readonly locationQuery = signal<string>('');
|
||||
readonly locationSearchResults = signal<AutocompleteLocationItem[]>([]);
|
||||
|
||||
@@ -82,13 +113,13 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (!raw) return null;
|
||||
|
||||
const currentInstIds = new Set(
|
||||
this.comparisonInstitutions().map((i) => i.id.toLowerCase()),
|
||||
this.comparisonInstitutions().map((i: CompareItem) => i.id.toLowerCase()),
|
||||
);
|
||||
const currentCountryIds = new Set(
|
||||
this.comparisonCountries().map((c) => c.id.toLowerCase()),
|
||||
this.comparisonCountries().map((c: CompareItem) => c.id.toLowerCase()),
|
||||
);
|
||||
const currentRegionIds = new Set(
|
||||
this.comparisonRegions().map((r) => r.id.toLowerCase()),
|
||||
this.comparisonRegions().map((r: CompareItem) => r.id.toLowerCase()),
|
||||
);
|
||||
const defaultInstId = 'https://openalex.org/I62318514'.toLowerCase();
|
||||
|
||||
@@ -97,17 +128,9 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (s.entity_type === 'institution') {
|
||||
return id === defaultInstId || currentInstIds.has(id);
|
||||
} else if (s.entity_type === 'country') {
|
||||
return (
|
||||
currentCountryIds.has(id) ||
|
||||
currentCountryIds.has('https://openalex.org/countries/' + id) ||
|
||||
Array.from(currentCountryIds).some((cid) => cid.endsWith('/' + id))
|
||||
);
|
||||
return currentCountryIds.has(id);
|
||||
} else if (s.entity_type === 'region') {
|
||||
return (
|
||||
currentRegionIds.has(id) ||
|
||||
currentRegionIds.has('https://openalex.org/continents/' + id) ||
|
||||
Array.from(currentRegionIds).some((rid) => rid.endsWith('/' + id))
|
||||
);
|
||||
return currentRegionIds.has(id);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@@ -121,31 +144,31 @@ export class UniTrendParentComponent implements OnInit {
|
||||
// Computed dirty state to enable "Search" button
|
||||
readonly isDirty = computed(() => {
|
||||
const fetchedInsts = this.fetchedInstitutions()
|
||||
.map((i) => i.id)
|
||||
.map((i: CompareItem) => i.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
const currentInsts = this.comparisonInstitutions()
|
||||
.map((i) => i.id)
|
||||
.map((i: CompareItem) => i.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
if (fetchedInsts !== currentInsts) return true;
|
||||
|
||||
const fetchedC = this.fetchedCountries()
|
||||
.map((c) => c.id)
|
||||
.map((c: CompareItem) => c.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
const currentC = this.comparisonCountries()
|
||||
.map((c) => c.id)
|
||||
.map((c: CompareItem) => c.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
if (fetchedC !== currentC) return true;
|
||||
|
||||
const fetchedR = this.fetchedRegions()
|
||||
.map((r) => r.id)
|
||||
.map((r: CompareItem) => r.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
const currentR = this.comparisonRegions()
|
||||
.map((r) => r.id)
|
||||
.map((r: CompareItem) => r.id)
|
||||
.sort()
|
||||
.join(',');
|
||||
if (fetchedR !== currentR) return true;
|
||||
@@ -173,7 +196,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
|
||||
if (kws.length > 0) {
|
||||
// Find existing selections that are still in keywords, or default to all
|
||||
const validSelections = currentSelections.filter((t) =>
|
||||
const validSelections = currentSelections.filter((t: string) =>
|
||||
kws.includes(t),
|
||||
);
|
||||
if (validSelections.length > 0) {
|
||||
@@ -188,6 +211,12 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (!active || !updatedSelections.includes(active)) {
|
||||
this.activeChartTopic.set(updatedSelections[0] || '');
|
||||
}
|
||||
|
||||
// If comparison list is empty, initialize default institutions dynamically
|
||||
const currentInsts = untracked(() => this.comparisonInstitutions());
|
||||
if (currentInsts.length === 0) {
|
||||
untracked(() => this.initializeDefaultInstitutions());
|
||||
}
|
||||
} else {
|
||||
this.selectedTrendTopics.set([]);
|
||||
}
|
||||
@@ -202,7 +231,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
const insts = Array.isArray(params['institutions'])
|
||||
? params['institutions']
|
||||
: [params['institutions']];
|
||||
const parsed = insts.map((i) => {
|
||||
const parsed = insts.map((i: string) => {
|
||||
const parts = i.split('|');
|
||||
return { id: parts[0], name: parts[1] || parts[0] };
|
||||
});
|
||||
@@ -213,7 +242,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
const ccs = Array.isArray(params['countries'])
|
||||
? params['countries']
|
||||
: [params['countries']];
|
||||
const parsed = ccs.map((c) => {
|
||||
const parsed = ccs.map((c: string) => {
|
||||
const parts = c.split('|');
|
||||
return { id: parts[0], name: parts[1] || parts[0] };
|
||||
});
|
||||
@@ -224,7 +253,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
const regs = Array.isArray(params['regions'])
|
||||
? params['regions']
|
||||
: [params['regions']];
|
||||
const parsed = regs.map((r) => {
|
||||
const parsed = regs.map((r: string) => {
|
||||
const parts = r.split('|');
|
||||
return { id: parts[0], name: parts[1] || parts[0] };
|
||||
});
|
||||
@@ -243,16 +272,69 @@ export class UniTrendParentComponent implements OnInit {
|
||||
if (params['active_chart_topic']) {
|
||||
this.activeChartTopic.set(params['active_chart_topic']);
|
||||
}
|
||||
|
||||
// Auto-trigger load once on initial page render if keywords are present
|
||||
if (this.rawTrendResponse() === null && this.keywords().length > 0) {
|
||||
this.fetchTrendData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadTrendSuggestions();
|
||||
this.initializeDefaultInstitutions();
|
||||
}
|
||||
|
||||
// Dynamically load top institutions to initialize comparisons using the top-institutions service
|
||||
initializeDefaultInstitutions() {
|
||||
const kws = this.keywords();
|
||||
if (kws.length === 0) return;
|
||||
|
||||
const topic = kws[0];
|
||||
this.isSuggestionsLoading.set(true);
|
||||
|
||||
forkJoin({
|
||||
deInsts:
|
||||
this.apiService.getTopInstitutionsApiInseServiceUniversityRankingsTopInstitutionsGet(
|
||||
topic,
|
||||
undefined,
|
||||
'DE',
|
||||
2,
|
||||
),
|
||||
overallInsts:
|
||||
this.apiService.getTopInstitutionsApiInseServiceUniversityRankingsTopInstitutionsGet(
|
||||
topic,
|
||||
undefined,
|
||||
undefined,
|
||||
2,
|
||||
),
|
||||
}).subscribe({
|
||||
next: ({
|
||||
deInsts,
|
||||
overallInsts,
|
||||
}: {
|
||||
deInsts: Array<TopInstitutionItem>;
|
||||
overallInsts: Array<TopInstitutionItem>;
|
||||
}) => {
|
||||
const uniqueInsts = new Map<string, string>();
|
||||
|
||||
// Add DE ones
|
||||
deInsts.forEach((inst: TopInstitutionItem) => {
|
||||
if (inst.id) uniqueInsts.set(inst.id, inst.display_name || 'Unknown');
|
||||
});
|
||||
|
||||
// Add overall ones
|
||||
overallInsts.forEach((inst: TopInstitutionItem) => {
|
||||
if (inst.id) uniqueInsts.set(inst.id, inst.display_name || 'Unknown');
|
||||
});
|
||||
|
||||
const list = Array.from(uniqueInsts.entries()).map(([id, name]) => ({
|
||||
id,
|
||||
name,
|
||||
}));
|
||||
this.comparisonInstitutions.set(list);
|
||||
this.isSuggestionsLoading.set(false);
|
||||
},
|
||||
error: (err: any) => {
|
||||
console.error('Failed to load default institutions dynamically:', err);
|
||||
this.isSuggestionsLoading.set(false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch recommended institutions for comparison based on current topics
|
||||
@@ -268,11 +350,11 @@ export class UniTrendParentComponent implements OnInit {
|
||||
|
||||
const countryFilter =
|
||||
this.comparisonCountries().length > 0
|
||||
? this.comparisonCountries()[0].id.split('/').pop()
|
||||
? this.comparisonCountries()[0].id
|
||||
: undefined;
|
||||
const regionFilter =
|
||||
this.comparisonRegions().length > 0
|
||||
? this.comparisonRegions()[0].name
|
||||
? this.comparisonRegions()[0].id
|
||||
: undefined;
|
||||
|
||||
this.apiService
|
||||
@@ -283,7 +365,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
6,
|
||||
)
|
||||
.subscribe({
|
||||
next: (res) => {
|
||||
next: (res: any) => {
|
||||
this.topSuggestions.set(res || []);
|
||||
this.isSuggestionsLoading.set(false);
|
||||
},
|
||||
@@ -309,12 +391,12 @@ export class UniTrendParentComponent implements OnInit {
|
||||
this.apiService
|
||||
.getTrendApiInseServiceUniversityRankingsTrendGet(
|
||||
topics,
|
||||
this.comparisonInstitutions().map((i) => i.id),
|
||||
this.comparisonCountries().map((c) => c.id),
|
||||
this.comparisonRegions().map((r) => r.id),
|
||||
this.comparisonInstitutions().map((i: CompareItem) => i.id),
|
||||
this.comparisonCountries().map((c: CompareItem) => c.id),
|
||||
this.comparisonRegions().map((r: CompareItem) => r.id),
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
next: (response: TrendResponse) => {
|
||||
this.rawTrendResponse.set(response);
|
||||
this.isTrendLoading.set(false);
|
||||
this.updateUrlParams();
|
||||
@@ -331,15 +413,21 @@ export class UniTrendParentComponent implements OnInit {
|
||||
trend_topics: this.selectedTrendTopics(),
|
||||
institutions:
|
||||
this.comparisonInstitutions().length > 0
|
||||
? this.comparisonInstitutions().map((i) => `${i.id}|${i.name}`)
|
||||
? this.comparisonInstitutions().map(
|
||||
(i: CompareItem) => `${i.id}|${i.name}`,
|
||||
)
|
||||
: null,
|
||||
countries:
|
||||
this.comparisonCountries().length > 0
|
||||
? this.comparisonCountries().map((c) => `${c.id}|${c.name}`)
|
||||
? this.comparisonCountries().map(
|
||||
(c: CompareItem) => `${c.id}|${c.name}`,
|
||||
)
|
||||
: null,
|
||||
regions:
|
||||
this.comparisonRegions().length > 0
|
||||
? this.comparisonRegions().map((r) => `${r.id}|${r.name}`)
|
||||
? this.comparisonRegions().map(
|
||||
(r: CompareItem) => `${r.id}|${r.name}`,
|
||||
)
|
||||
: null,
|
||||
start_year: this.startYear(),
|
||||
end_year: this.endYear(),
|
||||
@@ -364,7 +452,9 @@ export class UniTrendParentComponent implements OnInit {
|
||||
updated = current.includes(topic) ? current : [...current, topic];
|
||||
} else {
|
||||
updated =
|
||||
current.length > 1 ? current.filter((t) => t !== topic) : current;
|
||||
current.length > 1
|
||||
? current.filter((t: string) => t !== topic)
|
||||
: current;
|
||||
if (current.length === 1) {
|
||||
(event.target as HTMLInputElement).checked = true;
|
||||
}
|
||||
@@ -382,7 +472,10 @@ export class UniTrendParentComponent implements OnInit {
|
||||
// Add comparison institution
|
||||
addInstitution(id: string, name: string) {
|
||||
const current = this.comparisonInstitutions();
|
||||
if (!current.some((i) => i.id === id) && id !== this.primaryInstitution()) {
|
||||
if (
|
||||
!current.some((i: CompareItem) => i.id === id) &&
|
||||
id !== this.primaryInstitution()
|
||||
) {
|
||||
this.comparisonInstitutions.set([...current, { id, name }]);
|
||||
}
|
||||
this.searchQuery.set('');
|
||||
@@ -392,14 +485,16 @@ export class UniTrendParentComponent implements OnInit {
|
||||
// Remove comparison institution (data reuses instantly via computed)
|
||||
removeInstitution(id: string) {
|
||||
const current = this.comparisonInstitutions();
|
||||
this.comparisonInstitutions.set(current.filter((i) => i.id !== id));
|
||||
this.comparisonInstitutions.set(
|
||||
current.filter((i: CompareItem) => i.id !== id),
|
||||
);
|
||||
}
|
||||
|
||||
// Add country or region
|
||||
addLocation(loc: AutocompleteLocationItem) {
|
||||
if (loc.type === 'country') {
|
||||
const current = this.comparisonCountries();
|
||||
if (!current.some((c) => c.id === loc.id)) {
|
||||
if (!current.some((c: CompareItem) => c.id === loc.id)) {
|
||||
this.comparisonCountries.set([
|
||||
...current,
|
||||
{ id: loc.id, name: loc.display_name },
|
||||
@@ -407,7 +502,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
}
|
||||
} else if (loc.type === 'continent') {
|
||||
const current = this.comparisonRegions();
|
||||
if (!current.some((r) => r.id === loc.id)) {
|
||||
if (!current.some((r: CompareItem) => r.id === loc.id)) {
|
||||
this.comparisonRegions.set([
|
||||
...current,
|
||||
{ id: loc.id, name: loc.display_name },
|
||||
@@ -423,16 +518,20 @@ export class UniTrendParentComponent implements OnInit {
|
||||
removeLocation(id: string, type: 'country' | 'continent') {
|
||||
if (type === 'country') {
|
||||
const current = this.comparisonCountries();
|
||||
this.comparisonCountries.set(current.filter((c) => c.id !== id));
|
||||
this.comparisonCountries.set(
|
||||
current.filter((c: CompareItem) => c.id !== id),
|
||||
);
|
||||
} else if (type === 'continent') {
|
||||
const current = this.comparisonRegions();
|
||||
this.comparisonRegions.set(current.filter((r) => r.id !== id));
|
||||
this.comparisonRegions.set(
|
||||
current.filter((r: CompareItem) => r.id !== id),
|
||||
);
|
||||
}
|
||||
this.loadTrendSuggestions();
|
||||
}
|
||||
|
||||
// Scaling mode toggle (data reuses instantly)
|
||||
setChartMode(mode: 'normalized' | 'total') {
|
||||
setChartMode(mode: 'normalized' | 'total' | 'cumulative') {
|
||||
this.chartMode.set(mode);
|
||||
this.updateUrlParams();
|
||||
}
|
||||
@@ -450,7 +549,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
this.institutionsApiService
|
||||
.autocompleteInstitutions(query, undefined, 'education', 10)
|
||||
.subscribe({
|
||||
next: (res) => {
|
||||
next: (res: AutocompleteResponse) => {
|
||||
this.searchResults.set(res.results || []);
|
||||
},
|
||||
error: () => {
|
||||
@@ -471,7 +570,7 @@ export class UniTrendParentComponent implements OnInit {
|
||||
query,
|
||||
)
|
||||
.subscribe({
|
||||
next: (res) => {
|
||||
next: (res: AutocompleteLocationItem[]) => {
|
||||
this.locationSearchResults.set(res || []);
|
||||
},
|
||||
error: () => {
|
||||
|
||||
Reference in New Issue
Block a user