Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : UQO Éval — Le Grand Défi Immobilier8 * File : tests/helpers/realdata.ts9 * Module : tests10 * 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/**44 * Chargement de l'extrait réel (data/dev/listings.db, lecture seule) à travers45 * le moteur de normalisation — exactement le chemin suivi par la synchronisation.46 */47import path from "node:path";48import { DatabaseSync } from "node:sqlite";49import {50 DEFAULT_NORMALIZE_OPTIONS,51 dedupeProperties,52 isEligible,53 normalizeListing,54 type NormalizedProperty,55 type RawListing,56 type RawPricePoint,57} from "../../packages/engine/src/index.ts";5859export const LISTINGS_DB = path.resolve(import.meta.dirname, "../../data/dev/listings.db");6061/** Date figée : la normalisation ne dépend pas de l'horloge du poste. */62export const FIXED_NOW = new Date("2026-11-25T12:00:00Z");6364export interface RealData {65 rawCount: number;66 raws: RawListing[];67 normalized: NormalizedProperty[];68 deduped: NormalizedProperty[];69 eligible: NormalizedProperty[];70 rejections: Record<string, number>;71}7273let cache: RealData | null = null;7475export function loadRealData(): RealData {76 if (cache) return cache;77 const db = new DatabaseSync(LISTINGS_DB, { readOnly: true });78 try {79 db.exec("pragma query_only = on");80 const raws = // même alias que apps/api/src/source.ts : la colonne source `vraiprix` devient `assessment_json`81 db.prepare("select *, vraiprix as assessment_json from listings where active = 1 and price > 0 order by uid").all() as unknown as RawListing[];82 const logs = new Map<string, RawPricePoint[]>();83 for (const row of db.prepare("select uid, ts, price from price_log order by uid, ts").all() as unknown as (RawPricePoint & { uid: string })[]) {84 const list = logs.get(row.uid) ?? [];85 list.push({ ts: row.ts, price: row.price });86 logs.set(row.uid, list);87 }88 const rejections: Record<string, number> = {};89 const normalized: NormalizedProperty[] = [];90 for (const raw of raws) {91 const result = normalizeListing(raw, logs.get(raw.uid) ?? [], { ...DEFAULT_NORMALIZE_OPTIONS, now: FIXED_NOW });92 if (result.ok) normalized.push(result.property);93 else rejections[result.reason] = (rejections[result.reason] ?? 0) + 1;94 }95 const deduped = dedupeProperties(normalized);96 cache = { rawCount: raws.length, raws, normalized, deduped, eligible: deduped.filter((p) => isEligible(p)), rejections };97 return cache;98 } finally {99 db.close();100 }101}102