import pandas as pd

# 读取决策文件
df = pd.read_csv('outputs/reports/llm_decisions_20260415.csv')

# 只分析智能判断的行
llm_df = df[df['source'] == '智能判断'].copy()

print(f"总智能决策数：{len(llm_df)}")
print("\n=== 多维度使用率分析 ===")

# 分析每个维度的使用
dimensions = {
    'bid_increased_7d': 'bid_increased_7d',
    'creative_changed_7d': 'creative_changed_7d',
    'stable_spend': 'stable_spend',
    'ad_age': 'ad_age'
}

for name, keyword in dimensions.items():
    count = llm_df['reason'].str.contains(keyword, na=False).sum()
    pct = count / len(llm_df) * 100
    print(f"{name}: {count}条 ({pct:.1f}%)")

print("\n=== 降价幅度分布 ===")
bid_down_df = llm_df[llm_df['action'] == 'bid_down']
print(bid_down_df['recommended_change_pct'].value_counts().sort_index())

print("\n=== 特殊场景识别 ===")
print(f"调价无效场景: {llm_df['dimension'].str.contains('调价无效', na=False).sum()}条")
print(f"创意问题场景: {llm_df['reason'].str.contains('creative_changed_7d=true但', na=False).sum()}条")
print(f"数据不稳定场景: {llm_df['reason'].str.contains('数据不稳定', na=False).sum()}条")

print("\n=== 示例决策（调价无效） ===")
invalid_price = llm_df[llm_df['dimension'].str.contains('调价无效', na=False)]
for _, row in invalid_price.head(3).iterrows():
    print(f"ad_id={row['ad_id']}: {row['reason']}")
