Merge pull request #229 from yunyingk/mac15/generate-accuracy-venn-diagram

Add vector Venn diagram generator and upgrade accuracy chart
This commit is contained in:
yunyingk authored and GitHub committed 2026-10-12 17:25:19 +08:00
commit f788f9c6db
6 files changed
+147 -151

No files matched your search

+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
@@ -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("<svg");
expect(svg).toEndWith("</svg>\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%");
});
});
+66
View File
@@ -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 `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" font-family="PingFang SC, -apple-system, Hiragino Sans GB, Microsoft YaHei, sans-serif">
<rect x="0" y="0" width="${width}" height="${height}" fill="#ffffff"/>
<!-- Left Circle: AI Accuracy (Soft Blue) -->
<circle cx="370" cy="155" r="140" fill="#b3dbff" fill-opacity="0.75"/>
<!-- Right Circle: Human Accuracy (Soft Mint/Teal) -->
<circle cx="530" cy="155" r="140" fill="#cdeee4" fill-opacity="0.75"/>
<!-- Left exclusive percentage -->
<text x="320" y="164" font-size="25" font-weight="500" fill="#1f2328" text-anchor="middle">${fmt(aiOnly)}</text>
<!-- Left label & dashed pointer -->
<line x1="190" y1="155" x2="270" y2="155" stroke="#1f2328" stroke-width="1.8" stroke-dasharray="6 4"/>
<text x="178" y="143" font-size="18" font-weight="500" fill="#1f2328" text-anchor="end">${aiLabel}</text>
<text x="178" y="171" font-size="16" fill="#1f2328" text-anchor="end">(总准确率${fmt(aiAccuracy)})</text>
<!-- Center overlap percentage -->
<text x="450" y="164" font-size="25" font-weight="500" fill="#1f2328" text-anchor="middle">${fmt(bothAccurate)}</text>
<!-- Center bottom label & vertical dashed line extending through bottom of intersection -->
<line x1="450" y1="200" x2="450" y2="325" stroke="#1f2328" stroke-width="1.8" stroke-dasharray="6 4"/>
<text x="450" y="360" font-size="18" font-weight="500" fill="#1f2328" text-anchor="middle">${bothLabel}</text>
<!-- Right exclusive percentage -->
<text x="580" y="164" font-size="25" font-weight="500" fill="#1f2328" text-anchor="middle">${fmt(humanOnly)}</text>
<!-- Right label & dashed pointer -->
<line x1="630" y1="155" x2="710" y2="155" stroke="#1f2328" stroke-width="1.8" stroke-dasharray="6 4"/>
<text x="722" y="143" font-size="18" font-weight="500" fill="#1f2328" text-anchor="start">${humanLabel}</text>
<text x="722" y="171" font-size="16" fill="#1f2328" text-anchor="start">(总准确率${fmt(humanAccuracy)})</text>
</svg>
`;
}
@@ -1,27 +1,32 @@
<svg xmlns="http://www.w3.org/2000/svg" width="880" height="400" viewBox="0 0 880 400" font-family="PingFang SC, Hiragino Sans GB, Microsoft YaHei, sans-serif">
<rect x="0" y="0" width="880" height="400" fill="#ffffff"/>
<g stroke="#eceff3" stroke-width="1">
<line x1="110" y1="265" x2="800" y2="265"/>
<line x1="110" y1="190" x2="800" y2="190"/>
<line x1="110" y1="115" x2="800" y2="115"/>
<line x1="110" y1="40" x2="800" y2="40"/>
</g>
<line x1="110" y1="340" x2="800" y2="340" stroke="#d1d9e0" stroke-width="1.5"/>
<g font-size="13" fill="#8b949e" text-anchor="end">
<text x="98" y="345">0%</text>
<text x="98" y="270">25%</text>
<text x="98" y="195">50%</text>
<text x="98" y="120">75%</text>
<text x="98" y="45">100%</text>
</g>
<rect x="270" y="63.76" width="150" height="276.24" rx="4" fill="#4c8bf5"/>
<rect x="510" y="90.01" width="150" height="249.99" rx="4" fill="#6fbf9a"/>
<g font-size="22" font-weight="600" fill="#1f2328" text-anchor="middle">
<text x="345" y="54">92.08%</text>
<text x="585" y="80">83.33%</text>
</g>
<g font-size="15" fill="#59636e" text-anchor="middle">
<text x="345" y="372">AI 审核</text>
<text x="585" y="372">人工审核</text>
</g>
<svg xmlns="http://www.w3.org/2000/svg" width="920" height="400" viewBox="0 0 920 400" font-family="PingFang SC, -apple-system, Hiragino Sans GB, Microsoft YaHei, sans-serif">
<rect x="0" y="0" width="920" height="400" fill="#ffffff"/>
<!-- Left Circle: AI Accuracy (Soft Blue) -->
<circle cx="370" cy="155" r="140" fill="#b3dbff" fill-opacity="0.75"/>
<!-- Right Circle: Human Accuracy (Soft Mint/Teal) -->
<circle cx="530" cy="155" r="140" fill="#cdeee4" fill-opacity="0.75"/>
<!-- Left exclusive percentage (16.67%) -->
<text x="320" y="164" font-size="25" font-weight="500" fill="#1f2328" text-anchor="middle">16.67%</text>
<!-- Left label & dashed pointer -->
<line x1="190" y1="155" x2="270" y2="155" stroke="#1f2328" stroke-width="1.8" stroke-dasharray="6 4"/>
<text x="178" y="143" font-size="18" font-weight="500" fill="#1f2328" text-anchor="end">AI审核准确</text>
<text x="178" y="171" font-size="16" fill="#1f2328" text-anchor="end">(总准确率92.08%)</text>
<!-- Center overlap percentage (75.42%) -->
<text x="450" y="164" font-size="25" font-weight="500" fill="#1f2328" text-anchor="middle">75.42%</text>
<!-- Center bottom label & vertical dashed line extending through bottom of intersection -->
<line x1="450" y1="200" x2="450" y2="325" stroke="#1f2328" stroke-width="1.8" stroke-dasharray="6 4"/>
<text x="450" y="360" font-size="18" font-weight="500" fill="#1f2328" text-anchor="middle">AI与人工都准确</text>
<!-- Right exclusive percentage (7.92%) -->
<text x="580" y="164" font-size="25" font-weight="500" fill="#1f2328" text-anchor="middle">7.92%</text>
<!-- Right label & dashed pointer -->
<line x1="630" y1="155" x2="710" y2="155" stroke="#1f2328" stroke-width="1.8" stroke-dasharray="6 4"/>
<text x="722" y="143" font-size="18" font-weight="500" fill="#1f2328" text-anchor="start">人工审核准确</text>
<text x="722" y="171" font-size="16" fill="#1f2328" text-anchor="start">(总准确率83.33%)</text>
</svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

@@ -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
```
抽样基于账期截止日的固定随机种子执行,全过程可由第三方复现,完整可执行代码随报告附件交付。
**抽样算法说明**