diff --git a/.gitignore b/.gitignore index 148293c..428e09b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ tmp/ # Local runtime state (rule snapshots, bridge, reports) — never committed .local/ -reports/ +/reports/ # Developer-only build-time credentials for compile-time injection — never committed .env.langfuse diff --git a/.zcodeignore b/.zcodeignore index bfdaa64..ee9bf82 100644 --- a/.zcodeignore +++ b/.zcodeignore @@ -12,7 +12,7 @@ tmp/ # Local runtime state (rule snapshots, bridge, reports) — never committed .local/ -reports/ +/reports/ # Developer-only build-time credentials for compile-time injection — never committed .env.langfuse diff --git a/src/domains/seal/reports/charts/venn.test.ts b/src/domains/seal/reports/charts/venn.test.ts new file mode 100644 index 0000000..258a8e8 --- /dev/null +++ b/src/domains/seal/reports/charts/venn.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, test } from "bun:test"; +import { renderVennAccuracySvg } from "./venn.js"; + +describe("renderVennAccuracySvg", () => { + test("generates valid SVG with correct computed differences and labels", () => { + const svg = renderVennAccuracySvg({ + aiAccuracy: 92.08, + humanAccuracy: 83.33, + bothAccurate: 75.42 + }); + + expect(svg).toStartWith("\n"); + expect(svg).toContain("92.08%"); + expect(svg).toContain("83.33%"); + expect(svg).toContain("75.42%"); + // aiOnly = 92.08 - 75.42 = 16.66% or 16.67% + expect(svg).toContain("16.66%"); + // humanOnly = 83.33 - 75.42 = 7.91% + expect(svg).toContain("7.91%"); + expect(svg).toContain("AI审核准确"); + expect(svg).toContain("人工审核准确"); + expect(svg).toContain("AI与人工都准确"); + }); + + test("supports customized labels and dimensions", () => { + const svg = renderVennAccuracySvg({ + aiAccuracy: 90.0, + humanAccuracy: 80.0, + bothAccurate: 70.0, + aiLabel: "机器审核", + humanLabel: "复核人员", + bothLabel: "高度对齐", + width: 1000, + height: 500 + }); + + expect(svg).toContain('width="1000"'); + expect(svg).toContain('height="500"'); + expect(svg).toContain("机器审核"); + expect(svg).toContain("复核人员"); + expect(svg).toContain("高度对齐"); + expect(svg).toContain("20.00%"); + expect(svg).toContain("10.00%"); + }); +}); diff --git a/src/domains/seal/reports/charts/venn.ts b/src/domains/seal/reports/charts/venn.ts new file mode 100644 index 0000000..9c2c980 --- /dev/null +++ b/src/domains/seal/reports/charts/venn.ts @@ -0,0 +1,66 @@ +export interface VennAccuracyOptions { + aiAccuracy: number; + humanAccuracy: number; + bothAccurate: number; + aiLabel?: string; + humanLabel?: string; + bothLabel?: string; + width?: number; + height?: number; +} + +/** + * 自动生成 AI 与人工审核准确率对比的精美矢量维恩交集图 (SVG)。 + * 100% 纯代码矢量计算,无位图缩放模糊,离线自包含,杜绝外部 OSS 图床与水印。 + */ +export function renderVennAccuracySvg(options: VennAccuracyOptions): string { + const { + aiAccuracy, + humanAccuracy, + bothAccurate, + aiLabel = "AI审核准确", + humanLabel = "人工审核准确", + bothLabel = "AI与人工都准确", + width = 920, + height = 400 + } = options; + + const aiOnly = Math.max(0, Number((aiAccuracy - bothAccurate).toFixed(2))); + const humanOnly = Math.max(0, Number((humanAccuracy - bothAccurate).toFixed(2))); + + const fmt = (v: number) => `${v.toFixed(2)}%`; + + return ` + + + + + + + + + + ${fmt(aiOnly)} + + + + ${aiLabel} + (总准确率${fmt(aiAccuracy)}) + + + ${fmt(bothAccurate)} + + + + ${bothLabel} + + + ${fmt(humanOnly)} + + + + ${humanLabel} + (总准确率${fmt(humanAccuracy)}) + +`; +} diff --git a/src/domains/seal/reports/templates/assets/图1-准确率对比.svg b/src/domains/seal/reports/templates/assets/图1-准确率对比.svg index 4452e2a..0a1e632 100644 --- a/src/domains/seal/reports/templates/assets/图1-准确率对比.svg +++ b/src/domains/seal/reports/templates/assets/图1-准确率对比.svg @@ -1,27 +1,32 @@ - - - - - - - - - - - 0% - 25% - 50% - 75% - 100% - - - - - 92.08% - 83.33% - - - AI 审核 - 人工审核 - + + + + + + + + + + + 16.67% + + + + AI审核准确 + (总准确率92.08%) + + + 75.42% + + + + AI与人工都准确 + + + 7.92% + + + + 人工审核准确 + (总准确率83.33%) diff --git a/src/domains/seal/reports/templates/examples/赢家时尚-202608.md b/src/domains/seal/reports/templates/examples/赢家时尚-202608.md index 26a292f..a5545ab 100644 --- a/src/domains/seal/reports/templates/examples/赢家时尚-202608.md +++ b/src/domains/seal/reports/templates/examples/赢家时尚-202608.md @@ -36,7 +36,7 @@ AI 审核准确率的计算方式: $$ \text{AI 审核准确率} = \frac{\text{依规判定正确单数}}{\text{样本总量}} = \frac{221}{240} = 92.08\% $$ -![AI 与人工审核准确率对比](https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/res/1X3lE5wWdYx19lJb/img/813e2e1f-f01e-4680-adce-9fae1e02710f.png) +![AI 与人工审核准确率对比](../assets/图1-准确率对比.svg) *图 1 · AI 与人工审核准确率对比* @@ -256,128 +256,7 @@ $$ \text{AI 审核准确率} = \frac{\text{依规判定正确单数}}{\text{样 | 3 | 保底 30 笔大额采购与预付款单据(上中下旬各 10 笔),其余 170 笔按企业当期各报销模板的实际发生比例加权分配 | | 4 | 固定随机种子抽样算法基于截止日固定随机种子(Seed: 20260831)自动执行,且全流程清单支持任何第三方精准复现核验 | -为确保抽样过程完全透明、客观且具备 100% 审计可复现性,完整可执行核心代码如下: - -```python -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -赢家时尚(EEKA)Seal 智能审批跑批质效评估——240笔样本分层随机抽样算法程序 -随机种子设定依据:20260831(取自 2026 年 8 月 31 日账期截止日) -业务约束:时间 1:1:1 均衡(80:80:80) | 采购保底 >= 30 笔 | 决策配比 100同意:100驳回:40复核 -""" -import random -import hashlib -from collections import defaultdict, Counter - -RANDOM_SEED = 20260831 # 账期截止日固定随机种子 - -# 采购核心模板关键词(保底 30 笔,上中下旬各 >= 10 笔) -PROCUREMENT_KEYWORDS = ["采购", "预付款", "申购", "非生产物料"] - -# 各时间段抽样约束矩阵(总计 80 * 3 = 240 笔) -PERIOD_SPEC = { - "EARLY": { - "name": "8月上旬 (8.01 ~ 8.10)", - "date_range": ("08-01", "08-10"), - "total": 80, - "proc_min": 10, - "decisions": {"APPROVE": 36, "REJECT": 31, "REVIEW": 13} - }, - "MID": { - "name": "8月中旬 (8.11 ~ 8.20)", - "date_range": ("08-11", "08-20"), - "total": 80, - "proc_min": 10, - "decisions": {"APPROVE": 37, "REJECT": 30, "REVIEW": 13} - }, - "LATE": { - "name": "8月下旬 (8.21 ~ 8.31)", - "date_range": ("08-21", "08-31"), - "total": 80, - "proc_min": 10, - "decisions": {"APPROVE": 27, "REJECT": 39, "REVIEW": 14} - } -} - -def classify_period(date_str: str) -> str: - """按提交日期划分上中下旬""" - day = date_str.strip()[-5:] - if "08-01" <= day <= "08-10": return "EARLY" - if "08-11" <= day <= "08-20": return "MID" - if "08-21" <= day <= "08-31": return "LATE" - return "UNKNOWN" - -def is_procurement(template_name: str) -> bool: - """判定是否为大额采购及预付款核心单据""" - return any(k in template_name for k in PROCUREMENT_KEYWORDS) - -def deterministic_stratified_sample(raw_pool: list, seed: int = RANDOM_SEED) -> list: - """ - 分层确定性随机抽样核心算法 - :param raw_pool: 8 月全量 6,573 笔跑批单据池 - :param seed: 固定随机种子 (20260831) - :return: 严格满足 240 笔约束准绳的审计样本列表 - """ - # 1. 办结归档单据过滤 (100% 抽取终审单据 APPROVED 或 TERMINATED) - - valid_pool = [ ] - - for b in raw_pool: - p_key = classify_period(b["submit_date"]) - if p_key == "UNKNOWN": continue - status = str(b.get("manual_status", "")).upper() - if not ("APPROVE" in status or "TERMINAT" in status or "同意" in status or "终止" in status): - continue - valid_pool.append({ - **b, - "period_key": p_key, - "is_proc": is_procurement(b.get("template", "")), - "norm_decision": b["ai_decision"] - }) - - # 2. 分层桶归类:(时间段, 是否采购, AI决策) - buckets = defaultdict(list) - for b in valid_pool: - key = (b["period_key"], b["is_proc"], b["norm_decision"]) - buckets[key].append(b) - - # 3. 确定性哈希散列排序 (消除跨操作系统平台乱序,保证 100% 可复现) - for key, items in buckets.items(): - items.sort(key=lambda x: hashlib.sha256(f"{seed}_{x['bill_no']}".encode()).hexdigest()) - - # 4. 按约束矩阵多维分层抽取 - - selected = [ ] - - for p_key in ["EARLY", "MID", "LATE"]: - spec = PERIOD_SPEC[p_key] - for dec, quota in spec["decisions"].items(): - proc_candidates = buckets[(p_key, True, dec)] - non_proc_candidates = buckets[(p_key, False, dec)] - - # 采购类保底分配 (每旬 >= 10 笔,全月 >= 30 笔) - proc_target = 3 if dec != "REVIEW" else 4 - if dec == "APPROVE" and p_key == "MID": proc_target = 4 - - picked_proc = proc_candidates[:proc_target] - needed_non_proc = quota - len(picked_proc) - picked_non_proc = non_proc_candidates[:needed_non_proc] - - selected.extend(picked_proc) - selected.extend(picked_non_proc) - - # 5. 排序输出:前 200 笔为确定性判定(同意/驳回),后 40 笔为建议复核 - definitive = [s for s in selected if s["norm_decision"] in ("APPROVE", "REJECT", "同意", "驳回")] - review = [s for s in selected if s["norm_decision"] in ("REVIEW", "建议复核")] - definitive.sort(key=lambda x: (x["submit_date"], x["bill_no"])) - review.sort(key=lambda x: (x["submit_date"], x["bill_no"])) - - final_240 = definitive + review - for idx, item in enumerate(final_240, start=1): - item["sample_seq"] = idx - return final_240 -``` +抽样基于账期截止日的固定随机种子执行,全过程可由第三方复现,完整可执行代码随报告附件交付。 **抽样算法说明**