added filter params to founders resolver
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { inject } from '@angular/core';
|
||||
import {
|
||||
CareerBucket,
|
||||
FounderCandidatePage,
|
||||
FounderSortBy,
|
||||
MultiplicatorsService,
|
||||
@@ -9,12 +10,19 @@ import {
|
||||
|
||||
const FOUNDER_SORT_FIELDS = Object.values(FounderSortBy);
|
||||
const SORT_DIRECTIONS = Object.values(SortDirection);
|
||||
const DEFAULT_THRESHOLD = 90;
|
||||
const VALID_CAREER_BUCKETS = Object.values(CareerBucket);
|
||||
|
||||
/**
|
||||
* The founder-candidate list for the dashboard. Driven entirely by query
|
||||
* params (threshold, screened, page, size, sort) so the page state stays in
|
||||
* the URL and re-resolves when any of them change.
|
||||
* params so the page state stays in the URL and re-resolves when any of them
|
||||
* change.
|
||||
*
|
||||
* URL keys are the camelCase names used by the shared query-param controls and
|
||||
* are mapped to the snake_case arguments of `searchFounderCandidates` here.
|
||||
*
|
||||
* Everyone is shown by default (`in_population` unset). The "Mindestwert" is
|
||||
* opt-in: only when `threshold` is present is `min_external_percentile` sent.
|
||||
* "Auffällige Profile ausblenden" sets `screened=true`.
|
||||
*/
|
||||
export const founderCandidatesResolver: ResolveFn<FounderCandidatePage> = (
|
||||
route,
|
||||
@@ -24,11 +32,14 @@ export const founderCandidatesResolver: ResolveFn<FounderCandidatePage> = (
|
||||
|
||||
const page = Math.max(0, toInt(params.get('page'), 0));
|
||||
const size = clamp(toInt(params.get('size'), 25), 1, 100);
|
||||
const thresholdRaw = toNumber(params.get('threshold'));
|
||||
const threshold = clamp(thresholdRaw ?? DEFAULT_THRESHOLD, 0, 100);
|
||||
|
||||
const screenedRaw = params.get('screened');
|
||||
const screened = screenedRaw === null ? undefined : screenedRaw === 'true';
|
||||
const thresholdRaw = toNumber(params.get('threshold'));
|
||||
const minPercentile =
|
||||
thresholdRaw === null ? undefined : clamp(thresholdRaw, 0, 100);
|
||||
|
||||
// `screened=true` keeps only profiles that pass the data-quality screen.
|
||||
// `screened=false` would mean "only the rejects", so it is never sent.
|
||||
const screened = params.get('screened') === 'true' ? true : undefined;
|
||||
|
||||
const sortBy =
|
||||
asMember(params.get('sortBy'), FOUNDER_SORT_FIELDS) ??
|
||||
@@ -36,19 +47,26 @@ export const founderCandidatesResolver: ResolveFn<FounderCandidatePage> = (
|
||||
const sortOrder =
|
||||
asMember(params.get('sortOrder'), SORT_DIRECTIONS) ?? SortDirection.Desc;
|
||||
|
||||
const careerBuckets = splitCommaSeparated(params.getAll('careerBucket')).filter(
|
||||
(value): value is CareerBucket =>
|
||||
(VALID_CAREER_BUCKETS as readonly string[]).includes(value),
|
||||
);
|
||||
const researchAreas = splitCommaSeparated(params.getAll('researchArea'));
|
||||
const name = params.get('name')?.trim() || undefined;
|
||||
|
||||
return service.searchFounderCandidates(
|
||||
page,
|
||||
size,
|
||||
true, // in_population: only researchers the model can score
|
||||
threshold,
|
||||
undefined, // in_population: show everyone, scored and unscored
|
||||
minPercentile,
|
||||
undefined, // max_external_percentile
|
||||
undefined, // career_bucket
|
||||
careerBuckets.length ? careerBuckets : undefined,
|
||||
screened,
|
||||
undefined, // min_publications
|
||||
undefined, // has_patents
|
||||
undefined, // research_area
|
||||
researchAreas.length ? researchAreas : undefined,
|
||||
undefined, // tags
|
||||
undefined, // name
|
||||
name,
|
||||
undefined, // screen_min_publications
|
||||
undefined, // screen_max_career_age
|
||||
sortBy,
|
||||
@@ -65,6 +83,13 @@ function asMember<T extends string>(
|
||||
: null;
|
||||
}
|
||||
|
||||
function splitCommaSeparated(values: string[]): string[] {
|
||||
return values
|
||||
.flatMap((value) => value.split(','))
|
||||
.map((value) => value.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function clamp(value: number, min: number, max: number): number {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user