Vrai-Prix — l'évaluation du vrai prix des propriétés résidentielles au Québec.
TypeScript 90.2%
JavaScript 3.5%
Python 3.4%
CSS 1.9%
HTML 0.6%
1// Auteur : Simon-Pierre Boucher — contact@spboucher.ai2/**3 * Statistiques « la mesure à l'épreuve du marché » (/stats, /stats/marche).4 *5 * Deux sources, dans l'ordre :6 * 1. data/marche-stats.json — produit chaque nuit par scripts/immoka-sync.sh7 * (ré-évaluation de toutes les annonces Immo-Ka vivantes, MARCHE_STATS_OUT) ;8 * lu à chaud, jamais versionné, mis en cache 10 min en mémoire ;9 * 2. src/data/marche-stats.json — instantané versionné, embarqué au build,10 * utilisé si le fichier nocturne est absent ou illisible (laptop, premier11 * déploiement).12 * Serveur seulement (fs).13 */14import fs from "fs";15import path from "path";16import type { MarcheStats } from "@/components/MarcheView";17import bundled from "@/data/marche-stats.json";1819// chemin statique (data/…) : Turbopack ne trace alors pas tout le projet dans la sortie serveur20const LIVE_PATH = path.join(process.cwd(), "data", "marche-stats.json");21const TTL_MS = 10 * 60 * 1000;2223let cache: { at: number; mtimeMs: number; stats: MarcheStats } | null = null;2425export function loadMarcheStats(): MarcheStats {26 const now = Date.now();27 try {28 const st = fs.statSync(LIVE_PATH);29 if (cache && cache.mtimeMs === st.mtimeMs && now - cache.at < TTL_MS) return cache.stats;30 const parsed = JSON.parse(fs.readFileSync(LIVE_PATH, "utf8")) as MarcheStats;31 if (parsed?.global?.n && parsed.source) {32 cache = { at: now, mtimeMs: st.mtimeMs, stats: parsed };33 return parsed;34 }35 } catch {36 /* fichier nocturne absent ou illisible → instantané versionné */37 }38 return bundled as unknown as MarcheStats;39}40