# -*- coding: utf-8 -*-
"""3a vs 3b 交叉对账：同一窗口(2026-07-01~)两个独立产物的 work_item_id 集合与逐月计数。"""
import json
import os
from collections import Counter

B = os.path.dirname(os.path.abspath(__file__))
a = json.load(open(os.path.join(B, 'activities_feishu.json'), encoding='utf-8'))['items']
d = json.load(open(os.path.join(B, 'daily_activities_mcp.json'), encoding='utf-8'))['items']
win = [x for x in d if str(x.get('start_time') or '') >= '2026-07-01']

ida = {'FS%s' % x['id'][2:] if x['id'].startswith('FS') else x['id'] for x in a}
idb = {str('FS%s' % x.get('work_item_id')) for x in win}
print('3a 条数:', len(a), '唯一id:', len(ida))
print('3b 窗口条数:', len(win), '唯一id:', len(idb))
print('只在 3b 有:', len(idb - ida), '| 只在 3a 有:', len(ida - idb))
print('3a 逐月:', dict(sorted(Counter(x['date'][:7] for x in a).items())))
print('3b 逐月:', dict(sorted(Counter(str(x.get('start_time'))[:7] for x in win).items())))
only = idb - ida
if only:
    for x in win:
        if str('FS%s' % x.get('work_item_id')) in only:
            print('  3b独有 sample:', x.get('start_time'), x.get('name'), '| 类型=',
                  (x.get('field_76654e') or {}).get('label') if isinstance(x.get('field_76654e'), dict) else x.get('field_76654e'))
