code wiki / (root) / nx_underbuilt_board.nx

nx_underbuilt_board.nx source

↩ module page · 97 lines · 4647 B

1// nx_underbuilt_board.nx -- R6 THE UNDERBUILT-PART BOARD (cadtwin ladder; operator: identify underbuilt 2// parts when flipping cars). Reads the banked NHTSA complaints+recalls JSON (nx_underbuilt_fetch) and prints, 3// per vehicle: total complaints, per-COMPONENT frequency ranked with permille share, crash/fire tallies, and 4// the recall components (mandated fixes = confirmed underbuilt). All parsing = nx_underbuilt_lib context-byte 5// JSON scan; deterministic integer output. Vehicles grow as DATA rows in main (add a fetch row + a board row). 6// expect_exit: 0 license_tier: ORIGINAL 7import "nx_underbuilt_lib.nx" 8const K_MAGIC_16777216: i64 = 16777216 9const K_MAGIC_65536: i64 = 65536 10const K_MAGIC_8192: i64 = 8192 11const K_MAGIC_1024: i64 = 1024 12 13func ubb_vehicle(label: *u8, cpath: *u8, rpath: *u8, buf: *u8, t: *i64, rank: *i64) -> i64 { 14 ubl_puts("\n== " as *u8); ubl_puts(label); ubl_puts(" ==\n" as *u8) 15 let n: i64 = ubl_read(cpath, buf, K_MAGIC_16777216) 16 if n <= 0 { ubl_puts(" MISSING complaints raw (run nx_underbuilt_fetch)\n" as *u8); return 0 } 17 let total: i64 = ubl_key_int(buf, n, "count" as *u8, 5) 18 let crash: i64 = ubl_count_true(buf, n, "crash" as *u8, 5) 19 let fire: i64 = ubl_count_true(buf, n, "fire" as *u8, 4) 20 let ig1: i64 = ubl_reset(t) 21 let recs: i64 = ubl_tally(t, buf, n, "components" as *u8, 10) 22 ubl_puts(" complaints total=" as *u8); ubl_putn(total) 23 ubl_puts(" records-parsed=" as *u8); ubl_putn(recs) 24 ubl_puts(" crash-flag=" as *u8); ubl_putn(crash) 25 ubl_puts(" fire-flag=" as *u8); ubl_putn(fire); ubl_puts("\n" as *u8) 26 if recs <= 0 { ubl_puts(" NO records parsed\n" as *u8); return 0 } 27 let m: i64 = ubl_top(t, rank, 8) 28 let cnts: *i64 = t[4] as *i64 29 var r: i64 = 0 30 while r < m { 31 let idx: i64 = rank[r] 32 if idx >= 0 { 33 let c: i64 = cnts[idx] 34 let pm: i64 = (c * 1000) / recs 35 ubl_puts(" " as *u8); ubl_putn(pm); ubl_puts(" permille " as *u8); ubl_putn(c); ubl_puts("x " as *u8) 36 let ig2: i64 = ubl_name_out(t, idx) 37 ubl_puts("\n" as *u8) 38 } 39 r = r + 1 40 } 41 let topidx: i64 = rank[0] 42 let ndist: i64 = t[5] 43 44 let rn: i64 = ubl_read(rpath, buf, K_MAGIC_16777216) 45 var rcount: i64 = 0 - 1 46 if rn > 0 { 47 rcount = ubl_key_int(buf, rn, "Count" as *u8, 5) 48 let ig3: i64 = ubl_reset(t) 49 let rrecs: i64 = ubl_tally(t, buf, rn, "Component" as *u8, 9) 50 ubl_puts(" recalls total=" as *u8); ubl_putn(rcount); ubl_puts(" components:" as *u8); ubl_puts("\n" as *u8) 51 let rcnts: *i64 = t[4] as *i64 52 let rm: i64 = ubl_top(t, rank, 6) 53 var q: i64 = 0 54 while q < rm { 55 let ridx: i64 = rank[q] 56 if ridx >= 0 { 57 ubl_puts(" " as *u8); ubl_putn(rcnts[ridx]); ubl_puts("x " as *u8) 58 let ig4: i64 = ubl_name_out(t, ridx) 59 ubl_puts("\n" as *u8) 60 } 61 q = q + 1 62 } 63 } else { 64 ubl_puts(" MISSING recalls raw\n" as *u8) 65 } 66 if total <= 0 { return 0 } 67 if ndist <= 0 { return 0 } 68 if rcount < 0 { return 0 } 69 return 1 70} 71 72func main() -> i64 { 73 ubl_puts("=== nx_underbuilt_board -- NHTSA complaint/recall component frequency = the underbuilt-part flip signal ===\n" as *u8) 74 ubl_puts("(real API data banked by nx_underbuilt_fetch; permille = share of complaint records naming the component)\n" as *u8) 75 let buf: *u8 = sys_mmap(K_MAGIC_16777216) 76 let arena: *u8 = sys_mmap(K_MAGIC_65536) 77 let offs: *i64 = sys_mmap(K_MAGIC_8192) as *i64 78 let lens: *i64 = sys_mmap(K_MAGIC_8192) as *i64 79 let cnts: *i64 = sys_mmap(K_MAGIC_8192) as *i64 80 let t: *i64 = sys_mmap(256) as *i64 81 t[0] = arena as i64 82 t[2] = offs as i64 83 t[3] = lens as i64 84 t[4] = cnts as i64 85 t[8] = K_MAGIC_65536 86 let rank: *i64 = sys_mmap(K_MAGIC_1024) as *i64 87 88 var ok: i64 = 0 89 ok = ok + ubb_vehicle("2013 NISSAN ALTIMA (CVT era)" as *u8, "knowledge/fetched/ub_alt13c.raw" as *u8, "knowledge/fetched/ub_alt13r.raw" as *u8, buf, t, rank) 90 ok = ok + ubb_vehicle("2011 CHEVROLET CRUZE" as *u8, "knowledge/fetched/ub_crz11c.raw" as *u8, "knowledge/fetched/ub_crz11r.raw" as *u8, buf, t, rank) 91 ok = ok + ubb_vehicle("2016 HONDA CIVIC" as *u8, "knowledge/fetched/ub_civ16c.raw" as *u8, "knowledge/fetched/ub_civ16r.raw" as *u8, buf, t, rank) 92 93 ubl_puts("\nvehicles ok=" as *u8); ubl_putn(ok); ubl_puts(" / 3\n" as *u8) 94 if ok == 3 { ubl_puts("verdict=GREEN (board computed from real NHTSA data)\n" as *u8); return 0 } 95 ubl_puts("verdict=RED\n" as *u8) 96 return 1 97}