code wiki / _hdl_build / nx_vizsla_venue.nx

nx_vizsla_venue.nx source

↩ module page · 683 lines · 25541 B

1// nx_vizsla_venue.nx -- NISHI VIZSLA VENUE PIPELINE: coordinate finding + hiring buildings. 2// Operator 2026-07-07: "coordinating the finding and hiring of buildings". The deal-pipeline 3// pattern (nx_vizsla_deal precedent) applied to venue hire: REQUIREMENTS -> CANDIDATES -> 4// additive STAGE history (found/contacted/quoted/visited/booked/rejected, latest-by-date wins, 5// nothing destroyed) -> integer FIT SCORE vs the requirement -> a BOOKED venue emits the exact 6// calendar EVENT line so the hire lands on the group calendar (composes nx_vizsla_calendar's 7// load format -- the bridge is data, not a fork). 8// 9// Records (load <file> <prefix> [segid], additive + CID-idempotent): 10// REQ <event> <capacity> <budget_cents> <date> <start_min> <dur_min> -> "req:" 11// VENUE <event> <vid> <capacity> <cost_cents> <contact> <name> -> "ven:" 12// STAGE <date> <event> <vid> <found|contacted|quoted|visited|booked|rejected> -> "stg:" 13// Command: 14// board <prefix> <event> 15// per candidate: latest stage + fit score = cap_ok*50 + within_budget*30 + 16// ((budget-cost)*20)/budget (cheaper = better, integer) with over_budget/too_small flags; 17// sorted score desc / cost asc / vid. best = top non-rejected. A booked venue emits 18// VIZSLA-VEN-BOOKED + VIZSLA-VEN-CAL-LINE "EVENT venue-<event> <date> <start> <dur> <name>". 19// Loud-fail: missing REQ, unknown event, bad stage word, bad numbers/dates. 20// Score weights 50/30/20 are the documented v1 model (single place, swap for CONF rows when 21// multi-event tuning is real -- rule 11 exception documented, not buried). 22// spec: knowledge/research/2026-06-22-vizsla-sclass-roadmap.md license_tier: ORIGINAL 23import "nx_syscalls.nx" 24import "nx_canon_cid.nx" 25import "nx_seg_store.nx" 26const K_MAGIC_1970: i64 = 1970 27const K_MAGIC_146097: i64 = 146097 28const K_MAGIC_719468: i64 = 719468 29const K_MAGIC_2048: i64 = 2048 30const K_MAGIC_1440: i64 = 1440 31const K_MAGIC_4096: i64 = 4096 32const K_MAGIC_65536: i64 = 65536 33 34func vv_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 35func vv_p(s: *u8) -> i64 { sys_write(1, s, vv_slen(s)); return 0 } 36 37func vv_eq(a: *u8, b: *u8) -> i64 { 38 var i: i64 = 0 39 var go: i64 = 1 40 while go == 1 { 41 if a[i] != b[i] { return 0 } 42 if a[i] == (0 as u8) { return 1 } 43 i = i + 1 44 } 45 return 0 46} 47 48func vv_cmp(a: *u8, b: *u8) -> i64 { 49 var i: i64 = 0 50 var go: i64 = 1 51 while go == 1 { 52 let ca: i64 = a[i] as i64 53 let cb: i64 = b[i] as i64 54 if ca < cb { return 0 - 1 } 55 if ca > cb { return 1 } 56 if ca == 0 { return 0 } 57 i = i + 1 58 } 59 return 0 60} 61 62func vv_dup(s: *u8) -> *u8 { 63 let n: i64 = vv_slen(s) 64 let d: *u8 = sys_mmap(n + 2) 65 var i: i64 = 0 66 while i <= n { d[i] = s[i]; i = i + 1 } 67 return d 68} 69 70func vv_atoi(s: *u8) -> i64 { 71 var v: i64 = 0 72 var i: i64 = 0 73 while s[i] != (0 as u8) { 74 let d: i64 = (s[i] as i64) - 48 75 if d >= 0 { if d <= 9 { v = v * 10 + d } } 76 i = i + 1 77 } 78 return v 79} 80 81func vv_digits(s: *u8) -> i64 { 82 if s[0] == (0 as u8) { return 0 } 83 var i: i64 = 0 84 while s[i] != (0 as u8) { 85 let d: i64 = (s[i] as i64) - 48 86 if d < 0 { return 0 } 87 if d > 9 { return 0 } 88 i = i + 1 89 } 90 return 1 91} 92 93func vv_isws(c: i64) -> i64 { 94 if c == 32 { return 1 } 95 if c == 13 { return 1 } 96 if c == 9 { return 1 } 97 return 0 98} 99 100func vv_tok(b: *u8, off: i64, lend: i64, dst: *u8, cap: i64) -> i64 { 101 var p: i64 = off 102 var go: i64 = 1 103 while go == 1 { 104 if p >= lend { go = 0 } else { 105 if vv_isws(b[p] as i64) == 1 { p = p + 1 } else { go = 0 } 106 } 107 } 108 var t: i64 = 0 109 go = 1 110 while go == 1 { 111 if p >= lend { go = 0 } else { 112 if vv_isws(b[p] as i64) == 1 { go = 0 } else { 113 if t < cap - 1 { dst[t] = b[p]; t = t + 1 } 114 p = p + 1 115 } 116 } 117 } 118 dst[t] = 0 as u8 119 return p 120} 121 122func vv_cat(dst: *u8, off: i64, s: *u8) -> i64 { 123 var i: i64 = 0 124 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 125 return off + i 126} 127 128func vv_catn(dst: *u8, off: i64, v: i64) -> i64 { 129 var o: i64 = off 130 var m: i64 = v 131 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 132 let t: *u8 = sys_mmap(28) 133 var k: i64 = 0 134 if m == 0 { t[0] = 48 as u8; k = 1 } 135 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 136 var i: i64 = 0 137 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 138 return o + k 139} 140 141func vv_kmemeq(b: *u8, off: i64, n: i64, s: *u8) -> i64 { 142 if vv_slen(s) != n { return 0 } 143 var i: i64 = 0 144 while i < n { 145 if b[off + i] != s[i] { return 0 } 146 i = i + 1 147 } 148 return 1 149} 150 151func vv_field(rec: *u8, rl: i64, want: *u8, out: *u8, cap: i64) -> i64 { 152 if rl < 8 { return 0 } 153 let nf: i64 = ss_r32(rec, 4) 154 var off: i64 = 8 155 var fi: i64 = 0 156 while fi < nf { 157 if off + 8 > rl { return 0 } 158 let kl: i64 = ss_r32(rec, off) 159 let koff: i64 = off + 4 160 let vl: i64 = ss_r32(rec, koff + kl) 161 let voff: i64 = koff + kl + 4 162 if vv_kmemeq(rec, koff, kl, want) == 1 { 163 var t: i64 = 0 164 while t < vl { 165 if t < cap - 1 { out[t] = rec[voff + t] } 166 t = t + 1 167 } 168 if t > cap - 1 { t = cap - 1 } 169 out[t] = 0 as u8 170 return 1 171 } 172 off = voff + vl 173 fi = fi + 1 174 } 175 return 0 176} 177 178func vv_iskind(b: *u8, koff: i64, kl: i64, pfx: *u8) -> i64 { 179 if kl <= 4 { return 0 } 180 return vv_kmemeq(b, koff, 4, pfx) 181} 182 183func vv_datedays(s: *u8) -> i64 { 184 let nums: *i64 = sys_mmap(8 * 4) as *i64 185 var nn: i64 = 0 186 var cur: i64 = 0 187 var indig: i64 = 0 188 var i: i64 = 0 189 var go: i64 = 1 190 while go == 1 { 191 let c: i64 = s[i] as i64 192 var isd: i64 = 0 193 if c >= 48 { if c <= 57 { isd = 1 } } 194 if isd == 1 { cur = cur * 10 + (c - 48); indig = 1 } 195 if isd == 0 { 196 if indig == 1 { 197 if nn < 4 { nums[nn] = cur; nn = nn + 1 } 198 cur = 0 199 indig = 0 200 } 201 } 202 if c == 0 { go = 0 } 203 i = i + 1 204 } 205 if nn != 3 { return 0 - 1 } 206 var y: i64 = nums[0] 207 let m: i64 = nums[1] 208 let d: i64 = nums[2] 209 if y < K_MAGIC_1970 { return 0 - 1 } 210 if m < 1 { return 0 - 1 } 211 if m > 12 { return 0 - 1 } 212 if d < 1 { return 0 - 1 } 213 if d > 31 { return 0 - 1 } 214 if m <= 2 { y = y - 1 } 215 let era: i64 = y / 400 216 let yoe: i64 = y - era * 400 217 var mp: i64 = m - 3 218 if m <= 2 { mp = m + 9 } 219 let doy: i64 = (153 * mp + 2) / 5 + d - 1 220 let doe: i64 = yoe * 365 + yoe / 4 - yoe / 100 + doy 221 return era * K_MAGIC_146097 + doe - K_MAGIC_719468 222} 223 224func vv_find(list: *i64, n: i64, s: *u8) -> i64 { 225 var i: i64 = 0 226 while i < n { 227 if vv_eq(list[i] as *u8, s) == 1 { return i } 228 i = i + 1 229 } 230 return 0 - 1 231} 232 233func vv_stage_ok(s: *u8) -> i64 { 234 if vv_eq(s, "found" as *u8) == 1 { return 1 } 235 if vv_eq(s, "contacted" as *u8) == 1 { return 1 } 236 if vv_eq(s, "quoted" as *u8) == 1 { return 1 } 237 if vv_eq(s, "visited" as *u8) == 1 { return 1 } 238 if vv_eq(s, "booked" as *u8) == 1 { return 1 } 239 if vv_eq(s, "rejected" as *u8) == 1 { return 1 } 240 return 0 241} 242 243func vv_put(keys: *i64, vals: *i64, nf: i64, kp: *u8, st: *i64) -> i64 { 244 let enc: *u8 = sys_mmap(K_MAGIC_2048) 245 let el: i64 = canon_encode(keys, vals, nf, enc) 246 let cid: *u8 = sys_mmap(96) 247 cid_of(enc, el, cid) 248 let kbuf: *u8 = sys_mmap(128) 249 var ko: i64 = 0 250 ko = vv_cat(kbuf, ko, kp) 251 ko = vv_cat(kbuf, ko, cid) 252 kbuf[ko] = 0 as u8 253 let seen: *i64 = st[1] as *i64 254 var fresh: i64 = 1 255 if vv_find(seen, st[2], kbuf) >= 0 { fresh = 0; st[4] = st[4] + 1 } 256 if fresh == 1 { 257 if st[2] < K_MAGIC_2048 { 258 let dk: *u8 = vv_dup(kbuf) 259 seen[st[2]] = dk as i64 260 st[2] = st[2] + 1 261 } 262 } 263 if fresh == 1 { 264 let pp: *i64 = sys_mmap(16) as *i64 265 let ll: *i64 = sys_mmap(16) as *i64 266 if ss_get_idx(st[6] as *u8, kbuf, pp, ll) == 1 { fresh = 0; st[5] = st[5] + 1 } 267 } 268 if fresh == 1 { 269 if ss_add(st[0] as *i64, 1, kbuf, enc, el) != 0 { return 0 - 1 } 270 st[3] = st[3] + 1 271 } 272 return 0 273} 274 275// ---------------- LOAD ---------------- 276func vv_cmd_load(argc: i64, argv: *i64) -> i64 { 277 if argc < 4 { vv_p("VIZSLA-VEN load needs <file> <prefix> -- fail loud\n" as *u8); return 1 } 278 let efile: *u8 = argv[2] as *u8 279 let prefix: *u8 = argv[3] as *u8 280 var segid: i64 = 0 281 if argc > 4 { segid = vv_atoi(argv[4] as *u8) } 282 if segid == 0 { segid = sys_now_us() } 283 284 let szp: *i64 = sys_mmap(16) as *i64 285 let b: *u8 = ss_readall(efile, szp) 286 let sz: i64 = szp[0] 287 if sz <= 0 { vv_p("VIZSLA-VEN file MISSING/EMPTY -- fail loud\n" as *u8); return 1 } 288 289 let rkeys: *i64 = sys_mmap(8 * 8) as *i64 290 let rvals: *i64 = sys_mmap(8 * 8) as *i64 291 rkeys[0] = "kind" as *u8 as i64 292 rkeys[1] = "event" as *u8 as i64 293 rkeys[2] = "capacity" as *u8 as i64 294 rkeys[3] = "budget" as *u8 as i64 295 rkeys[4] = "date" as *u8 as i64 296 rkeys[5] = "start" as *u8 as i64 297 rkeys[6] = "dur" as *u8 as i64 298 rvals[0] = "req" as *u8 as i64 299 let vkeys: *i64 = sys_mmap(8 * 8) as *i64 300 let vvals: *i64 = sys_mmap(8 * 8) as *i64 301 vkeys[0] = "kind" as *u8 as i64 302 vkeys[1] = "event" as *u8 as i64 303 vkeys[2] = "vid" as *u8 as i64 304 vkeys[3] = "capacity" as *u8 as i64 305 vkeys[4] = "cost" as *u8 as i64 306 vkeys[5] = "contact" as *u8 as i64 307 vkeys[6] = "name" as *u8 as i64 308 vvals[0] = "ven" as *u8 as i64 309 let skeys: *i64 = sys_mmap(8 * 8) as *i64 310 let svals: *i64 = sys_mmap(8 * 8) as *i64 311 skeys[0] = "kind" as *u8 as i64 312 skeys[1] = "date" as *u8 as i64 313 skeys[2] = "event" as *u8 as i64 314 skeys[3] = "vid" as *u8 as i64 315 skeys[4] = "stage" as *u8 as i64 316 svals[0] = "stg" as *u8 as i64 317 318 let st: *i64 = sys_mmap(8 * 8) as *i64 319 st[0] = ss_begin() as i64 320 st[1] = sys_mmap(8 * K_MAGIC_2048) 321 st[2] = 0 322 st[3] = 0 323 st[4] = 0 324 st[5] = 0 325 st[6] = prefix as i64 326 327 let t0: *u8 = sys_mmap(128) 328 let f1: *u8 = sys_mmap(128) 329 let f2: *u8 = sys_mmap(128) 330 let f3: *u8 = sys_mmap(128) 331 let f4: *u8 = sys_mmap(128) 332 let f5: *u8 = sys_mmap(128) 333 let f6: *u8 = sys_mmap(256) 334 var scanned: i64 = 0 335 336 var i: i64 = 0 337 while i < sz { 338 var e: i64 = i 339 var go: i64 = 1 340 while go == 1 { 341 if e >= sz { go = 0 } else { 342 if b[e] == (10 as u8) { go = 0 } else { e = e + 1 } 343 } 344 } 345 var p: i64 = vv_tok(b, i, e, t0, 128) 346 if t0[0] == (35 as u8) { t0[0] = 0 as u8 } 347 if vv_eq(t0, "REQ" as *u8) == 1 { 348 scanned = scanned + 1 349 p = vv_tok(b, p, e, f1, 128) 350 p = vv_tok(b, p, e, f2, 128) 351 p = vv_tok(b, p, e, f3, 128) 352 p = vv_tok(b, p, e, f4, 128) 353 p = vv_tok(b, p, e, f5, 128) 354 p = vv_tok(b, p, e, f6, 256) 355 if f1[0] == (0 as u8) { vv_p("VIZSLA-VEN REQ missing event -- fail loud\n" as *u8); return 1 } 356 if vv_digits(f2) == 0 { vv_p("VIZSLA-VEN REQ capacity not digits -- fail loud\n" as *u8); return 1 } 357 if vv_digits(f3) == 0 { vv_p("VIZSLA-VEN REQ budget not digits -- fail loud\n" as *u8); return 1 } 358 if vv_datedays(f4) < 0 { vv_p("VIZSLA-VEN REQ bad date -- fail loud\n" as *u8); return 1 } 359 if vv_digits(f5) == 0 { vv_p("VIZSLA-VEN REQ start not digits -- fail loud\n" as *u8); return 1 } 360 if vv_digits(f6) == 0 { vv_p("VIZSLA-VEN REQ dur not digits -- fail loud\n" as *u8); return 1 } 361 if vv_atoi(f2) < 1 { vv_p("VIZSLA-VEN REQ capacity < 1 -- fail loud\n" as *u8); return 1 } 362 if vv_atoi(f3) < 1 { vv_p("VIZSLA-VEN REQ budget < 1 -- fail loud\n" as *u8); return 1 } 363 if vv_atoi(f5) >= K_MAGIC_1440 { vv_p("VIZSLA-VEN REQ start >= 1440 -- fail loud\n" as *u8); return 1 } 364 if vv_atoi(f6) < 1 { vv_p("VIZSLA-VEN REQ dur < 1 -- fail loud\n" as *u8); return 1 } 365 rvals[1] = f1 as i64 366 rvals[2] = f2 as i64 367 rvals[3] = f3 as i64 368 rvals[4] = f4 as i64 369 rvals[5] = f5 as i64 370 rvals[6] = f6 as i64 371 if vv_put(rkeys, rvals, 7, "req:" as *u8, st) != 0 { vv_p("VIZSLA-VEN writer full -- fail loud\n" as *u8); return 1 } 372 } 373 if vv_eq(t0, "VENUE" as *u8) == 1 { 374 scanned = scanned + 1 375 p = vv_tok(b, p, e, f1, 128) 376 p = vv_tok(b, p, e, f2, 128) 377 p = vv_tok(b, p, e, f3, 128) 378 p = vv_tok(b, p, e, f4, 128) 379 p = vv_tok(b, p, e, f5, 128) 380 p = vv_tok(b, p, e, f6, 256) 381 if f1[0] == (0 as u8) { vv_p("VIZSLA-VEN VENUE missing event -- fail loud\n" as *u8); return 1 } 382 if f2[0] == (0 as u8) { vv_p("VIZSLA-VEN VENUE missing vid -- fail loud\n" as *u8); return 1 } 383 if vv_digits(f3) == 0 { vv_p("VIZSLA-VEN VENUE capacity not digits -- fail loud\n" as *u8); return 1 } 384 if vv_digits(f4) == 0 { vv_p("VIZSLA-VEN VENUE cost not digits -- fail loud\n" as *u8); return 1 } 385 if f5[0] == (0 as u8) { vv_p("VIZSLA-VEN VENUE missing contact -- fail loud\n" as *u8); return 1 } 386 if f6[0] == (0 as u8) { vv_p("VIZSLA-VEN VENUE missing name -- fail loud\n" as *u8); return 1 } 387 vvals[1] = f1 as i64 388 vvals[2] = f2 as i64 389 vvals[3] = f3 as i64 390 vvals[4] = f4 as i64 391 vvals[5] = f5 as i64 392 vvals[6] = f6 as i64 393 if vv_put(vkeys, vvals, 7, "ven:" as *u8, st) != 0 { vv_p("VIZSLA-VEN writer full -- fail loud\n" as *u8); return 1 } 394 } 395 if vv_eq(t0, "STAGE" as *u8) == 1 { 396 scanned = scanned + 1 397 p = vv_tok(b, p, e, f1, 128) 398 p = vv_tok(b, p, e, f2, 128) 399 p = vv_tok(b, p, e, f3, 128) 400 p = vv_tok(b, p, e, f4, 128) 401 if vv_datedays(f1) < 0 { vv_p("VIZSLA-VEN STAGE bad date -- fail loud\n" as *u8); return 1 } 402 if f2[0] == (0 as u8) { vv_p("VIZSLA-VEN STAGE missing event -- fail loud\n" as *u8); return 1 } 403 if f3[0] == (0 as u8) { vv_p("VIZSLA-VEN STAGE missing vid -- fail loud\n" as *u8); return 1 } 404 if vv_stage_ok(f4) == 0 { vv_p("VIZSLA-VEN STAGE not found|contacted|quoted|visited|booked|rejected -- fail loud\n" as *u8); return 1 } 405 svals[1] = f1 as i64 406 svals[2] = f2 as i64 407 svals[3] = f3 as i64 408 svals[4] = f4 as i64 409 if vv_put(skeys, svals, 5, "stg:" as *u8, st) != 0 { vv_p("VIZSLA-VEN writer full -- fail loud\n" as *u8); return 1 } 410 } 411 i = e + 1 412 } 413 414 var committed: i64 = 0 415 if st[3] > 0 { 416 if ss_commit(prefix, st[0] as *i64, segid) != 0 { vv_p("VIZSLA-VEN commit FAILED -- fail loud\n" as *u8); return 1 } 417 committed = 1 418 } 419 420 let rep: *u8 = sys_mmap(K_MAGIC_4096) 421 var o: i64 = 0 422 o = vv_cat(rep, o, "VIZSLA-VEN-LOAD scanned=" as *u8) 423 o = vv_catn(rep, o, scanned) 424 o = vv_cat(rep, o, " new=" as *u8) 425 o = vv_catn(rep, o, st[3]) 426 o = vv_cat(rep, o, " dup_infile=" as *u8) 427 o = vv_catn(rep, o, st[4]) 428 o = vv_cat(rep, o, " dup_instore=" as *u8) 429 o = vv_catn(rep, o, st[5]) 430 o = vv_cat(rep, o, " segment=" as *u8) 431 if committed == 1 { 432 o = vv_cat(rep, o, "seg-" as *u8) 433 o = vv_catn(rep, o, segid) 434 } else { 435 o = vv_cat(rep, o, "none" as *u8) 436 } 437 o = vv_cat(rep, o, "\n" as *u8) 438 sys_write(1, rep, o) 439 return 0 440} 441 442// ---------------- BOARD ---------------- 443func vv_cmd_board(argc: i64, argv: *i64) -> i64 { 444 if argc < 4 { vv_p("VIZSLA-VEN board needs <prefix> <event> -- fail loud\n" as *u8); return 1 } 445 let prefix: *u8 = argv[2] as *u8 446 let event: *u8 = argv[3] as *u8 447 448 var reqcap: i64 = 0 - 1 449 var reqbud: i64 = 0 - 1 450 let reqdate: *u8 = sys_mmap(128) 451 let reqstart: *u8 = sys_mmap(128) 452 let reqdur: *u8 = sys_mmap(128) 453 reqdate[0] = 0 as u8 454 455 let vn_id: *i64 = sys_mmap(8 * 64) as *i64 456 let vn_cap: *i64 = sys_mmap(8 * 64) as *i64 457 let vn_cost: *i64 = sys_mmap(8 * 64) as *i64 458 let vn_contact: *i64 = sys_mmap(8 * 64) as *i64 459 let vn_name: *i64 = sys_mmap(8 * 64) as *i64 460 let vn_stage: *i64 = sys_mmap(8 * 64) as *i64 461 let vn_sday: *i64 = sys_mmap(8 * 64) as *i64 462 var nv: i64 = 0 463 var nstg: i64 = 0 464 465 let segs: *i64 = sys_mmap(8 * 260) as *i64 466 let ns: i64 = ss_manifest(prefix, segs) 467 let fe: *u8 = sys_mmap(128) 468 let fa: *u8 = sys_mmap(256) 469 let fb: *u8 = sys_mmap(256) 470 let fc: *u8 = sys_mmap(256) 471 let fd2: *u8 = sys_mmap(256) 472 let fg: *u8 = sys_mmap(256) 473 var s: i64 = 0 474 while s < ns { 475 let path: *u8 = sys_mmap(512) 476 var po: i64 = 0 477 po = vv_cat(path, po, prefix) 478 po = vv_cat(path, po, segs[s] as *u8) 479 po = vv_cat(path, po, ".docs" as *u8) 480 path[po] = 0 as u8 481 let szp: *i64 = sys_mmap(16) as *i64 482 let b: *u8 = ss_readall(path, szp) 483 let sz: i64 = szp[0] 484 var j: i64 = 0 485 while j + 9 <= sz { 486 let kind: i64 = b[j] 487 let kl: i64 = ss_r32(b, j + 1) 488 let koff: i64 = j + 5 489 let vl: i64 = ss_r32(b, koff + kl) 490 let voff: i64 = koff + kl + 4 491 let rec: *u8 = (b as i64 + voff) as *u8 492 var isreq: i64 = 0 493 var isven: i64 = 0 494 var isstg: i64 = 0 495 if kind == 1 { isreq = vv_iskind(b, koff, kl, "req:" as *u8) } 496 if kind == 1 { isven = vv_iskind(b, koff, kl, "ven:" as *u8) } 497 if kind == 1 { isstg = vv_iskind(b, koff, kl, "stg:" as *u8) } 498 if isreq == 1 { 499 if vv_field(rec, vl, "event" as *u8, fe, 128) == 1 { if vv_eq(fe, event) == 1 { 500 vv_field(rec, vl, "capacity" as *u8, fa, 256) 501 vv_field(rec, vl, "budget" as *u8, fb, 256) 502 vv_field(rec, vl, "date" as *u8, reqdate, 128) 503 vv_field(rec, vl, "start" as *u8, reqstart, 128) 504 vv_field(rec, vl, "dur" as *u8, reqdur, 128) 505 reqcap = vv_atoi(fa) 506 reqbud = vv_atoi(fb) 507 } } 508 } 509 if isven == 1 { 510 if vv_field(rec, vl, "event" as *u8, fe, 128) == 1 { if vv_eq(fe, event) == 1 { 511 if nv < 64 { 512 vv_field(rec, vl, "vid" as *u8, fa, 256) 513 if vv_find(vn_id, nv, fa) < 0 { 514 vv_field(rec, vl, "capacity" as *u8, fb, 256) 515 vv_field(rec, vl, "cost" as *u8, fc, 256) 516 vv_field(rec, vl, "contact" as *u8, fd2, 256) 517 vv_field(rec, vl, "name" as *u8, fg, 256) 518 let d1: *u8 = vv_dup(fa) 519 let d2: *u8 = vv_dup(fd2) 520 let d3: *u8 = vv_dup(fg) 521 let d4: *u8 = vv_dup("found" as *u8) 522 vn_id[nv] = d1 as i64 523 vn_cap[nv] = vv_atoi(fb) 524 vn_cost[nv] = vv_atoi(fc) 525 vn_contact[nv] = d2 as i64 526 vn_name[nv] = d3 as i64 527 vn_stage[nv] = d4 as i64 528 vn_sday[nv] = 0 - 1 529 nv = nv + 1 530 } 531 } 532 } } 533 } 534 if isstg == 1 { 535 if vv_field(rec, vl, "event" as *u8, fe, 128) == 1 { if vv_eq(fe, event) == 1 { 536 vv_field(rec, vl, "vid" as *u8, fa, 256) 537 vv_field(rec, vl, "stage" as *u8, fb, 256) 538 vv_field(rec, vl, "date" as *u8, fc, 256) 539 let sd: i64 = vv_datedays(fc) 540 let hit: i64 = vv_find(vn_id, nv, fa) 541 nstg = nstg + 1 542 if hit >= 0 { 543 if sd >= vn_sday[hit] { 544 let dstg: *u8 = vv_dup(fb) 545 vn_stage[hit] = dstg as i64 546 vn_sday[hit] = sd 547 } 548 } 549 } } 550 } 551 j = voff + vl 552 } 553 s = s + 1 554 } 555 556 if reqcap < 0 { vv_p("VIZSLA-VEN board event has NO REQ -- fail loud\n" as *u8); return 1 } 557 if nv == 0 { vv_p("VIZSLA-VEN board event has NO venues -- fail loud\n" as *u8); return 1 } 558 559 // fit scores (cap_ok*50 + within_budget*30 + cheaper-bonus 0..20) 560 let scores: *i64 = sys_mmap(8 * 64) as *i64 561 let overb: *i64 = sys_mmap(8 * 64) as *i64 562 let small: *i64 = sys_mmap(8 * 64) as *i64 563 var i: i64 = 0 564 while i < nv { 565 var sc: i64 = 0 566 small[i] = 1 567 overb[i] = 1 568 if vn_cap[i] >= reqcap { sc = sc + 50; small[i] = 0 } 569 if vn_cost[i] <= reqbud { 570 overb[i] = 0 571 sc = sc + 30 572 sc = sc + ((reqbud - vn_cost[i]) * 20) / reqbud 573 } 574 scores[i] = sc 575 i = i + 1 576 } 577 578 // sort by score desc / cost asc / vid lex 579 let idxs: *i64 = sys_mmap(8 * 64) as *i64 580 i = 0 581 while i < nv { idxs[i] = i; i = i + 1 } 582 var a: i64 = 0 583 while a < nv { 584 var mn: i64 = a 585 var c: i64 = a + 1 586 while c < nv { 587 var better: i64 = 0 588 let ic: i64 = idxs[c] 589 let im: i64 = idxs[mn] 590 if scores[ic] > scores[im] { better = 1 } 591 if scores[ic] == scores[im] { 592 if vn_cost[ic] < vn_cost[im] { better = 1 } 593 if vn_cost[ic] == vn_cost[im] { 594 if vv_cmp(vn_id[ic] as *u8, vn_id[im] as *u8) < 0 { better = 1 } 595 } 596 } 597 if better == 1 { mn = c } 598 c = c + 1 599 } 600 if mn != a { let t1: i64 = idxs[a]; idxs[a] = idxs[mn]; idxs[mn] = t1 } 601 a = a + 1 602 } 603 604 let rep: *u8 = sys_mmap(K_MAGIC_65536) 605 var o: i64 = 0 606 var booked: i64 = 0 - 1 607 var best: i64 = 0 - 1 608 var vi: i64 = 0 609 while vi < nv { 610 let t: i64 = idxs[vi] 611 o = vv_cat(rep, o, "VIZSLA-VEN-CAND event=" as *u8) 612 o = vv_cat(rep, o, event) 613 o = vv_cat(rep, o, " id=" as *u8) 614 o = vv_cat(rep, o, vn_id[t] as *u8) 615 o = vv_cat(rep, o, " stage=" as *u8) 616 o = vv_cat(rep, o, vn_stage[t] as *u8) 617 o = vv_cat(rep, o, " cap=" as *u8) 618 o = vv_catn(rep, o, vn_cap[t]) 619 o = vv_cat(rep, o, " cost=" as *u8) 620 o = vv_catn(rep, o, vn_cost[t]) 621 o = vv_cat(rep, o, " score=" as *u8) 622 o = vv_catn(rep, o, scores[t]) 623 o = vv_cat(rep, o, " over_budget=" as *u8) 624 o = vv_catn(rep, o, overb[t]) 625 o = vv_cat(rep, o, " too_small=" as *u8) 626 o = vv_catn(rep, o, small[t]) 627 o = vv_cat(rep, o, " contact=" as *u8) 628 o = vv_cat(rep, o, vn_contact[t] as *u8) 629 o = vv_cat(rep, o, " name=" as *u8) 630 o = vv_cat(rep, o, vn_name[t] as *u8) 631 o = vv_cat(rep, o, "\n" as *u8) 632 if vv_eq(vn_stage[t] as *u8, "booked" as *u8) == 1 { if booked < 0 { booked = t } } 633 if vv_eq(vn_stage[t] as *u8, "rejected" as *u8) == 0 { if best < 0 { best = t } } 634 vi = vi + 1 635 } 636 637 if booked >= 0 { 638 o = vv_cat(rep, o, "VIZSLA-VEN-BOOKED event=" as *u8) 639 o = vv_cat(rep, o, event) 640 o = vv_cat(rep, o, " id=" as *u8) 641 o = vv_cat(rep, o, vn_id[booked] as *u8) 642 o = vv_cat(rep, o, " date=" as *u8) 643 o = vv_cat(rep, o, reqdate) 644 o = vv_cat(rep, o, "\n" as *u8) 645 // the calendar bridge: this line IS a valid nx_vizsla_calendar load row 646 o = vv_cat(rep, o, "VIZSLA-VEN-CAL-LINE EVENT venue-" as *u8) 647 o = vv_cat(rep, o, event) 648 o = vv_cat(rep, o, " " as *u8) 649 o = vv_cat(rep, o, reqdate) 650 o = vv_cat(rep, o, " " as *u8) 651 o = vv_cat(rep, o, reqstart) 652 o = vv_cat(rep, o, " " as *u8) 653 o = vv_cat(rep, o, reqdur) 654 o = vv_cat(rep, o, " " as *u8) 655 o = vv_cat(rep, o, vn_name[booked] as *u8) 656 o = vv_cat(rep, o, "\n" as *u8) 657 } 658 659 o = vv_cat(rep, o, "VIZSLA-VEN-VERDICT event=" as *u8) 660 o = vv_cat(rep, o, event) 661 o = vv_cat(rep, o, " venues=" as *u8) 662 o = vv_catn(rep, o, nv) 663 o = vv_cat(rep, o, " stages=" as *u8) 664 o = vv_catn(rep, o, nstg) 665 o = vv_cat(rep, o, " booked=" as *u8) 666 if booked >= 0 { o = vv_cat(rep, o, vn_id[booked] as *u8) } else { o = vv_cat(rep, o, "none" as *u8) } 667 o = vv_cat(rep, o, " best=" as *u8) 668 if best >= 0 { o = vv_cat(rep, o, vn_id[best] as *u8) } else { o = vv_cat(rep, o, "none" as *u8) } 669 o = vv_cat(rep, o, " score=" as *u8) 670 if best >= 0 { o = vv_catn(rep, o, scores[best]) } else { o = vv_catn(rep, o, 0 - 1) } 671 o = vv_cat(rep, o, "\n" as *u8) 672 sys_write(1, rep, o) 673 return 0 674} 675 676func main(argc: i64, argv: *i64) -> i64 { 677 if argc < 2 { vv_p("VIZSLA-VEN usage: load|board -- fail loud\n" as *u8); return 1 } 678 let cmd: *u8 = argv[1] as *u8 679 if vv_eq(cmd, "load" as *u8) == 1 { return vv_cmd_load(argc, argv) } 680 if vv_eq(cmd, "board" as *u8) == 1 { return vv_cmd_board(argc, argv) } 681 vv_p("VIZSLA-VEN unknown command (load|board) -- fail loud\n" as *u8) 682 return 1 683}