code wiki / _hdl_build / nx_condition_report.nx

nx_condition_report.nx source

↩ module page · 113 lines · 6731 B

1// nx_condition_report.nx -- MANHEIM-BUILD-L3 (assurance/trust): the CONDITION REPORT GRADER (Manheim 2// Condition Report / AutoGrade-class), the inspection grade every wholesale lot carries. Sovereign 3// (nx_cc->nxasm, no gcc), integer-exact + deterministic. 4// 5// WHY GRADE INTEGRITY IS THE WHOLE GAME: the grade drives the price AND it is the #1 source of ARBITRATION 6// disputes. A naive grader that AVERAGES category scores produces DANGEROUSLY WRONG grades for 7// structurally-compromised cars -- a frame-damaged car with pristine cosmetics averages out to "excellent", 8// which a buyer will arbitrate (and which then poisons any valuation built on it). The fix: a CRITICAL 9// DEFECT must CAP the grade, never be washed out by good panels. 10// 11// ENGINE: 12// cr_naive = weighted category average / 2 (ext 30 / int 20 / mech 30 / tires 10 / glass 10, sum 100) 13// cr_grade = cr_naive, but CAPPED at the structural ceiling (2.0 = 20) if ANY critical flag is set 14// (frame damage / flood / airbag-deployed / salvage brand). grade scale 0..50 (= 0.0..5.0). 15// 16// ===== S-CLASS EXCEED, MEASURED (no-wave law) ===== 17// main() is an EXCEED BENCH vs the naive averaging grader on grade INTEGRITY (deterministic, non-circular): 18// A (frame damage + pristine cosmetics): naive overgrades to 47 ("4.7 excellent" -- WRONG/dangerous); 19// ours CAPS at 20 ("2.0 structural") -> a 27-point integrity gap the naive grader gets wrong. 20// NEG-CONTROL B (same pristine cosmetics, NO critical flag): ours == naive == 47 -> ours does NOT 21// always-cap, it tracks real condition (proves the cap is defect-triggered, not a blanket clamp). 22// C (monotonicity): a clearly-worse car grades strictly lower. + determinism. 23// 24// HONEST SCOPE (no-overclaim): the measured exceed is grade INTEGRITY vs the naive-average baseline -- NOT a 25// claim to reproduce a specific human inspector's grade or Manheim's exact proprietary AutoGrade algorithm 26// (those need real inspection data = operator-host). Evidence -> knowledge/status/condition_report.log. 27// license_tier: ORIGINAL 28import "nx_syscalls.nx" 29 30const CR_LOG: *u8 = "knowledge/status/condition_report.log" 31const CR_W_EXT: i64 = 30 32const CR_W_INT: i64 = 20 33const CR_W_MECH: i64 = 30 34const CR_W_TIRES: i64 = 10 35const CR_W_GLASS: i64 = 10 36const CR_STRUCTURAL_CAP: i64 = 20 // 2.0 grade ceiling for any structural/branded defect 37const CR_SCALE: i64 = 50 // max grade (= 5.0) 38 39func cr_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 40func cr_wn(fd: i64, v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m; sys_write(fd,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(fd, bb, k); return 0 } 41 42// weighted category average (0..100) scaled to the 0..CR_SCALE grade. 43func cr_naive(ext: i64, intr: i64, mech: i64, tires: i64, glass: i64) -> i64 { 44 let wavg: i64 = (ext * CR_W_EXT + intr * CR_W_INT + mech * CR_W_MECH + tires * CR_W_TIRES + glass * CR_W_GLASS) / 100 45 return wavg * CR_SCALE / 100 46} 47// integrity grade: the naive grade, CAPPED at the structural ceiling if any critical defect flag is set. 48func cr_grade(ext: i64, intr: i64, mech: i64, tires: i64, glass: i64, frame: i64, flood: i64, airbag: i64, salvage: i64) -> i64 { 49 let base: i64 = cr_naive(ext, intr, mech, tires, glass) 50 var critical: i64 = 0 51 if frame == 1 { critical = 1 } 52 if flood == 1 { critical = 1 } 53 if airbag == 1 { critical = 1 } 54 if salvage == 1 { critical = 1 } 55 if critical == 1 { if base > CR_STRUCTURAL_CAP { return CR_STRUCTURAL_CAP } } 56 return base 57} 58 59func main() -> i64 { 60 // A: pristine cosmetics (all 95) BUT frame damage -> must CAP 61 let naive_A: i64 = cr_naive(95, 95, 95, 95, 95) 62 let ours_A: i64 = cr_grade(95, 95, 95, 95, 95, 1, 0, 0, 0) 63 let overgrade: i64 = naive_A - ours_A 64 65 // B (control): same pristine cosmetics, NO critical flag -> no cap, ours tracks real condition 66 let naive_B: i64 = cr_naive(95, 95, 95, 95, 95) 67 let ours_B: i64 = cr_grade(95, 95, 95, 95, 95, 0, 0, 0, 0) 68 69 // C (monotonicity): a clearly-worse car (all 60), no flags -> grades strictly lower than B 70 let ours_C: i64 = cr_grade(60, 60, 60, 60, 60, 0, 0, 0, 0) 71 72 // determinism 73 let d1: i64 = cr_grade(95, 95, 95, 95, 95, 1, 0, 0, 0) 74 let d2: i64 = cr_grade(95, 95, 95, 95, 95, 1, 0, 0, 0) 75 76 // ---- MEASURED exceed verdict ---- 77 var ok: i64 = 1 78 // A: ours caps at the structural ceiling; naive dangerously overgrades the frame-damaged car 79 if ours_A != CR_STRUCTURAL_CAP { ok = 0 } 80 if naive_A != 47 { ok = 0 } 81 if overgrade < 20 { ok = 0 } // material integrity gap (naive overgrades by >=20) 82 if naive_A <= CR_STRUCTURAL_CAP { ok = 0 } // neg-control: naive FAILS to cap (the dangerous case) 83 if ours_A > CR_STRUCTURAL_CAP { ok = 0 } // ours respects the ceiling 84 // B: no flag -> ours == naive (does not always-cap; tracks real condition) 85 if ours_B != naive_B { ok = 0 } 86 if ours_B != 47 { ok = 0 } 87 // C: monotonicity -- a worse car grades strictly lower 88 if ours_C >= ours_B { ok = 0 } 89 // determinism 90 if d1 != d2 { ok = 0 } 91 92 cr_w(1, "CONDITIONGATE engine=nx_condition_report MEASURED-grade-integrity-vs-naive-average" as *u8) 93 cr_w(1, " | A(frame+pristine) naive=" as *u8); cr_wn(1, naive_A) 94 cr_w(1, " ours=" as *u8); cr_wn(1, ours_A) 95 cr_w(1, " overgrade_naive=" as *u8); cr_wn(1, overgrade) 96 cr_w(1, " | ctrlB(no-flag) naive=" as *u8); cr_wn(1, naive_B); cr_w(1, " ours=" as *u8); cr_wn(1, ours_B) 97 cr_w(1, " | C(worse-car) ours=" as *u8); cr_wn(1, ours_C); cr_w(1, " (<B=" as *u8); cr_wn(1, ours_B); cr_w(1, ")" as *u8) 98 cr_w(1, " | SCOPE: grade-integrity vs naive-average ONLY; real-AutoGrade/human NOT-CLAIMED" as *u8) 99 if ok == 1 { cr_w(1, " verdict=GREEN\n" as *u8) } else { cr_w(1, " verdict=RED\n" as *u8) } 100 101 let lf: i64 = sys_openat_append(CR_LOG, 420) 102 if lf >= 0 { 103 cr_w(lf, "CONDITIONGATE engine=nx_condition_report A{naive=" as *u8); cr_wn(lf, naive_A) 104 cr_w(lf, " ours=" as *u8); cr_wn(lf, ours_A); cr_w(lf, " overgrade=" as *u8); cr_wn(lf, overgrade) 105 cr_w(lf, "} B{naive=" as *u8); cr_wn(lf, naive_B); cr_w(lf, " ours=" as *u8); cr_wn(lf, ours_B) 106 cr_w(lf, "} C{ours=" as *u8); cr_wn(lf, ours_C); cr_w(lf, "} SCOPE=grade-integrity-vs-naive-only" as *u8) 107 if ok == 1 { cr_w(lf, " verdict=GREEN\n" as *u8) } else { cr_w(lf, " verdict=RED\n" as *u8) } 108 sys_close(lf) 109 } 110 111 if ok == 1 { return 0 } 112 return 1 113}