feat(match): 工料机过滤统一到 lme_list_where 并用于检索口径
- 将「项目工料机」过滤规则唯一实现挪到 match.lme_list_where(),支持列前缀参数,工作台与后台统一引用 - 工料机检索(hist_search_lme 工程分支)同用该过滤,修复检索能搜出已被屏蔽单位(如台班)的问题 - 测试数据生成器支持独立参考库目录(REF_DIR),面板展示参考/测试库文件与存在状态 - 清理遗留的审查报告汇总与旧界面.html
This commit is contained in:
72
release/testdata/gen_testdata.py
vendored
72
release/testdata/gen_testdata.py
vendored
@@ -68,10 +68,15 @@ def _has_anchor(d):
|
||||
or os.path.exists(os.path.join(d, TEST_H)))
|
||||
|
||||
|
||||
REF_DIR = None # 参考库目录(None = 与数据目录同目录)
|
||||
|
||||
|
||||
def db_paths(dd):
|
||||
"""返回 (真实history, 测试history, 真实session, 测试session) 四个绝对路径。"""
|
||||
return (os.path.join(dd, REAL_H), os.path.join(dd, TEST_H),
|
||||
os.path.join(dd, "session.db"), os.path.join(dd, TEST_S))
|
||||
"""返回 (真实history, 测试history, 真实session, 测试session) 四个绝对路径。
|
||||
参考库可在独立目录(REF_DIR);测试库与附件一律落在数据目录 dd。"""
|
||||
rd = REF_DIR or dd
|
||||
return (os.path.join(rd, REAL_H), os.path.join(dd, TEST_H),
|
||||
os.path.join(rd, "session.db"), os.path.join(dd, TEST_S))
|
||||
|
||||
|
||||
def ensure_test_dbs(dd, log=print):
|
||||
@@ -80,7 +85,9 @@ def ensure_test_dbs(dd, log=print):
|
||||
rh, th, rs, ts = db_paths(dd)
|
||||
if not os.path.exists(th):
|
||||
if not os.path.exists(rh):
|
||||
raise SystemExit("!! 数据目录里既没有 history.db 也没有 history-test.db,无法建测试库")
|
||||
raise SystemExit("!! 参考目录里没有 %s(参考目录:%s),无法建测试库"
|
||||
% (REAL_H, _disp(os.path.dirname(rh) or dd)))
|
||||
os.makedirs(dd, exist_ok=True) # 测试库独立目录可能还不存在
|
||||
s = sqlite3.connect(rh)
|
||||
d = sqlite3.connect(th)
|
||||
s.backup(d)
|
||||
@@ -102,7 +109,7 @@ def find_data_dir():
|
||||
try:
|
||||
with open(CFG_PATH, encoding="utf-8") as f:
|
||||
p = (json.load(f) or {}).get("data_dir") or ""
|
||||
if p and os.path.exists(os.path.join(p, "history.db")):
|
||||
if p and _has_anchor(p):
|
||||
return os.path.normpath(p)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -122,9 +129,21 @@ def find_data_dir():
|
||||
return None
|
||||
|
||||
|
||||
def set_data_dir(p):
|
||||
with open(CFG_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump({"data_dir": p}, f, ensure_ascii=False, indent=2)
|
||||
def set_data_dir(p, ref_dir=None):
|
||||
cfg = {}
|
||||
if os.path.exists(CFG_PATH):
|
||||
try:
|
||||
with open(CFG_PATH, encoding="utf-8") as f:
|
||||
cfg = json.load(f) or {}
|
||||
except Exception:
|
||||
cfg = {}
|
||||
cfg["data_dir"] = p
|
||||
if ref_dir is not None:
|
||||
cfg["ref_dir"] = ref_dir
|
||||
tmp = CFG_PATH + ".tmp"
|
||||
with open(tmp, "w", encoding="utf-8") as f:
|
||||
json.dump(cfg, f, ensure_ascii=False, indent=2)
|
||||
os.replace(tmp, CFG_PATH)
|
||||
|
||||
# ---------------- 归一化 / 哈希(复刻 core/import_job.py 口径) ----------------
|
||||
|
||||
@@ -521,18 +540,26 @@ def _parser_vers(dd):
|
||||
"""从母体 app 源码读当前解析器版本(工程/价格两条线)。
|
||||
stale_batches() 按 kind 分开比,生成器必须同样分开盖版本号,否则全部误报过期。"""
|
||||
proj, price = PARSER_VER_FALLBACK, PARSER_VER_PRICE_FALLBACK
|
||||
core = os.path.join(os.path.dirname(dd), "app", "core")
|
||||
for fname, defv in (("import_job.py", "proj"), ("price_html.py", "price")):
|
||||
try:
|
||||
txt = open(os.path.join(core, fname), encoding="utf-8").read()
|
||||
m = re.search(r"PARSER_VER\s*=\s*['\"]([^'\"]+)", txt)
|
||||
if m:
|
||||
if defv == "proj":
|
||||
proj = m.group(1)
|
||||
else:
|
||||
price = m.group(1)
|
||||
except Exception:
|
||||
pass
|
||||
bases = [os.path.dirname(dd)]
|
||||
if REF_DIR:
|
||||
rb = os.path.dirname(REF_DIR)
|
||||
if rb not in bases:
|
||||
bases.append(rb) # 测试库在自定义目录时,参考库旁才是母体
|
||||
for base in bases:
|
||||
core = os.path.join(base, "app", "core")
|
||||
for fname, defv in (("import_job.py", "proj"), ("price_html.py", "price")):
|
||||
try:
|
||||
txt = open(os.path.join(core, fname), encoding="utf-8").read()
|
||||
m = re.search(r"PARSER_VER\s*=\s*['\"]([^'\"]+)", txt)
|
||||
if m:
|
||||
if defv == "proj":
|
||||
proj = m.group(1)
|
||||
else:
|
||||
price = m.group(1)
|
||||
except Exception:
|
||||
pass
|
||||
if proj != PARSER_VER_FALLBACK and price != PARSER_VER_PRICE_FALLBACK:
|
||||
break
|
||||
return proj, price
|
||||
|
||||
|
||||
@@ -1267,6 +1294,8 @@ def delete_testdata(dd, keep_files=False, log=print):
|
||||
# ---------------- 编排入口 ----------------
|
||||
|
||||
def run(cfg, log=print):
|
||||
global REF_DIR
|
||||
REF_DIR = (cfg.get("ref_dir") or "").strip() or None
|
||||
dd = cfg.get("data_dir") or find_data_dir()
|
||||
if not dd:
|
||||
log("!! 找不到数据目录(history.db)。请在控制台里手动指定数据目录。")
|
||||
@@ -1276,7 +1305,8 @@ def run(cfg, log=print):
|
||||
sc = _open_db(ts) if os.path.exists(ts) else None
|
||||
rng = random.Random() # 每次运行真随机(不固定种子)
|
||||
words = Words(hc)
|
||||
log("数据目录:%s" % _disp(dd))
|
||||
log("参考库目录:%s" % _disp(os.path.dirname(db_paths(dd)[0])))
|
||||
log("测试库目录:%s" % _disp(dd))
|
||||
log("词料:项目名 %d / 定额 %d / 工料机 %d / 建设单位 %d" % (
|
||||
len(words.stems), len(words.norms), len(words.lmes), len(words.builders)))
|
||||
t0 = time.time()
|
||||
|
||||
Reference in New Issue
Block a user