import assert from "node:assert/strict" import { readFileSync } from "node:fs" const SRC = "../../../../../src/modules/cockpit/" const { toPipeNetwork, filterPipeNetwork, pipeDistrictOf, PIPE_DISTRICT_PREFIX } = await import(SRC + "domain/pipeNetwork.js") // ---- 1) 真实载荷:前缀与名称(独立信号)逐条对照 const raw = JSON.parse(readFileSync(new URL("./geom-none.json", import.meta.url), "utf8")) const network = toPipeNetwork(raw.data) const all = [...network.pipes, ...network.components] console.log("pipes:", network.pipes.length, "components:", network.components.length, "blocked:", network.blocked.length) let checked = 0 const mismatch = [] for (const item of all) { const word = { 0: "城南", 1: "城北", 2: "太常" }[item.district] if (!word) continue checked += 1 if (!String(item.name).includes(word)) mismatch.push(item.code + "/" + item.name + "/" + word) } console.log("derived district checked:", checked, "mismatch:", mismatch.length, mismatch.slice(0, 3)) assert.equal(mismatch.length, 0, "编码前缀推出的片区与名称里的片区词不一致") const unresolved = all.filter((r) => r.district === null).map((r) => r.code) console.log("unresolved codes:", unresolved) // ---- 2) 过滤语义 const south = filterPipeNetwork(network, { scope: "south" }) const north = filterPipeNetwork(network, { scope: "north" }) const taichang = filterPipeNetwork(network, { scope: "taichang" }) const unassigned = filterPipeNetwork(network, { scope: "unassigned" }) const everywhere = filterPipeNetwork(network, { scope: "all" }) console.log("south pipes:", south.pipes.length, "taichang pipes:", taichang.pipes.length, "north pipes:", north.pipes.length) console.log("districtApplied:", { south: south.districtApplied, all: everywhere.districtApplied }) console.log("unresolvedCount south:", south.districtUnresolvedCount, "unassigned objects:", unassigned.pipes.length + unassigned.components.length) assert.equal(south.districtApplied, true) assert.equal(everywhere.districtApplied, false) assert.equal(south.pipes.length + taichang.pipes.length, network.pipes.length - 0 + 0 + (network.pipes.filter(p => p.district === null).length)) assert.equal(north.pipes.length, 0, "现网编码里没有城北前缀") assert.equal(unassigned.pipes.length + unassigned.components.length, unresolved.length) // ---- 3) 行业 × 片区 正交 const gasTc = filterPipeNetwork(network, { industry: "gas", scope: "taichang" }) const onlyGas = filterPipeNetwork(network, { industry: "gas", scope: "all" }) const onlyTc = filterPipeNetwork(network, { scope: "taichang" }) console.log("gas:", onlyGas.pipes.length + onlyGas.components.length, "taichang:", onlyTc.pipes.length + onlyTc.components.length, "gas∩taichang:", gasTc.pipes.length + gasTc.components.length) assert.ok(gasTc.pipes.every((p) => p.industry === "GAS" && p.district === 2)) console.log("SELFTEST PASS")