File size: 6,388 Bytes
e39a6b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
"""查 multi 题表和页面:python3 -I screen/multi/check.py

- 字段齐全(id pages q answers/facts type design shots),id 不重,type 是四类之一、每类至少 10 题;
- 每题 2–4 张图,页面 HTML 都在,PNG 渲染了(没渲染只警告);每类里电脑和手机截图都有;
- 答案在页面上:每题至少一个答案写法(去空格、归一化后)出现在这题几张截图的文字里;
  算出来的(到手价、合计、差额、最晚出门时间、几处)和判断(能不能、一不一致)不在页面上,在 COMPUTED 里登记了理由;
- 页面里的「X月X日(周X)/ X月X日 周X」星期和 2026 年日历对得上;
- 域名都是 .example;没有真实平台、品牌名;手机号只用 138/139/137 0000 xxxx 这种。
"""
import datetime as dt
import html as _h
import json
import os
import re
import sys

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(HERE))
import run_screen  # noqa: E402
import vlm  # noqa: E402

TYPES = ("比价", "比方案", "对行程", "对信息")
COMPUTED = {
    "mq002": "PLUS 价叠加满减后哪家最便宜:答案是店名,店名在页面上",
    "mq004": "九州 L 码 429−20=409(页面上 409 不出现)",
    "mq006": "白鹭 (299−30)/5.4=49.8 元/公斤",
    "mq008": "暖杯 89+44.5=133.5",
    "mq010": "禾木 1299−120=1179",
    "mq012": "星联 39+50+5=94",
    "mq013": "云帆 39.5×6+79×6=711",
    "mq015": "星联 99×12+200=1388",
    "mq016": "云帆 70×12+300=1140",
    "mq018": "青盾 (1000−100)×100%=900",
    "mq020": "木棉 1999+299=2298",
    "mq023": "09:38+52 分钟 > 10:00 → 不能",
    "mq026": "01:20 落地晚于末班 00:30 → 不能",
    "mq025": "落地 12-01 01:20,要订前一晚 11-30",
    "mq029": "09:30−30−45 分钟 = 08:15",
    "mq030": "周会 08:30 结束晚于 08:15 → 不能",
    "mq031": "订单页地址没改 → 没有",
    "mq032": "两处对不上(时间、地址)",
    "mq035": "1286−1268=18",
    "mq036": "抬头多了「信息」→ 不一致",
}
BANNED = ["微信", "支付宝", "淘宝", "天猫", "京东", "美团", "饿了么", "拼多多", "12306", "携程", "飞猪", "去哪儿", "滴滴", "高德", "百度",
          "钉钉", "飞书", "小红书", "抖音", "B站", "哔哩", "顺丰", "中国移动", "中国联通", "中国电信", "东方航空", "南方航空", "国航", "小米", "华为", "苹果公司"]
WEEK = "一二三四五六日"


def text_of(path):
    raw = open(path, encoding="utf-8").read()
    body = re.sub(r"(?s)<(style|script|title)[^>]*>.*?</\1>", " ", raw)
    return raw, _h.unescape(re.sub(r"<[^>]+>", " ", body))


def main():
    errs, warns = [], []
    rows = [json.loads(l) for l in open(os.path.join(HERE, "sets", "multi.jsonl"), encoding="utf-8") if l.strip()]
    ids = set()
    used = set()
    shots_by_type = {t: set() for t in TYPES}
    for r in rows:
        for k in ("id", "pages", "q", "type", "design", "shots"):
            if k not in r:
                errs.append(f"{r.get('id')} 少字段 {k}")
        if not (r.get("answers") or r.get("facts")):
            errs.append(f"{r['id']} 没有 answers 也没有 facts")
        if r["id"] in ids:
            errs.append(f"id 重复 {r['id']}")
        ids.add(r["id"])
        if r["type"] not in TYPES:
            errs.append(f"{r['id']} type 不对:{r['type']}")
        if not 2 <= len(r["pages"]) <= 4:
            errs.append(f"{r['id']} 截图 {len(r['pages'])} 张")
        texts = []
        for p in r["pages"]:
            used.add(p)
            path = os.path.join(HERE, "pages", p + ".html")
            if not os.path.exists(path):
                errs.append(f"{r['id']} 没有页面 {p}")
                continue
            texts.append(text_of(path)[1])
            if not os.path.exists(run_screen.pic(p)):
                warns.append(f"{p}.png 还没渲染")
        for s in r.get("shots", []):
            shots_by_type.get(r["type"], set()).add(s)
        alltext = vlm.norm(" ".join(texts))
        found = any(vlm.norm(a) and vlm.norm(a) in alltext for a in r.get("answers", []))
        if r.get("answers") and not found and r["id"] not in COMPUTED:
            errs.append(f"{r['id']} 答案 {r['answers'][:3]} 不在页面上,也没登记为算出来的")
        if found and r["id"] in COMPUTED and r["id"] not in ("mq002", "mq025", "mq032"):   # 025: 出发日碰巧是 11-30;032: 数字 2 到处都有
            warns.append(f"{r['id']} 登记为算出来的,但答案也在页面上出现:{r['answers'][:2]}(看看是不是干扰项碰巧一样)")
    for t in TYPES:
        n = sum(r["type"] == t for r in rows)
        if n < 10:
            errs.append(f"{t} 只有 {n} 题")
        if shots_by_type[t] != {"phone", "desktop"}:
            errs.append(f"{t} 截图只有 {shots_by_type[t]}")
    pages = sorted(f[:-5] for f in os.listdir(os.path.join(HERE, "pages")) if f.endswith(".html"))
    for p in pages:
        if p not in used:
            warns.append(f"页面 {p} 没有题用")
        raw, text = text_of(os.path.join(HERE, "pages", p + ".html"))
        for m in re.finditer(r"(\d{1,2})月(\d{1,2})日\s*[((]?\s*(?:周|星期)([一二三四五六日])", text):
            mo, d, w = int(m.group(1)), int(m.group(2)), m.group(3)
            real = WEEK[dt.date(2026, mo, d).weekday()]
            if real != w:
                errs.append(f"{p}: {m.group(0)} 实际是周{real}")
        for m in re.finditer(r"\b([a-z0-9-]+(?:\.[a-z0-9-]+)+)\.(com|cn|net|org|io)\b", raw):
            errs.append(f"{p}: 域名不是 .example:{m.group(0)}")
        for b in BANNED:
            if b in text:
                errs.append(f"{p}: 出现真实名字「{b}」")
        for m in re.finditer(r"(?<!\d)(?<!\d )1[3-9]\d[\s-]?\d{4}[\s-]?\d{4}(?!\d)", text):
            if not re.match(r"1[3-9]\d[\s-]?0000", m.group(0)):
                errs.append(f"{p}: 手机号像真的 {m.group(0)}")
    for e in errs:
        print("ERR ", e)
    for w in sorted(set(warns)):
        print("WARN", w)
    from collections import Counter
    print(f"{len(rows)} 题 {dict(Counter(r['type'] for r in rows))},{len(pages)} 张页面;{len(errs)} 处错")
    return 1 if errs else 0


if __name__ == "__main__":
    sys.exit(main())