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");