SPB Git

Repository Public

probe.ts 4.3 KB 71 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : UQO Éval — Le Grand Défi Immobilier8 * File             : scripts/probe.ts9 * Module           : scripts10 * Repository       : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website  : https://jeux.uqo-eval.app12 * Created          : 2026-11-2513 * Last Modified    : 2026-11-2514 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Sonde de développement : passe l'extrait réel dans les moteurs et affiche un bilan.44import { DatabaseSync } from "node:sqlite";45import { DEFAULT_NORMALIZE_OPTIONS, createRng, dedupeProperties, generateChoices, isEligible, normalizeListing, selectProperties, toPublicCard, toSnapshot, buildMarketContext, buildFeedback, poolLookup, type NormalizedProperty, type RawListing } from "../packages/engine/src/index.ts";46const db = new DatabaseSync(process.argv[2] ?? "data/dev/listings.db", { readOnly: true });47const rows = db.prepare("select * from listings").all() as unknown as RawListing[];48const logs = db.prepare("select ts, price from price_log where uid = ? order by ts");49const reasons: Record<string, number> = {};50const ok: NormalizedProperty[] = [];51for (const r of rows) {52  const res = normalizeListing(r, logs.all(r.uid) as never, { ...DEFAULT_NORMALIZE_OPTIONS, now: new Date() });53  if (res.ok) ok.push(res.property); else reasons[res.reason] = (reasons[res.reason] ?? 0) + 1;54}55const deduped = dedupeProperties(ok);56const eligible = deduped.filter((p) => isEligible(p));57console.log({ total: rows.length, normalized: ok.length, deduped: deduped.length, eligible: eligible.length, reasons });58const count = (f: (p: NormalizedProperty) => string) => Object.entries(eligible.reduce<Record<string, number>>((a, p) => ((a[f(p)] = (a[f(p)] ?? 0) + 1), a), {})).sort((a, b) => b[1] - a[1]);59console.log("catégories", count((p) => p.category)); console.log("régions", count((p) => p.regionName ?? "?"));60console.log("sans région", deduped.filter((p) => !p.regionCode).length, "desc", eligible.filter((p) => p.description).length, "loc", eligible.filter((p) => p.lat).length, "éval", eligible.filter((p) => p.assessment).length);61const bank = selectProperties(eligible, { size: 100 }, createRng("demo"));62const c2 = (f: (s: (typeof bank)[number]) => string) => Object.entries(bank.reduce<Record<string, number>>((a, p) => ((a[f(p)] = (a[f(p)] ?? 0) + 1), a), {})).sort((a, b) => b[1] - a[1]);63console.log("banque cat", c2((s) => s.property.category)); console.log("banque rég", c2((s) => s.property.regionName ?? "?")); console.log("phases", c2((s) => String(s.phase)));64for (const i of [0, 30, 60, 99]) {65  const s = bank[i]!; const g = generateChoices(s.property.price, s.difficulty, createRng(`q${i}`));66  console.log("\n#", i, "phase", s.phase, "atyp", s.atypicality.toFixed(2), g.prices, "rang", g.correctRank, g.gaps.map((x) => (x * 100).toFixed(1)));67  const snap = toSnapshot(s.property); const card = toPublicCard(snap, `q${i}`);68  console.log(JSON.stringify(card).slice(0, 900));69  console.log(JSON.stringify(buildFeedback(snap, buildMarketContext(s.property, poolLookup(eligible)), g.prices[0], `q${i}`, null)).slice(0, 1100));70}71
Files main
Menu

Theme