code wiki / _hdl_build / nx_ciq_visual.nx
nx_ciq_visual.nx source
↩ module page · 160 lines · 13926 B
1// nx_ciq_visual.nx -- R3 of the CIQ arc, now MARKET-GENERIC: the VISUALIZER. For EACH market it reads
2// placements + gap from the SOVEREIGN seg_store and emits a standalone browser Magic Quadrant (HTML +
3// inline SVG, integer coords no-float, authored byte-by-byte like Nishi's site pages -- NOT a 3rd-party
4// plot lib) to knowledge/staging/ciq_<market>_quadrant.html. Nishi is highlighted with its gap-vector
5// arrow. GATE per market: re-read + assert "<svg" + EVERY placed entity + quadrant labels (liar-kill a
6// phantom placement). 100% sovereign. license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_seg_store.nx"
9import "nx_uxf_decode.nx"
10const VZ_MAGIC_1024: i64 = 1024
11const VZ_MAGIC_131072: i64 = 131072
12
13const VZ_STORE: *u8 = "knowledge/store/ciq-"
14const VZ_W: i64 = 820
15const VZ_H: i64 = 600
16const VZ_ML: i64 = 90
17const VZ_MR: i64 = 40
18const VZ_MT: i64 = 64
19const VZ_MB: i64 = 70
20const VZ_EXMIN: i64 = 500
21const VZ_VISMIN: i64 = 500
22
23func vw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
24func vn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;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(1,bb,k); return 0 }
25func v_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 }
26func v_pint(s: *u8) -> i64 { var v: i64=0; var i: i64=0; var go: i64=1; while go==1 { let c: i64=s[i]; if c>=48 { if c<=57 { v=v*10+(c-48); i=i+1 } else { go=0 } } else { go=0 } } return v }
27func v_field(dk: *i64, dv: *i64, nf: i64, name: *u8) -> *u8 { var f: i64=0; while f<nf { if v_streq(dk[f] as *u8, name)==1 { return dv[f] as *u8 } f=f+1 } return 0 as *u8 }
28func v_split(buf: *u8, delim: i64, out: *i64, maxn: i64) -> i64 { var n: i64=0; var i: i64=0; var intok: i64=0; while buf[i]!=(0 as u8) { let c: i64=buf[i]; if c==delim { buf[i]=0 as u8; intok=0 } else { if intok==0 { if n<maxn { out[n]=(buf as i64)+i; n=n+1 } intok=1 } } i=i+1 } return n }
29func v_copy(src: *u8, dst: *u8) -> i64 { var i: i64=0; while src[i]!=(0 as u8){ dst[i]=src[i]; i=i+1 } dst[i]=0 as u8; return i }
30func bcat(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ buf[off+i]=s[i]; i=i+1 } return off+i }
31func bint(buf: *u8, off: i64, v: i64) -> i64 { var m: i64=v; var o: i64=off; if m<0{ buf[o]=45 as u8; o=o+1; m=0-m } let t: *u8=sys_mmap(32); var k: i64=0; if m==0{t[0]=48 as u8;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{ buf[o+i]=t[k-1-i]; i=i+1 } return o+k }
32func v_contains(hay: *u8, n: i64, needle: *u8) -> i64 { var nl: i64=0; while needle[nl]!=(0 as u8){ nl=nl+1 } if nl==0 { return 1 } var i: i64=0; while i + nl <= n { var j: i64=0; var ok: i64=1; while j < nl { if hay[i+j] != needle[j] { ok=0; j=nl } else { j=j+1 } } if ok==1 { return 1 } i=i+1 } return 0 }
33func v_key(buf: *u8, market: *u8, suffix: *u8) -> i64 { var o: i64=0; o=ss_cat(buf,o,"ciq:" as *u8); o=ss_cat(buf,o,market); o=ss_cat(buf,o,":" as *u8); o=ss_cat(buf,o,suffix); buf[o]=0 as u8; return o }
34func px_x(vis: i64) -> i64 { let pw: i64 = VZ_W - VZ_ML - VZ_MR; return VZ_ML + (vis * pw) / 1000 }
35func px_y(ex: i64) -> i64 { let ph: i64 = VZ_H - VZ_MT - VZ_MB; return VZ_MT + ((1000 - ex) * ph) / 1000 }
36
37func emit_dot(buf: *u8, off: i64, name: *u8, ex: i64, vis: i64, is_nishi: i64, idx: i64) -> i64 {
38 let cx: i64 = px_x(vis); let cy: i64 = px_y(ex)
39 var o: i64 = off
40 var col: *u8 = "#2c7fb8" as *u8; var rad: i64 = 6
41 if is_nishi==1 { col = "#c0392b" as *u8; rad = 9 }
42 o = bcat(buf, o, "<circle cx=\"" as *u8); o = bint(buf, o, cx); o = bcat(buf, o, "\" cy=\"" as *u8); o = bint(buf, o, cy)
43 o = bcat(buf, o, "\" r=\"" as *u8); o = bint(buf, o, rad); o = bcat(buf, o, "\" fill=\"" as *u8); o = bcat(buf, o, col); o = bcat(buf, o, "\" stroke=\"#fff\" stroke-width=\"2\"/>\n" as *u8)
44 var ly: i64 = cy - 12; let st: i64 = (idx % 3) * 14; ly = ly - st
45 o = bcat(buf, o, "<text x=\"" as *u8); o = bint(buf, o, cx + 11); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, ly)
46 o = bcat(buf, o, "\" font-family=\"monospace\" font-size=\"13\" fill=\"#111\">" as *u8); o = bcat(buf, o, name)
47 o = bcat(buf, o, " (" as *u8); o = bint(buf, o, vis); o = bcat(buf, o, "/" as *u8); o = bint(buf, o, ex); o = bcat(buf, o, ")</text>\n" as *u8)
48 return o
49}
50
51// emit ONE market's quadrant HTML; returns 1 if gate passes (svg + all entities present), else 0.
52func emit_market(market: *u8) -> i64 {
53 let gp: *i64 = sys_mmap(8) as *i64
54 let gl: *i64 = sys_mmap(8) as *i64
55 let dk: *i64 = sys_mmap(8 * 16) as *i64
56 let dv: *i64 = sys_mmap(8 * 16) as *i64
57 let mk: *u8 = sys_mmap(256); v_key(mk, market, "meta" as *u8)
58 if ss_get(VZ_STORE, mk, gp, gl) != 1 { return 0 }
59 let mnf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 16)
60 let ebuf: *u8 = sys_mmap(VZ_MAGIC_1024); v_copy(v_field(dk, dv, mnf, "entities" as *u8), ebuf)
61 let ent: *i64 = sys_mmap(8 * 16) as *i64
62 let N: i64 = v_split(ebuf, 44, ent, 16)
63
64 var ex_gap: i64 = 0; var vis_gap: i64 = 0
65 let gk: *u8 = sys_mmap(256); v_key(gk, market, "gap:nishi" as *u8)
66 if ss_get(VZ_STORE, gk, gp, gl) == 1 { let gnf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 16); ex_gap = v_pint(v_field(dk, dv, gnf, "ex_gap" as *u8)); vis_gap = v_pint(v_field(dk, dv, gnf, "vis_gap" as *u8)) }
67
68 let buf: *u8 = sys_mmap(VZ_MAGIC_131072)
69 var o: i64 = 0
70 o = bcat(buf, o, "<!doctype html><html><head><meta charset=\"utf-8\"><title>Nishi CIQ -- " as *u8); o = bcat(buf, o, market); o = bcat(buf, o, " Magic Quadrant</title>\n" as *u8)
71 o = bcat(buf, o, "<style>body{font-family:monospace;background:#f7f7f7;color:#111;margin:24px}h1{font-size:18px}.cap{color:#555;max-width:780px}</style></head><body>\n" as *u8)
72 o = bcat(buf, o, "<h1>Nishi Competitive-Intelligence Quadrant — " as *u8); o = bcat(buf, o, market); o = bcat(buf, o, " market</h1>\n" as *u8)
73 o = bcat(buf, o, "<p class=\"cap\">Gartner-style Magic Quadrant computed by the sovereign Nishi team (census → analyst → placer) over a cited capability matrix in the sovereign seg_store. x = Completeness of Vision, y = Ability to Execute. no-float permil 0..1000.</p>\n" as *u8)
74
75 let cx0: i64 = px_x(VZ_VISMIN); let cy0: i64 = px_y(VZ_EXMIN)
76 let x0: i64 = px_x(0); let x1: i64 = px_x(1000); let y0: i64 = px_y(0); let y1: i64 = px_y(1000)
77 o = bcat(buf, o, "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" as *u8); o = bint(buf, o, VZ_W); o = bcat(buf, o, "\" height=\"" as *u8); o = bint(buf, o, VZ_H); o = bcat(buf, o, "\" viewBox=\"0 0 " as *u8); o = bint(buf, o, VZ_W); o = bcat(buf, o, " " as *u8); o = bint(buf, o, VZ_H); o = bcat(buf, o, "\">\n" as *u8)
78 o = bcat(buf, o, "<rect x=\"0\" y=\"0\" width=\"" as *u8); o = bint(buf, o, VZ_W); o = bcat(buf, o, "\" height=\"" as *u8); o = bint(buf, o, VZ_H); o = bcat(buf, o, "\" fill=\"#ffffff\"/>\n" as *u8)
79 o = bcat(buf, o, "<rect x=\"" as *u8); o = bint(buf, o, cx0); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, y1); o = bcat(buf, o, "\" width=\"" as *u8); o = bint(buf, o, x1 - cx0); o = bcat(buf, o, "\" height=\"" as *u8); o = bint(buf, o, cy0 - y1); o = bcat(buf, o, "\" fill=\"#eaf6ea\"/>\n" as *u8)
80 o = bcat(buf, o, "<rect x=\"" as *u8); o = bint(buf, o, x0); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, y1); o = bcat(buf, o, "\" width=\"" as *u8); o = bint(buf, o, x1 - x0); o = bcat(buf, o, "\" height=\"" as *u8); o = bint(buf, o, y0 - y1); o = bcat(buf, o, "\" fill=\"none\" stroke=\"#333\" stroke-width=\"2\"/>\n" as *u8)
81 o = bcat(buf, o, "<line x1=\"" as *u8); o = bint(buf, o, cx0); o = bcat(buf, o, "\" y1=\"" as *u8); o = bint(buf, o, y1); o = bcat(buf, o, "\" x2=\"" as *u8); o = bint(buf, o, cx0); o = bcat(buf, o, "\" y2=\"" as *u8); o = bint(buf, o, y0); o = bcat(buf, o, "\" stroke=\"#bbb\" stroke-dasharray=\"5,4\"/>\n" as *u8)
82 o = bcat(buf, o, "<line x1=\"" as *u8); o = bint(buf, o, x0); o = bcat(buf, o, "\" y1=\"" as *u8); o = bint(buf, o, cy0); o = bcat(buf, o, "\" x2=\"" as *u8); o = bint(buf, o, x1); o = bcat(buf, o, "\" y2=\"" as *u8); o = bint(buf, o, cy0); o = bcat(buf, o, "\" stroke=\"#bbb\" stroke-dasharray=\"5,4\"/>\n" as *u8)
83 o = bcat(buf, o, "<text x=\"" as *u8); o = bint(buf, o, cx0 + 12); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, y1 + 18); o = bcat(buf, o, "\" font-family=\"monospace\" font-size=\"13\" fill=\"#2a7\">LEADERS</text>\n" as *u8)
84 o = bcat(buf, o, "<text x=\"" as *u8); o = bint(buf, o, x0 + 10); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, y1 + 18); o = bcat(buf, o, "\" font-family=\"monospace\" font-size=\"13\" fill=\"#999\">CHALLENGERS</text>\n" as *u8)
85 o = bcat(buf, o, "<text x=\"" as *u8); o = bint(buf, o, cx0 + 12); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, y0 - 8); o = bcat(buf, o, "\" font-family=\"monospace\" font-size=\"13\" fill=\"#999\">VISIONARIES</text>\n" as *u8)
86 o = bcat(buf, o, "<text x=\"" as *u8); o = bint(buf, o, x0 + 10); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, y0 - 8); o = bcat(buf, o, "\" font-family=\"monospace\" font-size=\"13\" fill=\"#999\">NICHE PLAYERS</text>\n" as *u8)
87 o = bcat(buf, o, "<text x=\"" as *u8); o = bint(buf, o, x0); o = bcat(buf, o, "\" y=\"" as *u8); o = bint(buf, o, VZ_H - 26); o = bcat(buf, o, "\" font-family=\"monospace\" font-size=\"12\" fill=\"#555\">Completeness of Vision →</text>\n" as *u8)
88 o = bcat(buf, o, "<text x=\"14\" y=\"" as *u8); o = bint(buf, o, VZ_MT + 6); o = bcat(buf, o, "\" font-family=\"monospace\" font-size=\"12\" fill=\"#555\">Ability to Execute ↑</text>\n" as *u8)
89
90 // nishi gap arrow
91 var nex: i64 = 0; var nvis: i64 = 0
92 let kb: *u8 = sys_mmap(256); let suf: *u8 = sys_mmap(128)
93 var ni: i64 = 0
94 while ni < N {
95 if v_streq(ent[ni] as *u8, "nishi" as *u8)==1 {
96 var so: i64=0; so=ss_cat(suf,so,"placement:" as *u8); so=ss_cat(suf,so,ent[ni] as *u8); suf[so]=0 as u8
97 v_key(kb, market, suf)
98 if ss_get(VZ_STORE, kb, gp, gl)==1 { let pnf: i64=canon_decode(gp[0] as *u8, gl[0], dk, dv, 16); nex=v_pint(v_field(dk,dv,pnf,"execute" as *u8)); nvis=v_pint(v_field(dk,dv,pnf,"vision" as *u8)) }
99 }
100 ni = ni + 1
101 }
102 if nex > 0 {
103 o = bcat(buf, o, "<line x1=\"" as *u8); o = bint(buf, o, px_x(nvis)); o = bcat(buf, o, "\" y1=\"" as *u8); o = bint(buf, o, px_y(nex)); o = bcat(buf, o, "\" x2=\"" as *u8); o = bint(buf, o, cx0); o = bcat(buf, o, "\" y2=\"" as *u8); o = bint(buf, o, cy0); o = bcat(buf, o, "\" stroke=\"#c0392b\" stroke-width=\"2\" stroke-dasharray=\"6,4\"/>\n" as *u8)
104 }
105 var i: i64 = 0
106 while i < N {
107 var so2: i64=0; so2=ss_cat(suf,so2,"placement:" as *u8); so2=ss_cat(suf,so2,ent[i] as *u8); suf[so2]=0 as u8
108 v_key(kb, market, suf)
109 if ss_get(VZ_STORE, kb, gp, gl)==1 {
110 let pnf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 16)
111 let ex: i64 = v_pint(v_field(dk, dv, pnf, "execute" as *u8))
112 let vis: i64 = v_pint(v_field(dk, dv, pnf, "vision" as *u8))
113 var isn: i64 = 0; if v_streq(ent[i] as *u8, "nishi" as *u8)==1 { isn = 1 }
114 o = emit_dot(buf, o, ent[i] as *u8, ex, vis, isn, i)
115 }
116 i = i + 1
117 }
118 o = bcat(buf, o, "</svg>\n" as *u8)
119 o = bcat(buf, o, "<p class=\"cap\"><b>Where Nishi needs to go:</b> +" as *u8); o = bint(buf, o, ex_gap); o = bcat(buf, o, " execute, +" as *u8); o = bint(buf, o, vis_gap); o = bcat(buf, o, " vision (permil) to reach LEADERS (red dashed = gap vector).</p>\n" as *u8)
120 o = bcat(buf, o, "</body></html>\n" as *u8)
121
122 let opath: *u8 = sys_mmap(256); var po: i64 = 0
123 po = ss_cat(opath, po, "knowledge/staging/ciq_" as *u8); po = ss_cat(opath, po, market); po = ss_cat(opath, po, "_quadrant.html" as *u8); opath[po] = 0 as u8
124 let fd: i64 = sys_openat_wr(opath, 420)
125 if fd < 0 { return 0 }
126 sys_write(fd, buf, o); sys_close(fd)
127
128 // gate: re-read + assert svg + all entities
129 let rb: *u8 = sys_mmap(VZ_MAGIC_131072); let rfd: i64 = sys_openat_rd(opath); var rn: i64 = 0
130 if rfd >= 0 { var r: i64 = 1; while r > 0 { r = sys_read(rfd, ((rb as i64)+rn) as *u8, VZ_MAGIC_131072 - rn); if r>0 { rn = rn + r } } sys_close(rfd) }
131 var ok: i64 = 1
132 if v_contains(rb, rn, "<svg" as *u8) == 0 { ok = 0 }
133 if v_contains(rb, rn, "LEADERS" as *u8) == 0 { ok = 0 }
134 var ec: i64 = 0; var e2: i64 = 0
135 while e2 < N { if v_contains(rb, rn, ent[e2] as *u8) == 1 { ec = ec + 1 } e2 = e2 + 1 }
136 if ec != N { ok = 0 }
137 vw(" emitted " as *u8); vw(opath); vw(" (" as *u8); vn(o); vw("B, " as *u8); vn(ec); vw("/" as *u8); vn(N); vw(" entities)\n" as *u8)
138 return ok
139}
140
141func main() -> i64 {
142 let gp: *i64 = sys_mmap(8) as *i64
143 let gl: *i64 = sys_mmap(8) as *i64
144 let dk: *i64 = sys_mmap(8 * 16) as *i64
145 let dv: *i64 = sys_mmap(8 * 16) as *i64
146 let mbuf: *u8 = sys_mmap(VZ_MAGIC_1024)
147 var have: i64 = 0
148 if ss_get(VZ_STORE, "ciq:markets" as *u8, gp, gl) == 1 { let mnf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 16); let lst: *u8 = v_field(dk, dv, mnf, "list" as *u8); if lst != (0 as *u8) { v_copy(lst, mbuf); have = 1 } }
149 if have == 0 { v_copy("connect" as *u8, mbuf) }
150 let markets: *i64 = sys_mmap(8 * 16) as *i64
151 let nm: i64 = v_split(mbuf, 44, markets, 16)
152
153 vw("=== nx_ciq_visual (market-generic) ===\n" as *u8)
154 var okc: i64 = 0
155 var mi: i64 = 0
156 while mi < nm { if emit_market(markets[mi] as *u8) == 1 { okc = okc + 1 } mi = mi + 1 }
157 vw("VISUALGATE markets=" as *u8); vn(nm); vw(" emitted_ok=" as *u8); vn(okc)
158 if okc == nm { vw(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
159 vw(" verdict=RED\n" as *u8); sys_exit(1); return 1
160}