houses: Leefbaarometer liveability per listing (PDOK geocode + LBM 2024 grid/buurt), min-score filter and sort; store every regional listing (no price caps at scrape time)
All checks were successful
Deploy production / deploy (push) Successful in 2m33s

This commit is contained in:
2026-10-24 15:40:20 +00:00
parent e95b7da1e3
commit 113eb54cd9
13 changed files with 19150 additions and 13 deletions

View File

@@ -12,6 +12,7 @@
import { readFileSync } from 'node:fs';
import { parseArgs } from 'node:util';
import postgres from 'postgres';
import { lbmClassLabel, scoreListings } from '../src/lib/house-tracker/liveability';
import {
inferOffer,
inferPropertyType,
@@ -254,6 +255,32 @@ async function add() {
return { ...inserted, action: 'added' };
});
print([row]);
if (row?.id) await liveability(row.id as number);
}
}
/** Leefbaarometer score for a listing that was just added or changed (skips if unchanged). */
async function liveability(id: number) {
try {
const r = await scoreListings(sql, { ids: [id] });
if (!r.checked) return;
const [l] = await sql<
{
lbm_class: number | null;
lbm_onv_class: number | null;
lbm_buurt_name: string | null;
lbm_precision: string | null;
}[]
>`select lbm_class, lbm_onv_class, lbm_buurt_name, lbm_precision from house.listings where id = ${id}`;
console.log(
l?.lbm_class != null
? ` leefbaarometer ${l.lbm_class}/9 ${lbmClassLabel(l.lbm_class)} · overlast ${l.lbm_onv_class}/9 · ${l.lbm_buurt_name}${l.lbm_precision === 'address' ? '' : ` (approx., ${l.lbm_precision})`}`
: r.failed
? ' leefbaarometer: lookup failed, the nightly run retries'
: ' leefbaarometer: no location found for this address'
);
} catch (error) {
console.warn(` leefbaarometer: ${(error as Error).message}`);
}
}
@@ -298,7 +325,10 @@ async function update() {
await recordPrice(tx, id, before.price_eur, given.price_eur);
return rows;
});
if (row) print([row]);
if (row) {
print([row]);
await liveability(id);
}
}
async function list() {