SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
2.5 KB · 41 lines typescript
Raw Blame History
1/**2 * Sales verification labels (§39, §205). A HEURISTIC over fields RareIndex already stores — it never3 * claims a transaction was independently confirmed. Labels:4 *   verified   — an auction-house / grading-company result, an auction with a confident match, or a5 *                high-trust source with a very confident match6 *   likely     — a valid, confidently matched completed listing from an ordinary source7 *   unverified — flagged by outlier detection, weak identification, or a low-trust source8 *   excluded   — bundles, zero prices and other records the pipeline excluded from valuation9 */10export type SaleVerification = 'verified' | 'likely' | 'unverified' | 'excluded';1112export interface SaleVerificationInput {13  status: string | null | undefined; // valid | flagged | excluded14  confidence: number | null | undefined; // 0–1 identification confidence15  flags?: string[] | null;16  sourceType?: string | null; // marketplace | auction_house | grading_company | dealer | …17  saleType?: string | null; // auction | fixed_price | best_offer | private | dealer | unknown18  trust?: number | null; // 0–1 source trust score19}2021export const VERIFIED_SOURCE_TYPES = new Set(['auction_house', 'grading_company']);2223export function classifySale(i: SaleVerificationInput): { label: SaleVerification; reason: string } {24  const conf = i.confidence ?? 0;25  const trust = i.trust ?? 0.5;26  if (i.status === 'excluded') return { label: 'excluded', reason: (i.flags ?? []).join(', ') || 'excluded by the pipeline' };27  if (i.status === 'flagged') return { label: 'unverified', reason: `flagged: ${(i.flags ?? []).join(', ') || 'outlier'}` };28  if (conf < 0.6) return { label: 'unverified', reason: 'weak identification' };29  if (trust < 0.5) return { label: 'unverified', reason: 'low-trust source' };30  if (i.sourceType && VERIFIED_SOURCE_TYPES.has(i.sourceType)) return { label: 'verified', reason: `${i.sourceType.replace('_', ' ')} result` };31  if (i.saleType === 'auction' && conf >= 0.8) return { label: 'verified', reason: 'auction result, confident match' };32  if (trust >= 0.8 && conf >= 0.85) return { label: 'verified', reason: 'high-trust source, confident match' };33  return { label: 'likely', reason: 'completed listing, confident match' };34}3536export function countVerification(labels: SaleVerification[]): Record<SaleVerification, number> {37  const out: Record<SaleVerification, number> = { verified: 0, likely: 0, unverified: 0, excluded: 0 };38  for (const l of labels) out[l]++;39  return out;40}41