docs/¹¤¾ß/»ã×Ü´ó±í²îÒì±È¶Ô.py
@@ -109,6 +109,19 @@
"""
def main(gen, dgf, prefix):
    ACTION = ("实质数值差异", "错误值(程序)", "错误值(手工)", "文本不同")
    IGNORE = ("已忽略(单边有值)", "已忽略(结构/设计)", "取整尾差(可忽略)", "文本型数字(可忽略)",
              "已知设计(母版新增行)", "已知设计(无表头草稿列)", "已知设计(排名表当月/累计块)", "其它")
    cats = list(ACTION) + list(IGNORE)
    REASON = {(" è´§è¿", "EA"): "2022年各市州累计同比:业务已确认软件口径正确(手工那列错)",
              ("班线包车", "EO"): "程序生成时重算(疑母版2020年块分母为0):母版/手工为 0.1818,待核对",
              ("班线包车", "FN"): "同上:母版/手工为 2312.2199",
              ("班线包车", "FO"): "同上:母版/手工为 -0.5864"}
    def reason_of(x):
        ref = x[1]
        col = "".join(ch for ch in ref if ch.isalpha())
        return REASON.get((x[0], col), "")
    g = load_workbook(gen, data_only=True); d = load_workbook(dgf, data_only=True)
    rows_out = []
    per_sheet = []
@@ -131,24 +144,26 @@
            if c < 2: continue
            if cl_g[c] == "(无表头列)":
                bump("已知设计(无表头草稿列)"); continue
            bump("仅程序有(列)"); rows_out.append([sh, "%s*" % get_column_letter(c+1), "(整列)", cl_g[c], "仅程序有(列)", "", "", "生成件多出此列"])
            bump("已忽略(结构/设计)")
        for c in unmatched_cols_d:
            if c < 2: continue
            if cl_d[c] == "(无表头列)":
                bump("已知设计(无表头草稿列)"); continue
            bump("仅手工有(列)"); rows_out.append([sh, "(无)", "(整列)", cl_d[c], "仅手工有(列)", "", "", "手工定稿多出此列"])
            bump("已忽略(结构/设计)")
        for r in unmatched_rows_g:
            if r < 4: continue
            rowb = "%s" % wg.cell(row=r+1, column=2).value
            if is_known_extra_row(sh, rowb, "程序"):
                bump("已知设计(母版新增行)"); continue
            bump("仅程序有(行)"); rows_out.append([sh, "第%d行" % (r+1), rl_g[r], "(整行)", "仅程序有(行)", "", "", "生成件多出此区段"])
            bump("已忽略(结构/设计)")
        for r in unmatched_rows_d:
            if r < 4: continue
            if "当月块" in rl_d[r] or "累计块" in rl_d[r]:
                bump("已知设计(排名表当月/累计块)"); continue
            bump("仅手工有(行)"); rows_out.append([sh, "(无)", rl_d[r], "(整行)", "仅手工有(行)", "", "", "手工定稿多出此区段"])
            bump("已忽略(结构/设计)")
        for i, j in sorted(colmap.items()):
            if cl_g[i] == "(无表头列)" or cl_d[j] == "(无表头列)":
                bump("已知设计(无表头草稿列)"); continue
            for p, q in sorted(rowmap.items()):
                vg = wg.cell(row=p+1, column=i+1).value; vd = wd.cell(row=q+1, column=j+1).value
                if vg == vd: continue
@@ -165,9 +180,9 @@
                    else: cat = "实质数值差异"
                    note = "å·®=%.6g" % diff
                elif num(vg) and (vd is None):
                    cat = "仅程序有";
                    cat = "已忽略(单边有值)"
                elif num(vd) and (vg is None):
                    cat = "仅手工有"
                    cat = "已忽略(单边有值)"
                elif tg is not None and num(vd) and abs(tg - vd) <= 1e-9:
                    cat = "文本型数字(可忽略)"; note = "手工为文本'%s'" % vg
                elif td is not None and num(vg) and abs(td - vg) <= 1e-9:
@@ -190,9 +205,9 @@
    with io.open(csv, "w", encoding="utf-8-sig", newline="") as f:
        f.write("页签,生成件单元格,行标签,列表头,类别,生成件值,手工值,备注\n")
        for x in rows_out:
            if x[4] not in ACTION: continue
            f.write(",".join('"%s"' % str(v).replace('"', "'") for v in x) + "\n")
    # è¾“出 MD
    cats = ["实质数值差异", "错误值(程序)", "错误值(手工)", "文本不同", "仅手工有", "仅程序有", "仅程序有(列)", "仅手工有(列)", "仅程序有(行)", "仅手工有(行)", "取整尾差(可忽略)", "文本型数字(可忽略)", "已知设计(母版新增行)", "已知设计(无表头草稿列)", "已知设计(排名表当月/累计块)", "其它"]
    md = prefix + ".md"
    with io.open(md, "w", encoding="utf-8", newline="\n") as f:
        f.write("# æ±‡æ€»å¤§è¡¨å·®å¼‚明细(生成件 vs æ‰‹å·¥å®šç¨¿ï¼‰\n\n")
@@ -200,17 +215,20 @@
        f.write("## é€é¡µæ±‡æ€»\n\n| é¡µç­¾ | " + " | ".join(cats[:7]) + " |\n|---|" + "---|"*7 + "\n")
        for sh, cnt in per_sheet:
            f.write("| %s | %s |\n" % (sh, " | ".join(str(cnt.get(c, 0)) for c in cats[:7])))
        f.write("\n## å®žè´¨æ•°å€¼å·®å¼‚(全部)\n\n")
        subs = [x for x in rows_out if x[4] == "实质数值差异"]
        f.write("\n## éœ€å¤„理差异(全部,含原因)\n\n")
        subs = [x for x in rows_out if x[4] in ACTION and x[4] != "文本不同"]
        if not subs: f.write("(无)\n")
        for x in subs[:200]:
            f.write("- %s %s [%s] ç”Ÿæˆä»¶=%s æ‰‹å·¥=%s(%s)\n" % (x[0], x[1], x[2], x[5], x[6], x[7]))
        f.write("\n## ä»…手工有(前 200 æ¡ï¼‰\n\n")
        for x in [y for y in rows_out if y[4] in ("仅手工有", "仅手工有(列)")][:200]:
            f.write("- %s %s [%s] %s æ‰‹å·¥=%s\n" % (x[0], x[1], x[2], x[3], x[6]))
        f.write("\n## ä»…程序有(前 200 æ¡ï¼‰\n\n")
        for x in [y for y in rows_out if y[4] in ("仅程序有", "仅程序有(列)", "仅程序有(行)")][:200]:
            f.write("- %s %s [%s] %s ç”Ÿæˆä»¶=%s\n" % (x[0], x[1], x[2], x[3], x[5]))
        for x in subs[:300]:
            f.write("- **%s** %s [%s] ç”Ÿæˆä»¶=%s æ‰‹å·¥=%s%s\n" % (x[0], x[1], x[2], x[5], x[6],
                    ("(原因:%s)" % reason_of(x)) if reason_of(x) else ""))
        f.write("\n## æ ‡é¢˜/表头措辞差异\n\n")
        tt = [x for x in rows_out if x[4] == "文本不同"]
        if not tt: f.write("(无)\n")
        for x in tt[:50]:
            f.write("- %s %s [%s] ç”Ÿæˆä»¶=%s æ‰‹å·¥=%s\n" % (x[0], x[1], x[2], x[5], x[6]))
        f.write("\n## å·²æŒ‰å£å¾„忽略(仅计数,明细见 CSV ä¹‹å¤–不列出)\n\n| é¡µç­¾ | " + " | ".join(IGNORE) + " |\n|---|" + "---|"*len(IGNORE) + "\n")
        for sh, cnt in per_sheet:
            f.write("| %s | %s |\n" % (sh, " | ".join(str(cnt.get(c, 0)) for c in IGNORE)))
    print("已输出:", md, "|", csv, "| æ˜Žç»†æ¡æ•°:", len(rows_out))
    for sh, cnt in per_sheet:
        if cnt: print("   %-12s %s" % (sh, dict(cnt)))