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/factories.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/** Fabriques de données synthétiques pour les tests unitaires et statistiques. */44import {45 CATEGORIES,46 DEFAULT_NORMALIZE_OPTIONS,47 type Category,48 type NormalizeOptions,49 type NormalizedProperty,50 type RawListing,51} from "../../packages/engine/src/index.ts";52import { FIXED_NOW } from "./realdata.ts";5354export const OPTIONS: NormalizeOptions = { ...DEFAULT_NORMALIZE_OPTIONS, now: FIXED_NOW };5556export const TS_2026_10_01 = Date.UTC(2026, 9, 1, 15) / 1000;57export const TS_2026_11_01 = Date.UTC(2026, 10, 1, 15) / 1000;58export const TS_2026_11_15 = Date.UTC(2026, 10, 15, 15) / 1000;5960const IMAGES = Array.from({ length: 6 }, (_, i) => `https://photos.exemple.test/annonce/${i + 1}.jpg`);6162/** Inscription brute valide (maison unifamiliale à Gatineau) ; chaque test ne modifie que ce qu'il vérifie. */63export function makeRaw(overrides: Partial<RawListing> = {}): RawListing {64 return {65 uid: "test:1",66 source: "centris",67 title: "Maison à vendre",68 address: "123 rue des Érables",69 sector: null,70 city: "Gatineau",71 region: "Outaouais",72 property_type: "Maison",73 price: 450_000,74 bedrooms: 3,75 bathrooms: 2,76 powder_rooms: 1,77 area_sqft: 1_500,78 lot_sqft: 6_000,79 year_built: 1995,80 mls: "12345678",81 description: null,82 details: "{}",83 images: JSON.stringify(IMAGES),84 lat: 45.4765,85 lng: -75.7013,86 first_seen: TS_2026_10_01,87 last_seen: TS_2026_11_15,88 updated_at: TS_2026_11_01,89 assessment_json: null,90 quality_score: 90,91 dup_hidden: 0,92 dup_of: null,93 active: 1,94 published: 1,95 ...overrides,96 };97}9899/** Propriété normalisée synthétique, entièrement déterminée par ses paramètres. */100export function makeProperty(overrides: Partial<NormalizedProperty> = {}): NormalizedProperty {101 const uid = overrides.sourceUid ?? "p:1";102 return {103 sourceUid: uid,104 source: "centris",105 category: "unifamiliale",106 subtype: null,107 municipality: "Gatineau",108 municipalityCode: "81017",109 sector: null,110 regionCode: "07",111 regionName: "Outaouais",112 mrc: null,113 price: 450_000,114 priceObservedAt: "2026-11-01",115 firstSeenAt: "2026-10-01",116 priceHistory: [],117 bedrooms: 3,118 bathrooms: 2,119 powderRooms: null,120 livingAreaSqft: 1_500,121 lotAreaSqft: 6_000,122 yearBuilt: 1995,123 rooms: 8,124 floors: 2,125 unitFloor: null,126 garage: "Attaché",127 pool: null,128 basement: "Aménagé",129 heating: "Plinthes électriques",130 heatingEnergy: "Électricité",131 siding: "Brique",132 roofing: "Bardeaux d'asphalte",133 foundation: "Béton coulé",134 windows: "PVC",135 parking: "Allée (2)",136 view: null,137 waterfront: null,138 siteFeatures: null,139 fireplace: null,140 condoFeesYearly: null,141 annualRevenue: null,142 municipalTaxes: 3_456,143 assessment: { total: 398_700, land: 120_300, building: 278_400, year: 2024 },144 description: null,145 imageUrls: IMAGES,146 lat: 45.4765,147 lng: -75.7013,148 qualityScore: 90,149 dedupeKeys: [`uid-key:${uid}`],150 ...overrides,151 };152}153154const REGION_CODES = ["03", "05", "06", "07", "13", "15", "16"];155const REGION_NAMES: Record<string, string> = { "03": "Capitale-Nationale", "05": "Estrie", "06": "Montréal", "07": "Outaouais", "13": "Laval", "15": "Laurentides", "16": "Montérégie" };156157/**158 * Bassin synthétique de `n` propriétés : catégories, régions, municipalités et159 * prix variés de façon déterministe (aucun hasard : tout dépend de l'indice).160 */161export function makePool(n: number, tweak: (p: NormalizedProperty, i: number) => Partial<NormalizedProperty> | void = () => {}): NormalizedProperty[] {162 const out: NormalizedProperty[] = [];163 for (let i = 0; i < n; i++) {164 const category: Category = CATEGORIES[i % 5 === 4 ? 3 : i % 4 === 3 ? 4 : i % 3 === 2 ? 1 : 0]!;165 const regionCode = REGION_CODES[i % REGION_CODES.length]!;166 const base = makeProperty({167 sourceUid: `syn:${String(i).padStart(5, "0")}`,168 category,169 regionCode,170 regionName: REGION_NAMES[regionCode]!,171 municipality: `Ville-${regionCode}-${i % 40}`,172 municipalityCode: null,173 price: 150_000 + ((i * 7919) % 900) * 1_000,174 yearBuilt: 1950 + (i % 70),175 dedupeKeys: [`mls:${10_000_000 + i}`],176 });177 out.push({ ...base, ...(tweak(base, i) ?? {}) });178 }179 return out;180}181