feat: 新增 AdminCost 造价标准管理模块并调整手工导出未采纳清单口径

This commit is contained in:
lianjianwei2024
2026-10-29 15:54:38 +08:00
parent a90734963c
commit b79c0df557
25 changed files with 27360 additions and 58 deletions

View File

@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
"""规范(2018)第6章 vs 两份 COS4 —— 最终对比汇总"""
import json, re, os
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SPEC = json.load(open(os.path.join(BASE, "DBJT15-145-2018_第6章_属性表.json"), encoding="utf-8"))
COS = json.load(open(os.path.join(BASE, "两份COS4_结构.json"), encoding="utf-8"))
FIX = {"其他项目费明细": "SundryCostsItem"}
def norm(s):
return re.sub(r"\s+", "", s)
spec_el, spec_tbl = {}, {}
for t in SPEC:
el = norm(FIX.get(norm(t["element"]), norm(t["element"])))
props = {norm(r[1]) for r in t["rows"][1:] if len(r) >= 2 and r[1] and r[1] != "属性名称"}
if not el:
continue
spec_el.setdefault(el, set()).update(props)
spec_tbl.setdefault(el, []).append(t["no"])
CONTAINERS = {"ConstructionInfo", "ConstructionSummary", "UnitWorks", "UnitWorksSummary",
"DivisionalAndElementalWorks", "Preliminaries", "Sundry", "AttrInfo", "AddiInfo",
"ProvisionalMaterialEquipment"}
print("规范(2018)第6章:属性表 %d 张,元素 %d 个,属性定义 %d 条\n" % (len(SPEC), len(spec_el), sum(len(v) for v in spec_el.values())))
cos_els = {}
for fname, ent in COS.items():
els = {}
for scope in ("attrs", "unit_attrs"):
for el, props in ent.get(scope, {}).items():
els.setdefault(norm(el), set()).update(props.keys())
cos_els[fname] = els
for fname, els in cos_els.items():
extra = {e: p for e, p in els.items() if e not in spec_el}
priv = {e: p for e, p in extra.items() if e not in CONTAINERS}
cont = {e: p for e, p in extra.items() if e in CONTAINERS}
print("=" * 72)
print(fname)
print(" 有属性元素 %d|规范内 %d|规范有属性表但COS4缺 %d|容器元素(规范无属性表) %d|★规范外 %d"
% (len(els), len(set(els) & set(spec_el)), len(set(spec_el) - set(els)), len(cont), len(priv)))
print(" ★规范第6章完全没有的元素:")
for e in sorted(priv):
print(" - %-44s %d 个属性:%s" % (e, len(priv[e]), ",".join(sorted(priv[e]))[:120]))
print(" 容器元素(规范有该元素、无属性表):%s" % ",".join(sorted(cont)))
# 属性名差异
diffs = []
for e in sorted(set(spec_el) & set(els)):
miss, add = spec_el[e] - els[e], els[e] - spec_el[e]
if miss or add:
diffs.append((e, sorted(miss), sorted(add)))
print(" 属性名有差异的元素 %d 个:" % len(diffs))
for e, m, a in diffs:
print(" %-42s 缺:%s 多:%s" % (e, ",".join(m) or "-", ",".join(a) or "-"))
print()
# 两家 COS4 互比
a, b = list(cos_els.items())
print("=" * 72)
print("两份 COS4 相互差异")
na, nb = set(a[1]), set(b[1])
print(" 共有元素 %d 个" % len(na & nb))
print(" 仅易达有:%s" % ",".join(sorted(na - nb)))
print(" 仅广联达有:%s" % ",".join(sorted(nb - na)))

View File

@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
"""解析两份 COS4:元素树 + 每元素属性集合 + 出现次数"""
import zipfile, json, os, re
import xml.etree.ElementTree as ET
from collections import defaultdict, OrderedDict
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
FILES = [
r"C:\Users\MZ\Desktop\1易达导出骨架.cos4",
r"C:\Users\MZ\Desktop\广联达导出最新架子.COS4",
]
OUT = os.path.join(BASE, "两份COS4_结构.json")
def decode_name(n):
try:
return n.encode("cp437").decode("gbk")
except Exception:
return n
def parse_xml(data):
"""返回 (元素->属性次数, 元素->子元素集合, 元素->出现次数)"""
root = ET.fromstring(data)
attrs = defaultdict(lambda: defaultdict(int))
children = defaultdict(set)
count = defaultdict(int)
def walk(e, parent=None):
tag = e.tag.split("}")[-1]
count[tag] += 1
if parent:
children[parent].add(tag)
for k, v in e.attrib.items():
attrs[tag][k.split("}")[-1]] += 1
for c in list(e):
walk(c, tag)
walk(root)
return root.tag, attrs, children, count
summary = {}
for f in FILES:
key = os.path.basename(f)
z = zipfile.ZipFile(f)
names = [(n, decode_name(n)) for n in z.namelist()]
proj = [n for n, d in names if d.lower().endswith("project.xml")]
units = [(n, d) for n, d in names if not d.lower().endswith("project.xml") and d.lower().endswith(".xml")]
ent = {"file": f, "project_xml": proj, "unit_count": len(units)}
if proj:
data = z.read(proj[0])
root, attrs, children, count = parse_xml(data)
ent["root"] = root
ent["attrs"] = {k: dict(v) for k, v in attrs.items()}
ent["children"] = {k: sorted(v) for k, v in children.items()}
ent["count"] = dict(count)
# 单位工程:取一个最大的作为样本 + 汇总所有
u_attrs = defaultdict(lambda: defaultdict(int))
u_children = defaultdict(set)
u_count = defaultdict(int)
roots = set()
for n, d in units:
try:
r, a, c, cnt = parse_xml(z.read(n))
except Exception as e:
continue
roots.add(r)
for k, v in a.items():
for ak, ac in v.items():
u_attrs[k][ak] = max(u_attrs[k][ak], ac)
for k, v in c.items():
u_children[k] |= v
for k, v in cnt.items():
u_count[k] += v
ent["unit_roots"] = sorted(roots)
ent["unit_attrs"] = {k: dict(v) for k, v in u_attrs.items()}
ent["unit_children"] = {k: sorted(v) for k, v in u_children.items()}
ent["unit_count"] = dict(u_count)
summary[key] = ent
json.dump(summary, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
for k, e in summary.items():
print("=" * 70)
print(k, "root:", e.get("root"), "units:", e.get("unit_count"), e.get("unit_roots"))
print(" 项目文件元素数:", len(e.get("attrs", {})), " 单位工程元素数:", len(e.get("unit_attrs", {})))
print(" 项目属性总数:", sum(len(v) for v in e.get("attrs", {}).values()))
print(" 单位工程属性总数:", sum(len(v) for v in e.get("unit_attrs", {}).values()))
print(" 项目元素:", sorted(e.get("count", {}).keys()))
print("->", OUT)

View File

@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
"""规范第 6 章属性表解析(v3:去反斜杠 + 合并 strong)"""
import re, json, html, os
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MD = os.path.join(BASE, "DBJT15-145-2018_全文含表格.md")
OUT = os.path.join(BASE, "DBJT15-145-2018_第6章_属性表.json")
lines = open(MD, encoding="utf-8").read().split("\n")
text = "\n".join(lines[5707:18611])
t2 = text.replace("\\", "")
t2 = re.sub(r"</strong>\s*<strong>", "", t2)
t2 = re.sub(r"<strong>|</strong>", "", t2)
def strip_tags(s):
s = re.sub(r"<img[^>]*>", "", s)
s = re.sub(r"<br\s*/?>", " ", s)
s = re.sub(r"<[^>]+>", "", s)
s = s.replace("&nbsp;", " ")
return html.unescape(s).strip()
heads = []
for m in re.finditer(r"表\s*6\s*\.\s*(\d+)\s*\.\s*(\d+)\s*-?\s*(\d*)\s*([^<>\n]{0,60}?)属性定义表", t2):
no = f"6.{m.group(1)}.{m.group(2)}" + (f"-{m.group(3)}" if m.group(3) else "")
heads.append((m.start(), no, m.group(4).strip()))
result = []
for i, (pos, no, name) in enumerate(heads):
nxt = heads[i + 1][0] if i + 1 < len(heads) else len(t2)
chunk = t2[pos:nxt]
tbl = re.search(r"<table>(.*?)</table>", chunk, re.S)
rows = []
if tbl:
for r in re.findall(r"<tr>(.*?)</tr>", tbl.group(1), re.S):
cells = re.findall(r"<td[^>]*>(.*?)</td>", r, re.S)
vals = [strip_tags(c) for c in cells]
if vals:
rows.append(vals)
result.append({"no": no, "element": name.strip(), "rows": rows})
json.dump(result, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)
print("tables:", len(result))
tot = 0
nos = []
for t in result:
props = [r[1] for r in t["rows"][1:] if len(r) >= 2 and r[1] and r[1] != "属性名称"]
tot += len(props)
nos.append(t["no"])
print(f"{t['no']:10s} {t['element'][:40]:42s} props={len(props)}")
print("total prop defs:", tot)
missing = []
print("表号序列:", nos)