# -*- coding: utf-8 -*-
"""Step 3 双产物验收：活动类型口径 / 离职归并 / 时间窗口覆盖。"""
import json
import os
from collections import Counter

B = os.path.dirname(os.path.abspath(__file__))


def load(n):
    with open(os.path.join(B, n), encoding='utf-8') as f:
        return json.load(f)


print('===== 3a activities_feishu.json =====')
a = load('activities_feishu.json')
items = a['items']
print('generated:', a.get('generated'), '| total:', a.get('total'), '| months:', a.get('months'))
print('channel_breakdown:', a.get('channel_breakdown'))
print('type_raw:', a.get('type_raw'))
print('活动类型未填条数:', sum(1 for x in items if not (x.get('atype') or '').strip()))
print('字段完整性:', {k: sum(1 for x in items if x.get(k)) for k in ('id', 'date', 'submitted_by', 'customer', 'atype', 'dept_raw', 'type')})
print('离职者残留(黄明月/张立娅):', Counter(x['submitted_by'] for x in items if x['submitted_by'] in ('黄明月', '张立娅')))
print('刘子研条数:', sum(1 for x in items if x['submitted_by'] == '刘子研'))
print('月份分布:', dict(sorted(Counter(x['date'][:7] for x in items).items())))

print('\n===== 3b daily_activities_mcp.json =====')
d = load('daily_activities_mcp.json')
di = d['items']
win = [x for x in di if str(x.get('start_time') or '') >= '2026-07-01']
typed_win = sum(1 for x in win if isinstance(x.get('field_76654e'), dict) and x['field_76654e'].get('label'))
print('updated:', d.get('updated'), '| total:', d.get('total'))
print('窗口内(>=2026-07-01)条数:', len(win), '| 其中活动类型已填:', typed_win,
      '(%.1f%%)' % (100.0 * typed_win / max(1, len(win))))
print('全文件活动类型已填:', sum(1 for x in di if isinstance(x.get('field_76654e'), dict) and x['field_76654e'].get('label')), '/', len(di))
print('窗口内活动类型分布:', dict(Counter(x['field_76654e'].get('label') for x in win if isinstance(x.get('field_76654e'), dict)).most_common()))
print('窗口内字段样例:', {k: (win[0].get(k) if not isinstance(win[0].get(k), dict) else win[0].get(k).get('label') or win[0].get(k).get('name_cn')) for k in ('name', 'start_time', 'field_b99055', 'field_5f20fc', 'field_76654e', 'field_5ed7ab', 'work_item_id')} if win else None)
