SPB Git

Repository Public

Provenance.tsx 8.2 KB 139 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/components/cout/Provenance.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// Vrai-Prix — méthode du coût : marqueurs de provenance (● observé ◐ calculé ○ indexé ◇ référence/hypothèse · AI),43// badges de couche (OBSERVÉ · INFÉRÉ PAR IA · CALCULÉ · PRIX SOURCÉ · HYPOTHÈSE) et origine des caractéristiques.44"use client";45import type { AttributeSource, Layer, PriceKind } from "@/lib/cost/types";4647export function kindGlyph(kind: PriceKind | null | undefined): string {48  switch (kind) {49    case "observed": case "official": return "●";50    case "derived": return "◐";51    case "indexed": return "○";52    case "reference": case "assumption": return "◇";53    default: return "·";54  }55}5657export function kindLabel(kind: PriceKind | null | undefined, fr: boolean): string {58  switch (kind) {59    case "observed": return fr ? "Observé directement" : "Directly observed";60    case "official": return fr ? "Publication officielle" : "Official publication";61    case "derived": return fr ? "Calculé depuis composants" : "Computed from components";62    case "indexed": return fr ? "Indexé" : "Indexed";63    case "reference": return fr ? "Référence interne (hypothèse)" : "Internal reference (assumption)";64    case "assumption": return fr ? "Hypothèse" : "Assumption";65    default: return fr ? "Donnée non disponible" : "Data not available";66  }67}6869export function kindTooltip(p: { kind: PriceKind | null | undefined; source?: string | null; observedAt?: string | null; note?: string | null }, fr: boolean): string {70  const d = p.observedAt ? fmtDate(p.observedAt, fr) : null;71  switch (p.kind) {72    case "observed": return fr ? `Observé directement chez ${p.source ?? "un fournisseur"}${d ? ` le ${d}` : ""}.` : `Directly observed at ${p.source ?? "a supplier"}${d ? ` on ${d}` : ""}.`;73    case "official": return fr ? `Taux publié par ${p.source ?? "une source officielle"}${d ? ` (en vigueur le ${d})` : ""}.` : `Rate published by ${p.source ?? "an official source"}${d ? ` (effective ${d})` : ""}.`;74    case "indexed": return p.note ?? (fr ? "Observation ancienne actualisée avec un indice Statistique Canada." : "Older observation updated with a Statistics Canada index.");75    case "derived": return fr ? "Calculé à partir de composants eux-mêmes sourcés." : "Computed from components that are themselves sourced.";76    case "reference": return fr ? "Prix de référence interne — hypothèse documentée, non observé." : "Internal reference price — documented assumption, not observed.";77    case "assumption": return p.note ?? (fr ? "Hypothèse documentée (productivité, pourcentage)." : "Documented assumption (productivity, percentage).");78    default: return fr ? "Donnée non disponible." : "Data not available.";79  }80}8182export function fmtDate(iso: string | null | undefined, fr: boolean): string {83  if (!iso) return "—";84  const d = new Date(iso.length <= 10 ? `${iso}T12:00:00` : iso);85  if (Number.isNaN(d.getTime())) return iso;86  return d.toLocaleDateString(fr ? "fr-CA" : "en-CA", { year: "numeric", month: "long", day: "numeric" });87}8889/** Icône de provenance avec infobulle native (title). */90export function KindIcon({ kind, fr, source, observedAt, note, className = "" }: { kind: PriceKind | null | undefined; fr: boolean; source?: string | null; observedAt?: string | null; note?: string | null; className?: string }) {91  const tone = kind === "observed" || kind === "official" ? "text-ink" : kind === "indexed" || kind === "derived" ? "text-accent" : "text-[var(--amber)]";92  return (93    <span className={`vp-mono inline-block text-[12px] leading-none ${tone} ${className}`} title={kindTooltip({ kind, source, observedAt, note }, fr)} aria-label={kindLabel(kind, fr)}>94      {kindGlyph(kind)}95    </span>96  );97}9899/** Légende des icônes de provenance. */100export function KindLegend({ fr }: { fr: boolean }) {101  const rows: [PriceKind, string][] = [["observed", fr ? "Observé directement" : "Observed directly"], ["derived", fr ? "Calculé depuis composants" : "Computed from components"], ["indexed", fr ? "Indexé (StatCan)" : "Indexed (StatCan)"], ["reference", fr ? "Référence interne · hypothèse" : "Internal reference · assumption"]];102  return (103    <div className="vp-mono flex flex-wrap gap-x-4 gap-y-1 text-[10px] uppercase tracking-[0.06em] text-ink-3">104      {rows.map(([k, l]) => (105        <span key={k} className="inline-flex items-center gap-1.5"><KindIcon kind={k} fr={fr} />{l}</span>106      ))}107      <span className="inline-flex items-center gap-1.5"><span className="vp-mono text-[9px] font-bold text-accent">AI</span>{fr ? "Classifié / inféré par IA" : "AI-classified / inferred"}</span>108    </div>109  );110}111112/** Badge de couche (§208) : OBSERVÉ · INFÉRÉ PAR IA · CALCULÉ · PRIX SOURCÉ · HYPOTHÈSE. */113export function LayerBadge({ layer, fr }: { layer: Layer; fr: boolean }) {114  const map: Record<Layer, { fr: string; en: string; cls: string }> = {115    observed: { fr: "Observé", en: "Observed", cls: "border-ink bg-ink text-paper" },116    ai_inferred: { fr: "Inféré par IA", en: "AI-inferred", cls: "border-accent text-accent" },117    computed: { fr: "Calculé", en: "Computed", cls: "border-[var(--line-strong)] text-ink" },118    sourced_price: { fr: "Prix sourcé", en: "Sourced price", cls: "border-[var(--line-strong)] text-ink-2" },119    assumption: { fr: "Hypothèse", en: "Assumption", cls: "border-[var(--amber)] text-[#8a5a12] bg-[var(--amber-soft)]" },120  };121  const m = map[layer];122  return <span className={`vp-mono inline-block border px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-[0.08em] ${m.cls}`}>{fr ? m.fr : m.en}</span>;123}124125/** Origine d'une caractéristique du bâtiment : MAMH / saisi / IA / dérivé / supposé / annonce. */126export function AttrBadge({ source, fr }: { source: AttributeSource | null | undefined; fr: boolean }) {127  const map: Record<string, { fr: string; en: string; cls: string }> = {128    MAMH: { fr: "MAMH", en: "MAMH", cls: "border-ink bg-ink text-paper" },129    cadastral: { fr: "Cadastre", en: "Cadastral", cls: "border-ink bg-ink text-paper" },130    listing: { fr: "Annonce", en: "Listing", cls: "border-[var(--line-strong)] text-ink" },131    user: { fr: "Saisi", en: "Entered", cls: "border-[var(--line-strong)] text-ink" },132    AI: { fr: "IA", en: "AI", cls: "border-accent text-accent" },133    derived: { fr: "Dérivé", en: "Derived", cls: "border-[var(--line)] text-ink-2" },134    assumed: { fr: "Supposé", en: "Assumed", cls: "border-[var(--amber)] text-[#8a5a12] bg-[var(--amber-soft)]" },135  };136  const m = map[source ?? "assumed"] ?? map.assumed;137  return <span className={`vp-mono inline-block border px-1.5 py-0.5 text-[9px] font-bold uppercase tracking-[0.08em] ${m.cls}`} title={fr ? "Origine de la caractéristique" : "Attribute origin"}>{fr ? m.fr : m.en}</span>;138}139
Files main
Menu

Theme