cars: import handles models without years, keeps roman numerals upper-case; don't cache an empty overview
Some checks failed
Deploy production / deploy (push) Has been cancelled
Some checks failed
Deploy production / deploy (push) Has been cancelled
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
// Re-runnable: brands/models are upserted by slug (Dex numbers stay stable, new models get
|
||||
// the next number), models that vanished are deleted, variants are replaced.
|
||||
import postgres from 'postgres';
|
||||
|
||||
const known = (xs: (number | null)[]) => xs.filter((x): x is number => x != null);
|
||||
const minOrNull = (xs: (number | null)[]) => (known(xs).length ? Math.min(...known(xs)) : null);
|
||||
const maxOrNull = (xs: (number | null)[]) => (known(xs).length ? Math.max(...known(xs)) : null);
|
||||
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
|
||||
@@ -333,7 +337,7 @@ const TRIM_WORDS = new Set(
|
||||
INJECTION ETECH PLUGIN HYBRID4 XDRIVE SDRIVE EDRIVE QUATTRO MOTION MATIC AWD WD X`.split(/\s+/)
|
||||
);
|
||||
const KEEP_UPPER = new Set(
|
||||
'GTI GTD GTE GTX GT AMG SUV MPV RS ST EV BEV PHEV TDI TSI SRT SS SVR SVT XL XLT CC SW TT GTS GTV RV CR-V HR-V EQA EQB EQC EQE EQS EQV EQT UX NX RX LX GX IS ES LS LC RC'.split(
|
||||
'GTI GTD GTE GTX GT AMG SUV MPV RS ST EV BEV PHEV TDI TSI SRT SS SVR SVT XL XLT CC SW TT GTS GTV RV CR-V HR-V EQA EQB EQC EQE EQS EQV EQT UX NX RX LX GX IS ES LS LC RC II III IV VI VII VIII IX XI XII'.split(
|
||||
' '
|
||||
)
|
||||
);
|
||||
@@ -828,8 +832,8 @@ function build(src: Awaited<ReturnType<typeof loadSources>>, fuel: RdwFuel[]) {
|
||||
.join(' ')
|
||||
.toLowerCase()
|
||||
.slice(0, 4000),
|
||||
firstYear: Math.min(...years),
|
||||
lastYear: Math.max(...years),
|
||||
firstYear: years.length ? Math.min(...years) : null,
|
||||
lastYear: years.length ? Math.max(...years) : null,
|
||||
bodies,
|
||||
sizeClasses: [...m.sizeClasses].sort(),
|
||||
fuels,
|
||||
@@ -881,8 +885,8 @@ function build(src: Awaited<ReturnType<typeof loadSources>>, fuel: RdwFuel[]) {
|
||||
name,
|
||||
country: COUNTRIES[b.key] ?? null,
|
||||
nlCount: b.nlCount,
|
||||
firstYear: Math.min(...models.map((m) => m.firstYear)),
|
||||
lastYear: Math.max(...models.map((m) => m.lastYear)),
|
||||
firstYear: minOrNull(models.map((m) => m.firstYear)),
|
||||
lastYear: maxOrNull(models.map((m) => m.lastYear)),
|
||||
sources: [...b.sources].sort(),
|
||||
models
|
||||
});
|
||||
|
||||
@@ -132,7 +132,7 @@ export async function carOverview(): Promise<Overview> {
|
||||
nlCars: Number(counts.nlCars)
|
||||
}
|
||||
};
|
||||
overviewCache = { at: Date.now(), value };
|
||||
if (value.stats.models) overviewCache = { at: Date.now(), value };
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user