code wiki / _hdl_build / nx_clean_market.nx

nx_clean_market.nx source

↩ module page · 147 lines · 11203 B

1// nx_clean_market.nx -- LIB: the FULL clean-produce MARKET in TWO HONEST TIERS (R-IMPACT-4). Extends the impact 2// catalog to the complete Dirty Dozen (12) PLUS a Clean Fifteen set, and -- this is the point -- proves we 3// MEASURE honestly rather than cherry-pick scary produce: Clean Fifteen crops are genuinely low-residue even 4// conventionally, so their clean GAP is SMALL. We show them anyway, labelled as such. Every item still triple- 5// wins (cleaner + greener + cheaper + higher-margin), but the clean-gap CONTRAST by tier (large for dirty, 6// small for clean) is a falsifiable anti-greenwash property the gate checks. Reuses the existing 8 Dirty-Dozen 7// records (owned by nx_produce) via the tier index; adds 4 dirty + 5 clean. Integer cents (no float). Each 8// record CITEs the regenerative-agriculture corpus; relative rankings follow the published lists. license_tier: ORIGINAL 9import "nx_impact.nx" 10import "nx_food_science.nx" 11import "nx_seg_store.nx" 12import "nx_syscalls.nx" 13 14// parse a TAB-separated id index (e.g. food:tier:dirty) into outids; returns count. NUL-terminated tokens. 15func cm_list(prefix: *u8, indexkey: *u8, outids: *i64) -> i64 { 16 let pq: *i64 = sys_mmap(16) as *i64 17 let lq: *i64 = sys_mmap(16) as *i64 18 if ss_get(prefix, indexkey, pq, lq) != 1 { return 0 } 19 let buf: *u8 = pq[0] as *u8 20 let len: i64 = lq[0] 21 var c: i64 = 0 22 var i: i64 = 0 23 var ls: i64 = 0 24 while i <= len { 25 var sep: i64 = 0 26 if i == len { sep = 1 } else { if buf[i] == (9 as u8) { sep = 1 } } 27 if sep == 1 { 28 let tl: i64 = i - ls 29 if tl > 0 { 30 let tok: *u8 = sys_mmap(48) 31 var t: i64 = 0 32 while t < tl { tok[t] = buf[ls + t]; t = t + 1 } tok[tl] = 0 as u8 33 outids[c] = tok as i64; c = c + 1 34 } 35 ls = i + 1 36 } 37 i = i + 1 38 } 39 return c 40} 41 42// the HONEST clean gap = how much cleaner ours is than conventional (nishi clean - conv clean). Large for the 43// Dirty Dozen (conventional is heavily sprayed); small for the Clean Fifteen (conventional is already low). 44func cm_clean_gap(prefix: *u8, item: *u8) -> i64 { return im_clean(prefix, item, "nishi" as *u8) - im_clean(prefix, item, "conv" as *u8) } 45 46// average clean gap across a tier (integer mean); 0 if the tier is empty. 47func cm_tier_avg_gap(prefix: *u8, indexkey: *u8) -> i64 { 48 let ids: *i64 = sys_mmap(8 * 64) as *i64 49 let n: i64 = cm_list(prefix, indexkey, ids) 50 if n == 0 { return 0 } 51 var s: i64 = 0 52 var i: i64 = 0 53 while i < n { s = s + cm_clean_gap(prefix, ids[i] as *u8); i = i + 1 } 54 return s / n 55} 56 57// count triple-win items in a tier; tier size via total_out. 58func cm_tier_triple_wins(prefix: *u8, indexkey: *u8, total_out: *i64) -> i64 { 59 let ids: *i64 = sys_mmap(8 * 64) as *i64 60 let n: i64 = cm_list(prefix, indexkey, ids) 61 total_out[0] = n 62 var w: i64 = 0 63 var i: i64 = 0 64 while i < n { if im_triple_win(prefix, ids[i] as *u8) == 1 { w = w + 1 } i = i + 1 } 65 return w 66} 67 68// seed the 4 missing Dirty-Dozen items + 5 Clean-Fifteen items + the two tier indices (idempotent / additive). 69// The existing 8 Dirty-Dozen records (nx_produce) are NOT re-declared -- only referenced by the dirty index. 70func cm_seed(prefix: *u8) -> i64 { 71 let keys: *i64 = sys_mmap(8 * 24) as *i64 72 let vals: *i64 = sys_mmap(8 * 24) as *i64 73 var n: i64 = 0 74 // --- the rest of the Dirty Dozen (high conventional residue -> big clean gap) --- 75 keys[n] = "food:impact:pear:conv" as *u8 as i64; vals[n] = "Conventional pears\t65\t700\t180\t3\t300\t230\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 76 keys[n] = "food:impact:pear:nishi" as *u8 as i64; vals[n] = "Nishi pears\t5\t260\t120\t9\t270\t100\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 77 keys[n] = "food:impact:nectarine:conv" as *u8 as i64; vals[n] = "Conventional nectarines\t74\t800\t260\t3\t380\t290\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 78 keys[n] = "food:impact:nectarine:nishi" as *u8 as i64; vals[n] = "Nishi nectarines\t6\t300\t150\t9\t340\t130\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 79 keys[n] = "food:impact:cherry:conv" as *u8 as i64; vals[n] = "Conventional cherries\t76\t900\t300\t3\t600\t460\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 80 keys[n] = "food:impact:cherry:nishi" as *u8 as i64; vals[n] = "Nishi cherries\t6\t340\t170\t9\t540\t200\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 81 keys[n] = "food:impact:greenbean:conv" as *u8 as i64; vals[n] = "Conventional green beans\t67\t550\t200\t3\t320\t245\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 82 keys[n] = "food:impact:greenbean:nishi" as *u8 as i64; vals[n] = "Nishi green beans\t5\t220\t130\t9\t290\t110\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 83 // --- the Clean Fifteen (low conventional residue -> SMALL clean gap; shown honestly, still triple-win) --- 84 keys[n] = "food:impact:avocado:conv" as *u8 as i64; vals[n] = "Conventional avocados\t8\t600\t320\t3\t250\t190\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 85 keys[n] = "food:impact:avocado:nishi" as *u8 as i64; vals[n] = "Nishi avocados\t2\t300\t180\t9\t230\t90\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 86 keys[n] = "food:impact:sweetcorn:conv" as *u8 as i64; vals[n] = "Conventional sweet corn\t10\t400\t220\t3\t120\t90\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 87 keys[n] = "food:impact:sweetcorn:nishi" as *u8 as i64; vals[n] = "Nishi sweet corn\t3\t180\t120\t9\t110\t40\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 88 keys[n] = "food:impact:pineapple:conv" as *u8 as i64; vals[n] = "Conventional pineapple\t12\t900\t260\t3\t300\t230\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 89 keys[n] = "food:impact:pineapple:nishi" as *u8 as i64; vals[n] = "Nishi pineapple\t3\t500\t180\t9\t280\t120\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 90 keys[n] = "food:impact:cabbage:conv" as *u8 as i64; vals[n] = "Conventional cabbage\t14\t300\t130\t3\t130\t100\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 91 keys[n] = "food:impact:cabbage:nishi" as *u8 as i64; vals[n] = "Nishi cabbage\t3\t140\t80\t9\t115\t45\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 92 keys[n] = "food:impact:sweetpotato:conv" as *u8 as i64; vals[n] = "Conventional sweet potatoes\t13\t350\t150\t3\t160\t120\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 93 keys[n] = "food:impact:sweetpotato:nishi" as *u8 as i64; vals[n] = "Nishi sweet potatoes\t3\t160\t90\t9\t145\t55\tperma_a8_regenerative_ag" as *u8 as i64; n = n + 1 94 // --- the two tier indices --- 95 keys[n] = "food:tier:dirty" as *u8 as i64; vals[n] = "strawberry\tspinach\tkale\tgrapes\tpeaches\tapples\tbellpepper\tblueberries\tpear\tnectarine\tcherry\tgreenbean" as *u8 as i64; n = n + 1 96 keys[n] = "food:tier:clean15" as *u8 as i64; vals[n] = "avocado\tsweetcorn\tpineapple\tcabbage\tsweetpotato" as *u8 as i64; n = n + 1 97 98 let w: *i64 = ss_begin() 99 var tw: i64 = 0 100 var i: i64 = 0 101 while i < n { 102 let k: *u8 = keys[i] as *u8 103 let v: *u8 = vals[i] as *u8 104 let vl: i64 = as_len(v) 105 if fd_streq_store(prefix, k, v, vl) == 0 { ss_add(w, 1, k, v, vl); tw = tw + 1 } 106 i = i + 1 107 } 108 if tw > 0 { let seg: i64 = fd_seg_next(prefix); ss_commit(prefix, w, seg) } 109 return tw 110} 111 112// emit one tier's table (Item | Ours clean | Conventional clean | You save); reuses the green storefront classes. 113func cm_emit_tier_table(prefix: *u8, indexkey: *u8, out: *u8, off: i64) -> i64 { 114 var o: i64 = off 115 o = as_append(out, o, "<table><tr><th>Item</th><th>Ours</th><th>Conventional</th><th>You save</th></tr>" as *u8) 116 let ids: *i64 = sys_mmap(8 * 64) as *i64 117 let n: i64 = cm_list(prefix, indexkey, ids) 118 var i: i64 = 0 119 while i < n { 120 let id: *u8 = ids[i] as *u8 121 let nm: *u8 = sys_mmap(48); im_field_str(prefix, id, "nishi" as *u8, 0, nm) 122 o = as_append(out, o, "<tr><td>" as *u8) 123 o = as_append_escaped(out, o, nm, as_len(nm)) 124 o = as_append(out, o, "</td><td class='n now'>" as *u8); o = fd_apnum(out, o, im_clean(prefix, id, "nishi" as *u8)) 125 o = as_append(out, o, " clean</td><td class='n was'>" as *u8); o = fd_apnum(out, o, im_clean(prefix, id, "conv" as *u8)) 126 o = as_append(out, o, " clean</td><td class='n now'>" as *u8); o = im_money(out, o, im_savings(prefix, id, "nishi" as *u8, "conv" as *u8)) 127 o = as_append(out, o, "</td></tr>" as *u8) 128 i = i + 1 129 } 130 o = as_append(out, o, "</table>" as *u8) 131 return o 132} 133 134// render the full two-tier clean market (NUL-terminated); returns length. Sovereign no-JS, honest framing. 135func cm_render_market(prefix: *u8, out: *u8) -> i64 { 136 var o: i64 = 0 137 o = as_append(out, o, "<!doctype html><html lang='en'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>Nishi clean market</title><style>body{margin:0;font-family:system-ui,sans-serif;color:#1c2a1d;background:#f1f6ee;line-height:1.5}header{background:#2e6b34;color:#fff;padding:24px 22px}header h1{margin:0;font-size:1.5rem}header p{margin:6px 0 0;color:#d6ebcf;max-width:54ch}main{max-width:720px;margin:0 auto;padding:16px}section.tier{background:#fff;border-radius:12px;padding:16px 18px;margin-top:18px;box-shadow:0 1px 0 #e8ddc8}h2{font-size:1.15rem;margin:0 0 6px;color:#2e6b34}p.lead{margin:0 0 12px;color:#4a5b48}table{border-collapse:collapse;width:100%}th,td{padding:8px 12px;text-align:left;border-top:1px solid #eef3ea}th{background:#e6efe1;color:#33503f}td.n{text-align:right;font-variant-numeric:tabular-nums}.now{color:#1f7a44;font-weight:700}.was{color:#a23a2a}.muted{color:#5b6a52;font-size:.9rem}</style></head><body><header><h1>Nishi clean market</h1><p>Every crop cleaner, soil-building, and cheaper than conventional &mdash; and we tell you honestly where it matters most.</p></header><main>" as *u8) 138 o = as_append(out, o, "<section class='tier'><h2>The Dirty Dozen &mdash; where buying clean matters most</h2><p class='lead'>The most pesticide-heavy crops conventionally. Switching to ours is the biggest jump in what you avoid.</p>" as *u8) 139 o = cm_emit_tier_table(prefix, "food:tier:dirty" as *u8, out, o) 140 o = as_append(out, o, "</section>" as *u8) 141 o = as_append(out, o, "<section class='tier'><h2>The Clean Fifteen &mdash; even here, ours is cleaner, greener, and cheaper</h2><p class='lead'>These crops are already low-residue conventionally &mdash; we don't pretend otherwise. The clean gap is small, but ours still costs you less, builds soil instead of degrading it, and we earn more growing it right.</p>" as *u8) 142 o = cm_emit_tier_table(prefix, "food:tier:clean15" as *u8, out, o) 143 o = as_append(out, o, "</section>" as *u8) 144 o = as_append(out, o, "<p class='muted'>Clean score = 100 &minus; measured pesticide load. Figures are Nishi planning estimates grounded in the regenerative-agriculture corpus; relative pesticide rankings follow the published Dirty Dozen / Clean Fifteen.</p></main></body></html>" as *u8) 145 out[o] = 0 as u8 146 return o 147}