SPB Git

Repository Public

MarcheView.tsx 27.9 KB 516 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/components/MarcheView.tsx9 * Module           : components10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-09-0812 * Last Modified    : 2026-09-0813 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142/**43 * /stats/marche — la mesure à l'épreuve du marché actif.44 * Compare l'estimation Vrai-Prix au prix demandé de ~49 000 annonces45 * réelles (copie des annonces, table vp_eval), et montre —46 * démarche — ce que l'écart mesure vraiment : l'erreur du47 * modèle PLUS la stratégie d'affichage du vendeur.48 */49"use client";50import { locNum } from "./MetricViz";51import { useLang } from "./LangContext";5253/* ---------------------------------- types --------------------------------- */54interface Slice {55  key: string;56  n: number;57  medianRatio: number | null;58  mdape: number | null;59  within10: number | null;60  within20: number | null;61  askAbove: number | null;62  inP10P90: number | null;63  medianAsk: number | null;64  medianEst: number | null;65  medianDiff: number | null;66  medianDiffPct: number | null;67  p25Diff: number | null;68  p75Diff: number | null;69}70interface MethodRow {71  key: string;72  main: boolean;73  n: number;74  coverage: number | null;75  medianRatio: number | null;76  mdape: number | null;77  within10: number | null;78  within20: number | null;79  medianDiff: number | null;80}81export interface MarcheStats {82  generated: string;83  source: {84    app: string;85    copiedAt: string;86    totalListings: number;87    geolocated: number;88    evaluated: number;89    valid: number;90    matchMedianM: number | null;91  };92  global: Omit<Slice, "key">;93  methods: MethodRow[];94  byConfidence: Slice[];95  byType: Slice[];96  byRegion: Slice[];97  byCity: Slice[];98  byBracket: Slice[];99  histogram: { below: number; above: number; bins: { lo: number; hi: number; n: number }[] };100  scatter: { p: number; e: number; l: string }[];101}102103/* -------------------------------- helpers -------------------------------- */104const money = (v: number | null, lang: string) =>105  v == null106    ? "—"107    : new Intl.NumberFormat(lang === "fr" ? "fr-CA" : "en-CA", {108        style: "currency",109        currency: "CAD",110        maximumFractionDigits: 0,111      }).format(v);112const pct = (v: number | null, lang: string, frac = 1) =>113  v == null ? "—" : `${(v * 100).toLocaleString(lang === "fr" ? "fr-CA" : "en-CA", { maximumFractionDigits: frac })} %`;114115function SectionTitle({ kicker, title }: { kicker: string; title: string }) {116  return (117    <div className="mb-4 mt-12">118      <span className="kicker">{kicker}</span>119      <h2 className="vp-display mt-2 text-[22px] font-bold uppercase tracking-[-0.02em]">{title}</h2>120    </div>121  );122}123124function Kpi({ label, value, hint }: { label: string; value: string; hint?: string }) {125  return (126    <div className="vp-card p-4">127      <div className="text-[11px] uppercase tracking-[0.08em] text-ink-3">{label}</div>128      <div className="vp-display mt-1 text-[26px] font-bold leading-none">{value}</div>129      {hint ? <div className="mt-2 text-[12px] leading-snug text-ink-2">{hint}</div> : null}130    </div>131  );132}133134/* ------------------------- histogramme du ratio ------------------------- */135function RatioHistogram({ s, fr }: { s: MarcheStats; fr: boolean }) {136  const bins = [137    { lo: 0, hi: 0.5, n: s.histogram.below },138    ...s.histogram.bins,139    { lo: 1.5, hi: Infinity, n: s.histogram.above },140  ];141  const max = Math.max(...bins.map((b) => b.n));142  const W = 720;143  const H = 210;144  const pad = { l: 8, r: 8, t: 14, b: 26 };145  const bw = (W - pad.l - pad.r) / bins.length;146  // repère x du ratio 1,0 : frontière entre les bacs 0,95-1,00 et 1,00-1,05147  const oneIdx = 1 + s.histogram.bins.findIndex((b) => Math.abs(b.lo - 1) < 1e-9);148  const oneX = pad.l + oneIdx * bw;149  return (150    <svg viewBox={`0 0 ${W} ${H}`} className="w-full" role="img"151      aria-label={fr ? "Distribution du ratio estimation / prix demandé" : "Distribution of estimate / asking price ratio"}>152      {bins.map((b, i) => {153        const h = max ? ((H - pad.t - pad.b) * b.n) / max : 0;154        const near1 = b.lo >= 0.9 - 1e-9 && b.hi <= 1.1 + 1e-9;155        return (156          <rect key={i} x={pad.l + i * bw + 1} y={H - pad.b - h} width={bw - 2} height={h}157            fill={near1 ? "var(--accent)" : "var(--ink-3)"} opacity={near1 ? 1 : 0.55} />158        );159      })}160      <line x1={oneX} y1={pad.t - 6} x2={oneX} y2={H - pad.b} stroke="var(--ink)" strokeDasharray="3 3" />161      <text x={oneX + 5} y={pad.t + 4} fontSize="11" fill="var(--ink)" fontFamily="var(--font-mono)">162        1,0 — {fr ? "estimation = prix demandé" : "estimate = asking price"}163      </text>164      {[0.5, 0.75, 1.0, 1.25, 1.5].map((v) => {165        const idx = 1 + (v - 0.5) / 0.05; // frontières des bacs intérieurs166        return (167          <text key={v} x={pad.l + idx * bw} y={H - 8} fontSize="10" textAnchor="middle" fill="var(--ink-3)"168            fontFamily="var(--font-mono)">169            {v.toLocaleString(fr ? "fr-CA" : "en-CA")}170          </text>171        );172      })}173    </svg>174  );175}176177/* --------------------- nuage prix demandé × estimation -------------------- */178function AskScatter({ s, fr }: { s: MarcheStats; fr: boolean }) {179  const CAP = 1_500_000;180  const pts = s.scatter.filter((d) => d.p <= CAP && d.e <= CAP);181  const W = 360;182  const H = 360;183  const pad = 34;184  const sc = (v: number) => pad + ((W - 2 * pad) * v) / CAP;185  return (186    <svg viewBox={`0 0 ${W} ${H}`} className="w-full max-w-[420px]" role="img"187      aria-label={fr ? "Nuage prix demandé vs estimation" : "Asking price vs estimate scatter"}>188      {[500000, 1000000, 1500000].map((v) => (189        <g key={v}>190          <line x1={sc(v)} y1={H - pad} x2={sc(v)} y2={pad} stroke="var(--line-soft)" />191          <line x1={pad} y1={H - sc(v)} x2={W - pad} y2={H - sc(v)} stroke="var(--line-soft)" />192          <text x={sc(v)} y={H - pad + 14} fontSize="9" textAnchor="middle" fill="var(--ink-3)" fontFamily="var(--font-mono)">193            {v / 1000000 >= 1 ? `${v / 1000000}M` : `${v / 1000}k`}194          </text>195          <text x={pad - 6} y={H - sc(v) + 3} fontSize="9" textAnchor="end" fill="var(--ink-3)" fontFamily="var(--font-mono)">196            {v / 1000000 >= 1 ? `${v / 1000000}M` : `${v / 1000}k`}197          </text>198        </g>199      ))}200      <line x1={sc(0)} y1={H - sc(0)} x2={sc(CAP)} y2={H - sc(CAP)} stroke="var(--ink)" strokeDasharray="4 3" />201      {pts.map((d, i) => (202        <circle key={i} cx={sc(d.p)} cy={H - sc(d.e)} r={1.6}203          fill={d.l === "A" ? "var(--accent)" : d.l === "B" ? "var(--accent-bright)" : "var(--ink-3)"} opacity={0.5} />204      ))}205      <text x={W / 2} y={H - 4} fontSize="10" textAnchor="middle" fill="var(--ink-2)">206        {fr ? "Prix demandé" : "Asking price"}207      </text>208      <text x={10} y={H / 2} fontSize="10" textAnchor="middle" fill="var(--ink-2)" transform={`rotate(-90 10 ${H / 2})`}>209        {fr ? "Estimation Vrai-Prix" : "Vrai-Prix estimate"}210      </text>211    </svg>212  );213}214215/* ------------------------------ tableau générique ------------------------------ */216function SliceTable({ rows, label, fr, keyHeader }: { rows: Slice[]; label?: string; fr: boolean; keyHeader: string }) {217  return (218    <div className="vp-card overflow-x-auto p-0">219      {label ? <div className="border-b border-[var(--line)] px-4 py-2 text-[12px] font-semibold uppercase tracking-[0.06em]">{label}</div> : null}220      <table className="w-full text-[13px]">221        <thead>222          <tr className="border-b border-[var(--line)] text-left text-[11px] uppercase tracking-[0.06em] text-ink-3">223            <th className="px-4 py-2">{keyHeader}</th>224            <th className="px-2 py-2 text-right">n</th>225            <th className="px-2 py-2 text-right">{fr ? "Ratio méd." : "Med. ratio"}</th>226            <th className="px-2 py-2 text-right">MdAPE</th>227            <th className="px-2 py-2 text-right">±20 %</th>228            <th className="px-2 py-2 text-right">{fr ? "Écart méd." : "Med. gap"}</th>229            <th className="px-4 py-2 text-right">{fr ? "Prix méd." : "Med. ask"}</th>230          </tr>231        </thead>232        <tbody>233          {rows.map((r) => (234            <tr key={r.key} className="border-b border-[var(--line-soft)] last:border-0">235              <td className="px-4 py-1.5 font-medium">{r.key}</td>236              <td className="px-2 py-1.5 text-right font-mono text-[12px]">{locNum(r.n, fr ? "fr" : "en", { maxFrac: 0 })}</td>237              <td className="px-2 py-1.5 text-right font-mono text-[12px]">238                {r.medianRatio == null ? "—" : r.medianRatio.toLocaleString(fr ? "fr-CA" : "en-CA", { minimumFractionDigits: 3, maximumFractionDigits: 3 })}239              </td>240              <td className="px-2 py-1.5 text-right font-mono text-[12px]">{pct(r.mdape, fr ? "fr" : "en")}</td>241              <td className="px-2 py-1.5 text-right font-mono text-[12px]">{pct(r.within20, fr ? "fr" : "en", 0)}</td>242              <td className="px-2 py-1.5 text-right font-mono text-[12px]">{money(r.medianDiff, fr ? "fr" : "en")}</td>243              <td className="px-4 py-1.5 text-right font-mono text-[12px]">{money(r.medianAsk, fr ? "fr" : "en")}</td>244            </tr>245          ))}246        </tbody>247      </table>248    </div>249  );250}251252/* ---------------------------------- vue ---------------------------------- */253export default function MarcheView({ s }: { s: MarcheStats }) {254  const { lang } = useLang();255  const fr = lang === "fr";256  const g = s.global;257  const copied = new Date(s.source.copiedAt + "T12:00:00").toLocaleDateString(fr ? "fr-CA" : "en-CA", {258    year: "numeric", month: "long", day: "numeric",259  });260261  return (262    <div className="mx-auto max-w-5xl px-4 pt-10 sm:pt-14">263      {/* ---- manchette ---- */}264      <section>265        <span className="kicker">{fr ? "Validation externe" : "External validation"}</span>266        <h1 className="vp-display mt-3 text-[clamp(26px,4.6vw,46px)] font-bold uppercase leading-[1.02] tracking-[-0.03em]">267          {fr ? "La mesure à l'épreuve du marché" : "The measure vs. the market"}268        </h1>269        <p className="mt-4 max-w-3xl text-[15px] leading-relaxed text-ink-2">270          {fr ? (271            <>272              Nous avons évalué avec le moteur Vrai-Prix{" "}273              <b>{locNum(s.source.evaluated, "fr", { maxFrac: 0 })} annonces réellement à vendre</b> au Québec274              (annonces publiques, copiées le {copied}) et comparé chaque estimation au{" "}275              <b>prix demandé</b> par le vendeur. C&apos;est un test grandeur nature — et une leçon d&apos;évaluation :276              l&apos;écart observé mélange l&apos;erreur du modèle <i>et</i> la stratégie d&apos;affichage.277            </>278          ) : (279            <>280              We ran the Vrai-Prix engine on{" "}281              <b>{locNum(s.source.evaluated, "en", { maxFrac: 0 })} properties actually for sale</b> in Québec282              (public listings, copied on {copied}) and compared each estimate to the seller&apos;s{" "}283              <b>asking price</b>. A full-scale test — and an appraisal lesson: the observed gap mixes model284              error <i>and</i> pricing strategy.285            </>286          )}287        </p>288        <div className="mt-8 grid grid-cols-1 gap-3 sm:grid-cols-3">289          <Kpi290            label={fr ? "Annonces évaluées" : "Listings appraised"}291            value={locNum(s.source.valid, fr ? "fr" : "en", { maxFrac: 0 })}292            hint={fr ? `sur ${locNum(s.source.totalListings, "fr", { maxFrac: 0 })} annonces actives publiées` : `of ${locNum(s.source.totalListings, "en", { maxFrac: 0 })} active published listings`}293          />294          <Kpi295            label={fr ? "Ratio médian estimation / prix demandé" : "Median estimate / asking ratio"}296            value={g.medianRatio == null ? "—" : g.medianRatio.toLocaleString(fr ? "fr-CA" : "en-CA", { minimumFractionDigits: 3 })}297            hint={298              fr299                ? `les vendeurs affichent en médiane ${pct(g.medianDiffPct, "fr")} au-dessus de notre estimation`300                : `sellers list a median ${pct(g.medianDiffPct, "en")} above our estimate`301            }302          />303          <Kpi304            label={fr ? "Prix demandés dans P10-P90" : "Asking prices within P10-P90"}305            value={pct(g.inP10P90, fr ? "fr" : "en")}306            hint={fr ? "part des prix demandés couverts par notre intervalle de confiance" : "share of asking prices covered by our confidence interval"}307          />308        </div>309      </section>310311      {/* ---- avertissement ---- */}312      <div className="vp-card mt-8 border-l-4 border-l-[var(--accent)] p-4 text-[13.5px] leading-relaxed text-ink-2">313        {fr ? (314          <>315            <b className="text-ink">Prix demandé ≠ valeur marchande.</b> Le moteur est calibré sur des{" "}316            <b>transactions réelles</b> (MdAPE 11,0 % contre les prix de vente). Face aux prix <i>demandés</i>, l&apos;écart317            médian monte à {pct(g.mdape, "fr")} : la différence contient la marge de négociation, la surenchère318            d&apos;affichage et les propriétés atypiques — pas seulement l&apos;erreur du modèle.{" "}319            {pct(g.askAbove, "fr", 0)} des annonces sont affichées <b>au-dessus</b> de notre estimation, un biais320            attendu et documenté en évaluation.321          </>322        ) : (323          <>324            <b className="text-ink">Asking price ≠ market value.</b> The engine is calibrated on{" "}325            <b>real transactions</b> (11.0% MdAPE against sale prices). Against <i>asking</i> prices the median gap326            rises to {pct(g.mdape, "en")}: the difference contains negotiation margin, listing premium and atypical327            properties — not just model error. {pct(g.askAbove, "en", 0)} of listings are priced <b>above</b> our328            estimate, an expected and well-documented bias.329          </>330        )}331      </div>332333      {/* ---- indicateurs ---- */}334      <SectionTitle kicker={fr ? "Indicateurs" : "Indicators"} title={fr ? "Performance globale" : "Overall performance"} />335      <div className="grid grid-cols-2 gap-3 sm:grid-cols-3">336        <Kpi label={fr ? "MdAPE vs prix demandé" : "MdAPE vs asking"} value={pct(g.mdape, fr ? "fr" : "en")} />337        <Kpi label={fr ? "Écart ≤ 10 %" : "Within 10%"} value={pct(g.within10, fr ? "fr" : "en")} />338        <Kpi label={fr ? "Écart ≤ 20 %" : "Within 20%"} value={pct(g.within20, fr ? "fr" : "en")} />339        <Kpi label={fr ? "Affichées au-dessus de l'estimation" : "Listed above estimate"} value={pct(g.askAbove, fr ? "fr" : "en")} />340        <Kpi label={fr ? "Prix demandé médian" : "Median asking price"} value={money(g.medianAsk, fr ? "fr" : "en")} />341        <Kpi label={fr ? "Estimation médiane" : "Median estimate"} value={money(g.medianEst, fr ? "fr" : "en")} />342      </div>343344      {/* ---- l'écart en dollars ---- */}345      <SectionTitle kicker={fr ? "L'écart" : "The gap"} title={fr ? "Prix demandé − valeur estimée" : "Asking price − estimated value"} />346      <div className="grid grid-cols-2 gap-3 sm:grid-cols-3">347        <Kpi348          label={fr ? "Écart médian" : "Median gap"}349          value={money(g.medianDiff, fr ? "fr" : "en")}350          hint={fr ? "en médiane, le vendeur demande ce montant de plus que notre estimation" : "median amount sellers ask above our estimate"}351        />352        <Kpi353          label={fr ? "Écart médian (%)" : "Median gap (%)"}354          value={pct(g.medianDiffPct, fr ? "fr" : "en")}355          hint={fr ? "(prix demandé − estimation) / estimation" : "(asking − estimate) / estimate"}356        />357        <Kpi358          label={fr ? "Écart interquartile" : "Interquartile gap"}359          value={`${money(g.p25Diff, fr ? "fr" : "en")} … ${money(g.p75Diff, fr ? "fr" : "en")}`}360          hint={fr ? "la moitié des annonces se situe dans cette fourchette d'écart (P25-P75)" : "half of listings fall in this gap range (P25-P75)"}361        />362      </div>363364      {/* ---- distribution ---- */}365      <SectionTitle kicker={fr ? "Distribution" : "Distribution"} title={fr ? "Ratio estimation / prix demandé" : "Estimate / asking price ratio"} />366      <div className="vp-card p-4">367        <RatioHistogram s={s} fr={fr} />368        <p className="mt-2 text-[12.5px] text-ink-2">369          {fr370            ? "En bleu : annonces où l'estimation est à ±10 % du prix demandé. La masse à gauche de 1,0 = vendeurs qui demandent plus que notre valeur estimée."371            : "Blue: listings where the estimate is within ±10% of asking. Mass left of 1.0 = sellers asking more than our estimated value."}372        </p>373      </div>374375      {/* ---- nuage + confiance ---- */}376      <div className="mt-8 grid grid-cols-1 gap-4 lg:grid-cols-2">377        <div className="vp-card p-4">378          <div className="mb-2 text-[12px] font-semibold uppercase tracking-[0.06em]">379            {fr ? "Prix demandé × estimation (échantillon)" : "Asking × estimate (sample)"}380          </div>381          <AskScatter s={s} fr={fr} />382          <p className="mt-1 text-[12px] text-ink-2">383            {fr384              ? "Diagonale = accord parfait. Bleu foncé : confiance A · turquoise : B · gris : C-D."385              : "Diagonal = perfect agreement. Dark blue: confidence A · turquoise: B · grey: C-D."}386          </p>387        </div>388        <div>389          <SliceTable390            rows={s.byConfidence.filter((r) => r.n > 0)}391            fr={fr}392            keyHeader={fr ? "Indice de confiance" : "Confidence index"}393            label={fr ? "L'indice de confiance tient sa promesse" : "The confidence index keeps its promise"}394          />395          <p className="mt-2 px-1 text-[12.5px] leading-relaxed text-ink-2">396            {fr397              ? "Point clé : l'erreur croît exactement comme l'indice l'annonce — de "398              : "Key point: error grows exactly as the index predicts — from "}399            {pct(s.byConfidence[0]?.mdape ?? null, fr ? "fr" : "en")} (A){fr ? " à " : " to "}400            {pct(s.byConfidence[2]?.mdape ?? null, fr ? "fr" : "en")} (C).{" "}401            {fr402              ? "En confiance A, le ratio médian est de 1,000 : aucune sur- ni sous-évaluation systématique."403              : "At confidence A the median ratio is 1.000: no systematic over- or under-valuation."}404          </p>405        </div>406      </div>407408      {/* ---- duel des méthodes ---- */}409      <SectionTitle kicker={fr ? "Trois méthodes" : "Three approaches"} title={fr ? "Le duel des méthodes" : "The method duel"} />410      <p className="mb-4 max-w-3xl text-[13.5px] leading-relaxed text-ink-2">411        {fr412          ? "Chaque annonce est aussi évaluée par les méthodes classiques de l'évaluation : la méthode du coût (terrain au marché + coût unitaire net du bâtiment, calibrés sur les ventes des 18 derniers mois grâce à la composition de chaque immeuble au rôle — aire d'étages, terrain, année, valeurs terrain/bâtiment) et le rôle indexé (étude de ratios de vente, IAAO). La mesure officielle Vrai-Prix reste l'hybride 65/35 — les autres servent de contre-expertise."413          : "Each listing is also appraised with the classic appraisal methods: the cost approach (market land + net unit building cost, calibrated on the last 18 months of sales using each building's composition in the roll — floor area, lot, year, land/building values) and the indexed roll (sales-ratio study, IAAO). The official Vrai-Prix measure remains the 65/35 hybrid — the others serve as cross-checks."}414      </p>415      <div className="vp-card overflow-x-auto p-0">416        <table className="w-full text-[13px]">417          <thead>418            <tr className="border-b border-[var(--line)] text-left text-[11px] uppercase tracking-[0.06em] text-ink-3">419              <th className="px-4 py-2">{fr ? "Méthode" : "Method"}</th>420              <th className="px-2 py-2 text-right">n</th>421              <th className="px-2 py-2 text-right">{fr ? "Ratio méd." : "Med. ratio"}</th>422              <th className="px-2 py-2 text-right">MdAPE</th>423              <th className="px-2 py-2 text-right">±10 %</th>424              <th className="px-2 py-2 text-right">±20 %</th>425              <th className="px-4 py-2 text-right">{fr ? "Écart méd." : "Med. gap"}</th>426            </tr>427          </thead>428          <tbody>429            {s.methods.map((m) => {430              const labels: Record<string, [string, string]> = {431                hybride: ["Hybride 65/35 — la mesure Vrai-Prix", "65/35 hybrid — the Vrai-Prix measure"],432                hedonique: ["Modèle hédonique seul (LightGBM)", "Hedonic model alone (LightGBM)"],433                comparables: ["Comparables ajustés seuls", "Adjusted comparables alone"],434                cout: ["Méthode du coût (calibrée marché)", "Cost approach (market-calibrated)"],435                role_indexe: ["Rôle indexé (ratios de vente IAAO)", "Indexed roll (IAAO sales ratios)"],436                ensemble: ["Ensemble — médiane hybride·coût·rôle", "Ensemble — median of hybrid·cost·roll"],437              };438              const lbl = labels[m.key]?.[fr ? 0 : 1] ?? m.key;439              return (440                <tr key={m.key}441                  className={`border-b border-[var(--line-soft)] last:border-0 ${m.main ? "bg-[var(--accent-soft)] font-semibold" : ""}`}>442                  <td className="px-4 py-1.5">{m.main ? "★ " : ""}{lbl}</td>443                  <td className="px-2 py-1.5 text-right font-mono text-[12px]">{locNum(m.n, fr ? "fr" : "en", { maxFrac: 0 })}</td>444                  <td className="px-2 py-1.5 text-right font-mono text-[12px]">445                    {m.medianRatio == null ? "—" : m.medianRatio.toLocaleString(fr ? "fr-CA" : "en-CA", { minimumFractionDigits: 3, maximumFractionDigits: 3 })}446                  </td>447                  <td className="px-2 py-1.5 text-right font-mono text-[12px]">{pct(m.mdape, fr ? "fr" : "en")}</td>448                  <td className="px-2 py-1.5 text-right font-mono text-[12px]">{pct(m.within10, fr ? "fr" : "en", 0)}</td>449                  <td className="px-2 py-1.5 text-right font-mono text-[12px]">{pct(m.within20, fr ? "fr" : "en", 0)}</td>450                  <td className="px-4 py-1.5 text-right font-mono text-[12px]">{money(m.medianDiff, fr ? "fr" : "en")}</td>451                </tr>452              );453            })}454          </tbody>455        </table>456      </div>457      <p className="mt-2 max-w-3xl text-[12.5px] leading-relaxed text-ink-2">458        {fr459          ? "Leçon du duel : aucune méthode ne domine partout — le coût peine sur les condos (quote-part de terrain au rôle) et les propriétés atypiques, les comparables seuls dérapent en marché mince, et c'est la combinaison qui stabilise la mesure."460          : "Duel takeaway: no method dominates everywhere — cost struggles with condos (land share in the roll) and atypical properties, comparables alone drift in thin markets, and the combination is what stabilizes the measure."}461      </p>462463      {/* ---- segments ---- */}464      <SectionTitle kicker={fr ? "Segments" : "Segments"} title={fr ? "Où la mesure excelle — et où elle peine" : "Where the measure excels — and struggles"} />465      <div className="grid grid-cols-1 gap-4 lg:grid-cols-2">466        <SliceTable rows={s.byType} fr={fr} keyHeader={fr ? "Type d'annonce" : "Listing type"} label={fr ? "Par type de propriété" : "By property type"} />467        <SliceTable rows={s.byBracket} fr={fr} keyHeader={fr ? "Tranche de prix" : "Price bracket"} label={fr ? "Par tranche de prix demandé" : "By asking price bracket"} />468        <SliceTable rows={s.byRegion} fr={fr} keyHeader={fr ? "Région" : "Region"} label={fr ? "Par région" : "By region"} />469        <SliceTable rows={s.byCity} fr={fr} keyHeader={fr ? "Ville" : "City"} label={fr ? "Principales villes" : "Top cities"} />470      </div>471472      {/* ---- méthode ---- */}473      <SectionTitle kicker={fr ? "Méthode" : "Method"} title={fr ? "D'où viennent ces chiffres" : "Where these numbers come from"} />474      <div className="vp-card p-4 text-[13.5px] leading-relaxed text-ink-2">475        {fr ? (476          <>477            Copie intégrale des <b>annonces publiques</b> ({copied}) :{" "}478            {locNum(s.source.totalListings, "fr", { maxFrac: 0 })} annonces actives publiées, dont{" "}479            {locNum(s.source.geolocated, "fr", { maxFrac: 0 })} géolocalisées. Chaque annonce est{" "}480            <b>jumelée par coordonnées GPS</b> à l&apos;unité du rôle d&apos;évaluation MAMH la plus proche481            (rayon 75 m puis 250 m, départage par type, superficie habitable et année — distance médiane482            de jumelage : {locNum(s.source.matchMedianM, "fr", { maxFrac: 1, unit: "m" })}) ;{" "}483            {locNum(s.source.evaluated, "fr", { maxFrac: 0 })} ont ainsi été évaluées, et l&apos;analyse retient484            les {locNum(s.source.valid, "fr", { maxFrac: 0 })} à prix demandé ≥ 50 000 $ — le même seuil que les485            ventes retenues par le moteur. Le merge complet annonce ↔ estimations (hybride, coût, rôle indexé)486            est conservé dans la table <code className="font-mono text-[12px]">vp_eval</code> et chaque annonce487            passe par <i>exactement le même calcul</i> que le formulaire public : modèle hédonique + comparables488            ajustés, pondération 65 / 35. Ratio médian et MdAPE sont des médianes — robustes aux annonces489            extrêmes.490          </>491        ) : (492          <>493            Full copy of the <b>public listings</b> ({copied}):{" "}494            {locNum(s.source.totalListings, "en", { maxFrac: 0 })} active published listings,{" "}495            {locNum(s.source.geolocated, "en", { maxFrac: 0 })} geolocated. Each listing is{" "}496            <b>matched by GPS coordinates</b> to the nearest MAMH assessment-roll unit (75 m then 250 m radius,497            tie-broken by type, living area and year — median match distance:{" "}498            {locNum(s.source.matchMedianM, "en", { maxFrac: 1, unit: "m" })});{" "}499            {locNum(s.source.evaluated, "en", { maxFrac: 0 })} were appraised, and the analysis keeps the{" "}500            {locNum(s.source.valid, "en", { maxFrac: 0 })} listings asking ≥ $50,000 — the same floor as the501            sales the engine uses. The full listing ↔ estimates merge (hybrid, cost, indexed roll) lives in the{" "}502            <code className="font-mono text-[12px]">vp_eval</code> table, and every listing goes through{" "}503            <i>exactly the same computation</i> as the public form: hedonic model + adjusted comparables, 65/35504            weighting. Median ratio and MdAPE are medians — robust to extreme listings.505          </>506        )}507      </div>508      <p className="mb-4 mt-6 text-[11.5px] text-ink-3">509        {fr510          ? `Généré le ${new Date(s.generated).toLocaleDateString("fr-CA")} · annonces publiques + rôles MAMH · à titre indicatif.`511          : `Generated ${new Date(s.generated).toLocaleDateString("en-CA")} · public listings + MAMH rolls · for teaching purposes.`}512      </p>513    </div>514  );515}516
Files main
Menu

Theme