From a3697ba27148a890bccb22e1b2392838702ec27e Mon Sep 17 00:00:00 2001 From: lianjianwei2024 <168657369+lianjianwei2024@users.noreply.github.com> Date: Sat, 10 Oct 2026 11:19:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(testdata):=20=E9=9D=A2=E6=9D=BF=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E3=80=8C=E6=95=B0=E6=8D=AE=E5=BA=93=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E6=80=BB=E8=A7=88=E3=80=8D=E2=80=94=E2=80=94=E6=89=93=E5=BC=80?= =?UTF-8?q?=E5=8D=B3=E8=87=AA=E5=8A=A8=E6=B8=85=E7=82=B9=E5=8F=82=E8=80=83?= =?UTF-8?q?=E5=BA=93/=E6=B5=8B=E8=AF=95=E5=BA=93=E5=85=A8=E9=87=8F?= =?UTF-8?q?=E5=AE=B6=E5=BA=95=EF=BC=88=E6=89=B9=E6=AC=A1/=E6=B8=85?= =?UTF-8?q?=E5=8D=95/=E5=AE=9A=E9=A2=9D/=E5=B7=A5=E6=96=99=E6=9C=BA/?= =?UTF-8?q?=E9=99=84=E4=BB=B6/=E4=BC=9A=E8=AF=9D=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E8=AF=BB=E8=BF=9E=E6=8E=A5=EF=BC=8C=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=89=8D=E5=90=8E=E5=8F=AF=E5=AF=B9=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release/testdata/gen_testdata.py | 42 ++++++++++++++++++++++++++++++++ release/testdata/panel_server.py | 32 +++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/release/testdata/gen_testdata.py b/release/testdata/gen_testdata.py index 7f4d7e3..c456b97 100644 --- a/release/testdata/gen_testdata.py +++ b/release/testdata/gen_testdata.py @@ -1233,6 +1233,48 @@ def stats_of(dd): sc.close() return out +# ---------------- 数据库资产总览(两库全量家底,打开面板即看) ---------------- + +def totals_of(dd): + """参考库与测试库的全量资产计数(不区分 mock,只数行数)。 + 缺文件的库返回 None。全部走只读连接,不碰写入。""" + rh, th, rs, ts = db_paths(dd) + + def h_totals(p): + if not os.path.exists(p): + return None + c = sqlite3.connect("file:%s?mode=ro" % p.replace("\\", "/"), uri=True, + timeout=15) + c.execute("PRAGMA busy_timeout=15000") + out = {} + for t in ("batches", "bills", "norms", "norm_res", "lmes", "lme_lib", + "prices", "attachments"): + try: + out[t] = c.execute("SELECT COUNT(*) FROM %s" % t).fetchone()[0] + except Exception: + out[t] = -1 + c.close() + return out + + def s_totals(p): + if not os.path.exists(p): + return None + c = sqlite3.connect("file:%s?mode=ro" % p.replace("\\", "/"), uri=True, + timeout=15) + c.execute("PRAGMA busy_timeout=15000") + out = {} + for t in ("sessions", "s_bills", "s_norms", "s_lmes"): + try: + out[t] = c.execute("SELECT COUNT(*) FROM %s" % t).fetchone()[0] + except Exception: + out[t] = -1 + c.close() + return out + + return {"ref_h": h_totals(rh), "ref_s": s_totals(rs), + "test_h": h_totals(th), "test_s": s_totals(ts)} + + # ---------------- 分块删除 ---------------- def delete_testdata(dd, keep_files=False, log=print): diff --git a/release/testdata/panel_server.py b/release/testdata/panel_server.py index 7c8c52d..41c5777 100644 --- a/release/testdata/panel_server.py +++ b/release/testdata/panel_server.py @@ -131,6 +131,11 @@ class H(BaseHTTPRequestHandler): s["ref_ok"] = [os.path.exists(rh), os.path.exists(rs)] s["test_ok"] = [os.path.exists(th), os.path.exists(ts)] s["running"] = running() + if dd and "error" not in s: + try: + s["totals"] = G.totals_of(dd) + except Exception as te_: + s["totals_err"] = str(te_) s["mode"] = _state["mode"] if running() else None self._send(200, s) elif self.path == "/api/log": @@ -246,6 +251,12 @@ height:300px;overflow-y:auto;padding:12px;border-radius:6px;white-space:pre-wrap padding:2px 0;font-size:12px;color:#fff;flex:none} .dblab.ref{background:#646a73}.dblab.test{background:var(--pri)} .dbin{flex:1;min-width:260px} +table.assets{border-collapse:collapse;width:100%;font-size:12px} +table.assets th,table.assets td{border:1px solid var(--line,#d5d9e0); +padding:3px 8px;text-align:right} +table.assets th:first-child,table.assets td:first-child{text-align:left} +table.assets th{background:#f2f4f7;font-weight:600} +table.assets .grp td{background:#fafbfc;font-weight:600;text-align:left} .dbname{font:12px Consolas,monospace} .badge{font-size:12px;padding:1px 8px;border-radius:10px;flex:none} .badge.ok{color:var(--ok);background:#eaf6e8} @@ -321,6 +332,11 @@ history-test.db / session-test.db(首次自动从真实库克隆底子), +

数据库资产总览(全量,含非测试数据)

+
+
打开面板即自动清点;生成前后各看一眼即可对账。 +参考库 = history.db / session.db;测试库 = history-test.db / session-test.db。
+

操作

@@ -384,7 +400,21 @@ async function loadStats(){const s=await(await fetch("/api/stats")).json(); h+=kpi("询价附件",s.inquiry_files??0);h+=kpi("绑定",s.lme_attach??0); h+=kpi("价格原件批次",s.price_attach_batches??0); h+=kpi("工作台会话",s.s_sessions??0); - document.getElementById("kpis").innerHTML=h;} + document.getElementById("kpis").innerHTML=h; + renderAssets(s.totals);} +function renderAssets(t){ + const el=document.getElementById("assets"); + if(!t){el.innerHTML='暂无数据(数据目录未就绪)';return;} + const HH=[["batches","批次"],["bills","清单"],["norms","定额"],["norm_res","定额消耗"], + ["lmes","工料机"],["lme_lib","价格库"],["prices","价格明细"],["attachments","附件"]]; + const SS=[["sessions","会话"],["s_bills","清单"],["s_norms","定额"],["s_lmes","工料机"]]; + const fmt=v=>v==null?"缺文件":(v<0?"-":v.toLocaleString()); + let h='指标参考库 history测试库 history-test参考库 session测试库 session-test'; + HH.forEach(([k,n])=>{h+=''+n+''+fmt((t.ref_h||{})[k]) + +''+fmt((t.test_h||{})[k])+'——';}); + SS.forEach(([k,n])=>{h+=''+n+'——'+fmt((t.ref_s||{})[k]) + +''+fmt((t.test_s||{})[k])+'';}); + el.innerHTML=h;} let last=0; async function poll(){const r=await(await fetch("/api/log")).json(); if(r.lines.length!==last){const el=document.getElementById("log");