#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""先探：9 月飞书活动的「线下/线上」能不能从活动名称+描述文本推断出来（决定口径可行性）。"""
import io
import json
import re
from collections import Counter

ROOT = '/Users/liuxinyuan/Desktop/Hermes输出-工作类'
items = json.load(io.open(ROOT + '/数据/daily_activities_mcp.json', encoding='utf-8'))['items']
sep = [x for x in items if (x.get('start_time') or '').startswith('2026-09')]
print('9 月活动 %d 条\n' % len(sep))

OFFLINE = ['拜访', '上门', '来访', '到访', '面谈', '当面', '请客', '吃饭', '出差', '驻场', '现场',
           '参观', '考察', '走访', '送样', '带样', '到场', '会议室见']
ONLINE = ['电话', '致电', '微信', '线上', '腾讯会议', '视频', 'zoom', 'Zoom', '邮件', '远程',
          '钉钉', '语音', '群沟通', '网络会议']


def infer(name, desc):
    t = ('%s %s' % (name or '', (desc or '')[:400]))
    o = [w for w in OFFLINE if w in t]
    n = [w for w in ONLINE if w in t]
    if o and not n:
        return 'offline', o[:2]
    if n and not o:
        return 'online', n[:2]
    if o and n:
        return 'both', (o[:1] + n[:1])
    return 'unknown', []


cnt = Counter()
who = {}
for x in sep:
    ch, ev = infer(x.get('name'), x.get('field_b99055'))
    cnt[ch] += 1
    who.setdefault(ch, []).append((x.get('name'), ev))

print('推断结果分布：')
tot = len(sep)
for k in ['offline', 'online', 'both', 'unknown']:
    print('  %-8s %5d  (%.1f%%)' % (k, cnt[k], cnt[k] * 100.0 / tot))

print('\n活动名称 top（全量）:')
for k, v in Counter(x.get('name') for x in sep).most_common(8):
    print('  %-22s %d' % (k or '(空)', v))

print('\n活动名称 top（被判定 unknown 的）:')
for k, v in Counter(x.get('name') for x in sep if infer(x.get('name'), x.get('field_b99055'))[0] == 'unknown').most_common(8):
    print('  %-22s %d' % (k or '(空)', v))

print('\nunknown 样例（看是否真的无线索）：')
n = 0
for x in sep:
    ch, ev = infer(x.get('name'), x.get('field_b99055'))
    if ch == 'unknown':
        print('  [%s] %s ｜ %s' % (x.get('start_time'), (x.get('name') or '')[:10], (x.get('field_b99055') or '')[:70]))
        n += 1
        if n >= 5:
            break
