code wiki / _hdl_build / nx_produce_gate.nx

nx_produce_gate.nx source

↩ module page · 103 lines · 5482 B

1// nx_produce_gate.nx -- GATE: R-IMPACT-2. The clean-produce catalog at product-line scale. T1 catalog (Dirty 2// Dozen subset), T2 EVERY item triple-wins, T3 basket customer savings, T4 we earn more on the basket (vertical 3// integration), T5 clean gap (Nishi clean >=90, conventional <=35 across the board), T6 sovereign storefront 4// shipped. license_tier: ORIGINAL 5import "nx_produce.nx" 6import "nx_impact.nx" 7import "nx_food_science.nx" 8import "nx_publisher.nx" 9import "nx_seg_store.nx" 10import "nx_syscalls.nx" 11 12const QG_FOOD: *u8 = "knowledge/store/food-" 13const QG_Q: *u8 = "knowledge/publish/produce-queue.tsv" 14const QG_LED: *u8 = "knowledge/publish/produce-ledger.tsv" 15const QG_STG: *u8 = "knowledge/publish/produce-stage" 16const QG_LIVE: *u8 = "knowledge/publish/produce-live" 17const QG_STAGE_FILE: *u8 = "knowledge/staging/produce/clean-produce.html" 18const QG_LIVE_FILE: *u8 = "knowledge/publish/produce-live/clean-produce.html" 19 20func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 21func g_i(v: i64) -> i64 { 22 let bb: *u8 = sys_mmap(28); var m: i64 = v 23 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 24 let t: *u8 = sys_mmap(28); var k: i64 = 0 25 if m == 0 { t[0] = 48 as u8; k = 1 } 26 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 27 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 28} 29func g_money(c: i64) -> i64 { let b: *u8 = sys_mmap(24); let o: i64 = im_money(b, 0, c); sys_write(1, b, o); return 0 } 30func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 31 32func main() -> i64 { 33 g_p("=== nx_produce_gate (R-IMPACT-2: the clean-produce catalog) ===\n" as *u8) 34 fd_seed(QG_FOOD) 35 let sw: i64 = pd_seed(QG_FOOD) 36 g_p("produce records authored this run=" as *u8); g_i(sw); g_p("\n" as *u8) 37 38 let ids: *i64 = sys_mmap(8 * 64) as *i64 39 let n: i64 = pd_list(QG_FOOD, ids) 40 41 var pass: i64 = 0 42 var tot: i64 = 0 43 44 // T1 catalog size 45 tot = tot + 1 46 if n == 8 { pass = pass + 1; g_p("PASS T1 catalog: 8 Dirty-Dozen items\n" as *u8) } else { g_p("FAIL T1 n=" as *u8); g_i(n); g_p("\n" as *u8) } 47 48 // T2 every item triple-wins 49 let totp: *i64 = sys_mmap(16) as *i64 50 let wins: i64 = pd_all_triple_win(QG_FOOD, totp) 51 g_p("triple-win items=" as *u8); g_i(wins); g_p("/" as *u8); g_i(totp[0]); g_p("\n" as *u8) 52 tot = tot + 1 53 if wins == totp[0] { if totp[0] == 8 { pass = pass + 1; g_p("PASS T2 EVERY item is cleaner+greener+cheaper AND higher-margin (8/8 triple win)\n" as *u8) } else { g_p("FAIL T2 count\n" as *u8) } } else { g_p("FAIL T2 wins\n" as *u8) } 54 55 // T3 basket customer savings 56 let bsave: i64 = pd_basket_savings(QG_FOOD) 57 g_p("basket: customer saves " as *u8); g_money(bsave); g_p("\n" as *u8) 58 tot = tot + 1 59 if bsave == 800 { pass = pass + 1; g_p("PASS T3 whole-basket savings $8.00 vs the supermarket\n" as *u8) } else { g_p("FAIL T3 bsave=" as *u8); g_i(bsave); g_p("\n" as *u8) } 60 61 // T4 we earn MORE on the basket 62 let mn: i64 = pd_basket_margin(QG_FOOD, "nishi" as *u8) 63 let mc: i64 = pd_basket_margin(QG_FOOD, "conv" as *u8) 64 g_p("basket margin: nishi=" as *u8); g_money(mn); g_p(" conv=" as *u8); g_money(mc); g_p("\n" as *u8) 65 tot = tot + 1 66 if mn > mc { if bsave > 0 { pass = pass + 1; g_p("PASS T4 we earn MORE on the basket (" as *u8); g_money(mn); g_p(" > " as *u8); g_money(mc); g_p(") while the customer pays less\n" as *u8) } else { g_p("FAIL T4 savings\n" as *u8) } } else { g_p("FAIL T4 margin\n" as *u8) } 67 68 // T5 clean gap across the board 69 tot = tot + 1 70 var ok5: i64 = 1 71 var i: i64 = 0 72 while i < n { 73 if im_clean(QG_FOOD, ids[i] as *u8, "nishi" as *u8) < 90 { ok5 = 0 } 74 if im_clean(QG_FOOD, ids[i] as *u8, "conv" as *u8) > 35 { ok5 = 0 } 75 i = i + 1 76 } 77 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 clean gap: every Nishi item >=90 clean, every conventional <=35\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 78 79 // T6 sovereign storefront + ship 80 let page: *u8 = sys_mmap(65536) 81 let np: i64 = pd_render_storefront(QG_FOOD, page) 82 tot = tot + 1 83 var ok6: i64 = 1 84 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } 85 if as_contains(page, np, "strawberries" as *u8) != 1 { ok6 = 0 } 86 if as_contains(page, np, "blueberries" as *u8) != 1 { ok6 = 0 } 87 if as_contains(page, np, "$8.00" as *u8) != 1 { ok6 = 0 } 88 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 89 sys_mkdir("knowledge/staging/produce" as *u8, 0x1ed) 90 let sfd: i64 = sys_openat_wr(QG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 91 pub_init() 92 sys_mkdir(QG_STG, 0x1ed) 93 sys_mkdir(QG_LIVE, 0x1ed) 94 pub_submit_to(QG_Q, QG_STAGE_FILE, "clean-produce.html" as *u8, "nishifoodfamily" as *u8, "nishi-produce" as *u8, "internal" as *u8) 95 pub_run_full(QG_Q, QG_LED, QG_STG, QG_LIVE, "publish:produce" as *u8) 96 if g_exists(QG_LIVE_FILE) != 1 { ok6 = 0 } 97 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 sovereign clean-produce storefront shipped (" as *u8); g_i(np); g_p(" bytes)\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 98 99 g_p("nx_produce_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 100 if pass == tot { g_p(" verdict=GREEN (clean-produce line: the triple win at basket scale, shipped)\n" as *u8); return 0 } 101 g_p(" verdict=RED\n" as *u8) 102 return 1 103}