重新按英文命名,修改成相对路径

This commit is contained in:
lianjianwei2024
2026-10-11 10:52:01 +08:00
parent eea5d511dc
commit 9bb23ac13b
64 changed files with 913 additions and 1427 deletions

61
release/testdata/check_db_once.py vendored Normal file
View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
"""一次性核查:lmes / norm_res 在测试库里的真实行数(只读,不写任何东西)。"""
import glob
import sqlite3
import sys
sys.stdout.reconfigure(errors="replace")
h = glob.glob("D:/Pricing review*/\u9020\u4ef7\u5ba1\u6838/data/history-test.db")[0]
s = glob.glob("D:/Pricing review*/\u9020\u4ef7\u5ba1\u6838/data/session-test.db")[0]
print("history-test:", h)
print("session-test:", s)
hc = sqlite3.connect(h, timeout=10)
q = "FROM batches WHERE is_mock=1 AND Name LIKE '\u6d4b\u8bd5%'"
print("\n== batches(is_mock=1)==")
for k, in hc.execute("SELECT kind, COUNT(*) " + q + " GROUP BY kind"):
print(" %-8s %d" % (k, hc.execute("SELECT COUNT(*) " + q + " AND kind=?", (k,)).fetchone()[0]))
joins = {
"lmes(工料机主表)": "FROM lmes l JOIN batches bt ON bt.id=l.batch_id WHERE bt.is_mock=1 AND bt.Name LIKE '\u6d4b\u8bd5%'",
"norm_res(定额人材机)": "FROM norm_res r JOIN norms n ON n.id=r.norm_id JOIN bills b ON b.id=n.bill_id JOIN batches bt ON bt.id=b.batch_id WHERE bt.is_mock=1 AND bt.Name LIKE '\u6d4b\u8bd5%'",
"lme_attach(工料机绑定)": "FROM lme_attach a JOIN batches bt ON bt.id=a.batch_id WHERE bt.is_mock=1 AND bt.Name LIKE '\u6d4b\u8bd5%'",
"inquiry_files(询价附件)": "FROM inquiry_files f JOIN batches bt ON bt.id=f.batch_id WHERE bt.is_mock=1 AND bt.Name LIKE '\u6d4b\u8bd5%'",
"prices(价格明细)": "FROM prices p JOIN batches bt ON bt.id=p.batch_id WHERE bt.is_mock=1 AND bt.Name LIKE '\u6d4b\u8bd5%'",
"bills(清单)": "FROM bills b JOIN batches bt ON bt.id=b.batch_id WHERE bt.is_mock=1 AND bt.Name LIKE '\u6d4b\u8bd5%'",
"norms(定额)": "FROM norms n JOIN bills b ON b.id=n.bill_id JOIN batches bt ON bt.id=b.batch_id WHERE bt.is_mock=1 AND bt.Name LIKE '\u6d4b\u8bd5%'",
}
print("\n== history-test.db 真实行数 ==")
for name, sql in joins.items():
try:
n = hc.execute("SELECT COUNT(*) " + sql).fetchone()[0]
print(" %-22s %d" % (name, n))
except Exception as e:
print(" %-22s ERR: %s" % (name, e))
# 抽一个测试项目看 lmes / norm_res 是否真有内容
bid = hc.execute("SELECT id, Name FROM batches WHERE is_mock=1 AND kind='project' ORDER BY id DESC LIMIT 1").fetchone()
if bid:
print("\n== 抽样项目 id=%d %s ==" % bid)
print(" lmes 行数:", hc.execute("SELECT COUNT(*) FROM lmes WHERE batch_id=?", (bid[0],)).fetchone()[0])
print(" lme_attach 行数:", hc.execute("SELECT COUNT(*) FROM lme_attach WHERE batch_id=?", (bid[0],)).fetchone()[0])
row = hc.execute(
"SELECT COUNT(*) FROM norm_res r JOIN norms n ON n.id=r.norm_id "
"JOIN bills b ON b.id=n.bill_id WHERE b.batch_id=?", (bid[0],)).fetchone()
print(" norm_res 行数:", row[0])
hc.close()
sc = sqlite3.connect(s, timeout=10)
print("\n== session-test.db 真实行数 ==")
for name, sql in {
"sessions": "FROM sessions WHERE name LIKE '\u6d4b\u8bd5%'",
"s_lmes": "FROM s_lmes WHERE session_id IN (SELECT id FROM sessions WHERE name LIKE '\u6d4b\u8bd5%')",
"s_norm_res": "FROM s_norm_res WHERE session_id IN (SELECT id FROM sessions WHERE name LIKE '\u6d4b\u8bd5%')",
}.items():
try:
print(" %-10s %d" % (name, sc.execute("SELECT COUNT(*) " + sql).fetchone()[0]))
except Exception as e:
print(" %-10s ERR: %s" % (name, e))
sc.close()
print("\n核查完成(只读)")

View File

@@ -10,8 +10,8 @@ is_mock=1(批次库)双标记。删除走本文件的分块循环(每块 2
SQLite 变量上限(32766)会直接报错。
随母体变化目录:全部相对定位。从本文件位置逐级向上找
<某级>/造价审核/data/history.db (工作区或包内)
<某级>/PricingReview*/造价审核/data/history.db(绿色包改名也能找到)
<某级>/CostReview/data/history.db (工作区或包内)
<某级>/PricingReview*/CostReview/data/history.db(绿色包改名也能找到)
找到即随包整体挪走照常用;界面里也可手动指定数据目录(存 config.json)。
命令行:
@@ -115,10 +115,10 @@ def find_data_dir():
pass
d = HERE
for _ in range(8):
cand = os.path.join(d, "造价审核", "data")
cand = os.path.join(d, "CostReview", "data")
if _has_anchor(cand):
return cand
pat = os.path.join(d, "PricingReview*", "造价审核", "data")
pat = os.path.join(d, "PricingReview*", "CostReview", "data")
for g in glob.glob(pat):
if _has_anchor(g):
return g
@@ -584,6 +584,30 @@ def _open_ro(path, timeout=3):
except Exception:
return None
_CKPT_N = [0] # 跨生成阶段的调用计数
def _ckpt(con, every=10):
"""生成中定期 PASSIVE checkpoint:面板统计等读者会挡住 auto-checkpoint,
WAL 会无限膨胀(实测 1000 项目攒出 6.7GB,后续生成恢复时被锁死)。
每 every 次调用做一次,失败静默(checkpoint 只是保健,不值得中断生成)。"""
_CKPT_N[0] += 1
if _CKPT_N[0] % every:
return
try:
con.execute("PRAGMA wal_checkpoint(PASSIVE)")
except Exception:
pass
def _merge(st, add):
"""统计累加:分块/多阶段各自返回新字典,st.update 会覆盖(只留最后一块),
汇总数字必然失真——必须逐键相加。"""
for k, v in add.items():
st[k] = st.get(k, 0) + v
return st
# ---------------- 结构级插入(history 与 session 两库共用一份逻辑数据) ----------------
# 逻辑行里的 owner 索引是本地序号,插入时映射为真实 id。
@@ -964,6 +988,7 @@ def gen_projects(hc, sc, dd, cfg, rng, words, log, start=0):
# uploads 源文件占位(联动/重新解析不缺文件)
write_file_rel(dd, "uploads", sha_src, "%s.cos4" % name)
hc.commit()
_ckpt(hc)
stats["project"] += 1
stats["bills"] += len(data["bills"])
stats["norms"] += sum(len(x) for x in data["norms"])
@@ -1021,9 +1046,12 @@ def gen_sessions_standalone(sc, cfg, rng, words, log):
sid = scur.lastrowid
insert_tree(sc, SQL_S, sid, data, ym=None)
sc.commit()
_ckpt(sc)
stats["sessions"] += 1
stats["bills"] += len(data["bills"])
stats["norms"] += sum(len(x) for x in data["norms"])
stats["res"] += sum(len(n2[6]) for x in data["norms"] for n2 in x)
stats["lmes"] += len(data["lmes"])
log(" [%d/%d] %s:清单 %d(独立会话)" % (i + 1, n, name, len(data["bills"])))
return stats
@@ -1104,6 +1132,7 @@ def gen_prices(hc, dd, cfg, rng, words, log):
cur.execute("UPDATE batches SET x_attach_sha=? WHERE id=?", (sha, bid))
stats["price_attach"] += 1
hc.commit()
_ckpt(hc)
stats[kind] += 1
stats["price_rows"] += n_rows
log(" %s:%d 份完成(每份 %d~%d 条,附件率 %d%%)" % (prefix, cnt, lo, hi, rate))
@@ -1474,17 +1503,24 @@ def run(cfg, log=print):
while off < total:
piece = dict(cfg); piece["n_project"] = min(chunk, total - off)
log(" —— 分批推进:第 %d~%d / %d 份 ——" % (off + 1, off + piece["n_project"], total))
st.update(gen_projects(hc, sc, dd, piece, rng, words, log, start=off))
_merge(st, gen_projects(hc, sc, dd, piece, rng, words, log, start=off))
off += piece["n_project"]
else:
st.update(gen_projects(hc, sc, dd, cfg, rng, words, log))
_merge(st, gen_projects(hc, sc, dd, cfg, rng, words, log))
if int(cfg.get("n_market", 0)) or int(cfg.get("n_info", 0)):
log("== 市场价/信息价 ==")
st.update(gen_prices(hc, dd, cfg, rng, words, log))
_merge(st, gen_prices(hc, dd, cfg, rng, words, log))
if sc is not None and not cfg.get("session_linked") and int(cfg.get("n_session", 0)) > 0:
log("== 独立工作台会话(%d 份,清单 %d~%d/份)==" % (
cfg["n_session"], cfg.get("sbill_lo", 150), cfg.get("sbill_hi", 400)))
st.update(gen_sessions_standalone(sc, cfg, rng, words, log))
_merge(st, gen_sessions_standalone(sc, cfg, rng, words, log))
# 收尾 checkpoint:全部读连接断开时把 WAL 收干净,不留巨型 WAL 给下次恢复
for c in (hc, sc):
if c is not None:
try:
c.execute("PRAGMA wal_checkpoint(TRUNCATE)")
except Exception:
pass
hc.close()
if sc is not None:
sc.close()

25
release/testdata/probe_db.py vendored Normal file
View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""最小探针:定位哪个库、哪种打开方式能读。只读 SELECT。"""
import glob
import sqlite3
import sys
sys.stdout.reconfigure(errors="replace")
base = glob.glob("D:/Pricing review*/\u9020\u4ef7\u5ba1\u6838/data")[0]
targets = {
"history.db(真实)": base + "/history.db",
"history-test.db": base + "/history-test.db",
"session.db(真实)": base + "/session.db",
"session-test.db": base + "/session-test.db",
}
for name, p in targets.items():
for mode, uri in (("普通", False), ("ro", True)):
try:
con = sqlite3.connect(p if not uri else "file:" + p.replace("\\", "/") + "?mode=ro", uri=uri, timeout=5)
n = con.execute("SELECT COUNT(*) FROM sqlite_master").fetchone()[0]
con.close()
print("%-18s %-4s OK, sqlite_master=%d" % (name, mode, n))
break
except Exception as e:
print("%-18s %-4s FAIL: %s" % (name, mode, e))

View File

@@ -22,7 +22,7 @@
"sbill_hi": 400,
"from_ym": "2024-01",
"to_ym": "2026-10",
"data_dir": "D:\\Pricing review‌\\造价审核\\data",
"ref_dir": "D:\\Pricing review‌\\造价审核\\data",
"data_dir": "D:\\PricingReview\\CostReview\\data",
"ref_dir": "D:\\PricingReview\\CostReview\\data",
"chunk": 100
}

View File

@@ -1,27 +1,27 @@
{
"n_project": 1000,
"bill_lo": 300,
"n_project": 10000,
"bill_lo": 600,
"bill_hi": 800,
"norm_lo": 3,
"norm_hi": 5,
"res_lo": 3,
"res_hi": 5,
"inq_per_project": 40,
"bind_rate": 70,
"n_market": 20,
"inq_per_project": 35,
"bind_rate": 50,
"n_market": 20000,
"market_lo": 500,
"market_hi": 800,
"market_attach_rate": 80,
"n_info": 20,
"n_info": 20000,
"info_lo": 500,
"info_hi": 800,
"info_attach_rate": 90,
"session_linked": false,
"n_session": 500,
"sbill_lo": 150,
"sbill_hi": 400,
"from_ym": "2024-01",
"n_session": 10000,
"sbill_lo": 800,
"sbill_hi": 1500,
"from_ym": "2018-01",
"to_ym": "2026-10",
"data_dir": "D:\\Pricing review‌\\造价审核\\data",
"ref_dir": "D:\\Pricing review‌\\造价审核\\data"
"data_dir": "D:\\PricingReview\\CostReview\\data",
"ref_dir": "D:\\PricingReview\\CostReview\\data"
}