# -*- coding: utf-8 -*-
"""从全量评论中抽取「金额 + 时间」自述，做成经验分布，用于校验 M1/M2 预估"""
import glob, json, re, sys
from collections import Counter

sys.stdout.reconfigure(encoding="utf-8")
ROOT = r"D:\Deepseek\douyin_fengdaquan"
CMT = ROOT + r"\comments_all"

AMT = re.compile(r"(\d+(?:\.\d+)?)\s*(万|千|百|w|W|k|K|块|元|米|快)")
MONTH = re.compile(r"(第一个月|第二个月|一个月|1个月|俩月|两个月|月)")
DAY = re.compile(r"(一天|每天|单天|日入)")

rows = []
for fp in glob.glob(CMT + r"\*.json"):
    j = json.load(open(fp, encoding="utf-8"))
    for c in j.get("comments", []):
        t = (c.get("text") or "").strip()
        if not t:
            continue
        m = AMT.search(t)
        if not m:
            continue
        val = float(m.group(1))
        unit = m.group(2)
        mult = 10000 if unit in "万wW" else 1000 if unit in "kK千" else 1
        amt = val * mult
        kind = "month" if MONTH.search(t) else ("day" if DAY.search(t) else "other")
        rows.append((amt, kind, c.get("digg") or 0, t))

print("含金额的评论:", len(rows))
for kind in ("month", "day", "other"):
    xs = sorted(r[0] for r in rows if r[1] == kind)
    if not xs:
        continue
    n = len(xs)
    print(f"\n[{kind}] {n} 条 | 中位 {xs[n//2]:,.0f} | P25 {xs[n//4]:,.0f} | P75 {xs[3*n//4]:,.0f} | 最小 {xs[0]:,.0f} | 最大 {xs[-1]:,.0f}")

print("\n=== 按月金额 ≥ 具体数值的评论（前 30，按赞）===")
for amt, kind, digg, t in sorted([r for r in rows if r[1] == "month"], key=lambda x: -x[2])[:30]:
    print(f"[{digg}] {amt:,.0f} | {t[:80]}")

print("\n=== 按天金额（前 15）===")
for amt, kind, digg, t in sorted([r for r in rows if r[1] == "day"], key=lambda x: -x[2])[:15]:
    print(f"[{digg}] {amt:,.0f} | {t[:80]}")
