抽奖池导入9月底至1103已激活批次58893行(UAT)——号段白名单+掩码格式双校验,剔除1907行出对照表;附全池手机号合规审计脚本与存量不合规明细116行
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
# xuchao: 抽奖池手机号合规审计——按白名单号段+掩码格式全表排查,不合规的未中奖数据导出明细CSV
|
||||
# 用法: python3 docs/tools_audit_pool_phone_20261110.py
|
||||
# 口径与 tools_import_activated_batch_20261110.py 完全一致(号段白名单58段+「3+4星+4」格式);只读。
|
||||
import os, re
|
||||
import pymysql
|
||||
|
||||
allowed = set()
|
||||
allowed.update(f'13{d}' for d in range(10))
|
||||
allowed.update(['140', '141', '144', '145', '146', '147', '148', '149'])
|
||||
allowed.update(f'15{d}' for d in range(10) if d != 4)
|
||||
allowed.update(['162', '165', '166', '167'])
|
||||
allowed.update(['170', '171', '172', '173', '175', '176', '177', '178'])
|
||||
allowed.update(f'18{d}' for d in range(10))
|
||||
allowed.update(f'19{d}' for d in range(10) if d != 4)
|
||||
_pat = re.compile(r'^(\d{3})\*{4}\d{4}$')
|
||||
|
||||
os.environ['SETTLE_ENV'] = 'uat'
|
||||
path = '/Users/jacobxu/Documents/Project/12301-dscp/docs/tools/settle_recompute_check.py'
|
||||
src = open(path).read()
|
||||
head = src.split("cur = conn.cursor(pymysql.cursors.DictCursor)", 1)[0] + "cur = conn.cursor(pymysql.cursors.DictCursor)"
|
||||
ns = {'__name__': 'env'}
|
||||
exec(compile(head, path, 'exec'), ns)
|
||||
conn, cur = ns['conn'], ns['cur']
|
||||
|
||||
cur.execute("SELECT COUNT(*) c FROM hhrs_lottery_pool")
|
||||
total = cur.fetchone()['c']
|
||||
cur.execute("SELECT id, member_name, county, member_identity_no, member_phone, won, created_time FROM hhrs_lottery_pool")
|
||||
bad = []
|
||||
for r in cur.fetchall():
|
||||
p = r['member_phone'] or ''
|
||||
m = _pat.match(p)
|
||||
if not m:
|
||||
why = '空值' if p == '' else '格式异常(非3+4星+4)'
|
||||
elif m.group(1) not in allowed:
|
||||
why = '号段不在白名单'
|
||||
else:
|
||||
continue
|
||||
r['问题'] = why
|
||||
bad.append(r)
|
||||
print(f'全池 {total} 行, 不合规 {len(bad)} 行')
|
||||
from collections import Counter
|
||||
bw = [r for r in bad if r['won'] == 0]
|
||||
ww = [r for r in bad if r['won'] == 1]
|
||||
print('其中 未中奖(won=0):', len(bw), ' 已中奖(won=1):', len(ww))
|
||||
print('未中奖问题分布:', Counter(r['问题'] for r in bw).most_common())
|
||||
print('未中奖号段分布:', Counter((r['member_phone'] or '')[:3] for r in bw if r['问题'] == '号段不在白名单').most_common())
|
||||
print('未中奖县区分布:', Counter(r['county'] for r in bw).most_common())
|
||||
|
||||
out = os.path.join(os.path.dirname(os.path.abspath(__file__)), '抽奖池_存量手机号不合规明细_20261110.csv')
|
||||
with open(out, 'w', encoding='utf-8-sig') as f:
|
||||
f.write('id,姓名,县区,脱敏身份证,脱敏手机号,问题,创建时间\n')
|
||||
for r in sorted(bw, key=lambda x: x['id']):
|
||||
f.write(f"{r['id']},{r['member_name']},{r['county']},{r['member_identity_no']},{r['member_phone']},{r['问题']},{r['created_time']}\n")
|
||||
print('未中奖明细已导出:', out)
|
||||
for r in ww:
|
||||
print('已中奖不合规(需单独关注):', r['id'], r['member_name'], r['county'], r['member_phone'], r['问题'])
|
||||
Reference in New Issue
Block a user