fix: separate historical source methodologies
This commit is contained in:
@@ -66,12 +66,42 @@ function datasetTheme(dataset: DatasetCreateResponse): string | null {
|
||||
return null
|
||||
}
|
||||
|
||||
function timelineSummary(
|
||||
temporalCount: number,
|
||||
temporalSeriesCount: number,
|
||||
otherMethodCount: number,
|
||||
firstYear: number | null,
|
||||
lastYear: number | null,
|
||||
): string {
|
||||
if (temporalCount < 2 || !firstYear || !lastYear) {
|
||||
return 'Alleen de huidige toestand is vergelijkbaar beschikbaar.'
|
||||
}
|
||||
const seriesNote = temporalSeriesCount > 1
|
||||
? ` in ${temporalSeriesCount} afzonderlijke reeksen`
|
||||
: ''
|
||||
const methodNote = otherMethodCount > 0
|
||||
? `plus ${otherMethodCount} andere bronmethode${otherMethodCount === 1 ? '' : 'n'}`
|
||||
: null
|
||||
return [
|
||||
`${temporalCount} vergelijkbare meetmomenten${seriesNote}`,
|
||||
`${firstYear}-${lastYear}`,
|
||||
methodNote,
|
||||
].filter(Boolean).join(' · ')
|
||||
}
|
||||
|
||||
export function SourceCatalogPanel({ datasets }: SourceCatalogPanelProps): JSX.Element {
|
||||
const ready = datasets.filter((dataset) => dataset.status === 'ready')
|
||||
const themes = Object.keys(THEME_LABELS).map((theme) => {
|
||||
const matches = ready.filter((dataset) => datasetTheme(dataset) === theme)
|
||||
const temporal = matches.filter((dataset) => dataset.temporal_series_key && dataset.observed_at)
|
||||
const years = temporal.map((dataset) => new Date(dataset.observed_at as string).getUTCFullYear())
|
||||
const seriesGroups = new Map<string, DatasetCreateResponse[]>()
|
||||
temporal.forEach((dataset) => {
|
||||
const seriesKey = dataset.temporal_series_key as string
|
||||
seriesGroups.set(seriesKey, [...(seriesGroups.get(seriesKey) ?? []), dataset])
|
||||
})
|
||||
const comparableSeries = [...seriesGroups.values()].filter((series) => series.length >= 2)
|
||||
const comparableObservations = comparableSeries.flat()
|
||||
const years = comparableObservations.map((dataset) => new Date(dataset.observed_at as string).getUTCFullYear())
|
||||
const latest = [...matches].sort(
|
||||
(left, right) => new Date(right.observed_at ?? right.imported_at ?? 0).getTime() - new Date(left.observed_at ?? left.imported_at ?? 0).getTime(),
|
||||
)[0]
|
||||
@@ -79,7 +109,9 @@ export function SourceCatalogPanel({ datasets }: SourceCatalogPanelProps): JSX.E
|
||||
theme,
|
||||
label: THEME_LABELS[theme],
|
||||
datasetCount: matches.length,
|
||||
temporalCount: temporal.length,
|
||||
temporalCount: comparableObservations.length,
|
||||
temporalSeriesCount: comparableSeries.length,
|
||||
otherMethodCount: matches.length - comparableObservations.length,
|
||||
firstYear: years.length ? Math.min(...years) : null,
|
||||
lastYear: years.length ? Math.max(...years) : null,
|
||||
source: latest?.source_name ?? latest?.source ?? null,
|
||||
@@ -105,11 +137,13 @@ export function SourceCatalogPanel({ datasets }: SourceCatalogPanelProps): JSX.E
|
||||
<span>{theme.source ? theme.source.replaceAll('_', ' ') : 'Nog niet ingeladen'}</span>
|
||||
</div>
|
||||
<b>{theme.datasetCount > 0 ? 'Beschikbaar' : 'Ontbreekt'}</b>
|
||||
<p>
|
||||
{theme.temporalCount >= 2 && theme.firstYear && theme.lastYear
|
||||
? `${theme.temporalCount} officiële meetmomenten · ${theme.firstYear}-${theme.lastYear}`
|
||||
: 'Alleen de huidige toestand is vergelijkbaar beschikbaar.'}
|
||||
</p>
|
||||
<p>{timelineSummary(
|
||||
theme.temporalCount,
|
||||
theme.temporalSeriesCount,
|
||||
theme.otherMethodCount,
|
||||
theme.firstYear,
|
||||
theme.lastYear,
|
||||
)}</p>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user