import pandas as pd

# 文件路径
difficulty_path = "/root/.openclaw/media/inbound/é_¾åº_æ_æ_å_è_ç³_æ_1.0---4d1d9fe3-1e36-4df1-baf6-d826fcf7a05e.xlsx" # 难度表
lv1_lower_path = "/root/.openclaw/media/inbound/â_¼ï_LV1-å_ç_å_è_åº_-ç¼_å_é_è_ç_è_é---5b90d819-abf3-4882-8772-ed8f3e0b449f.xlsx" # LV1下册词汇表
output_path = "/root/.openclaw/workspace-xiaoban/正确版_LV1下册词汇匹配结果.xlsx"

# 读取表格
df_diff = pd.read_excel(difficulty_path)
df_lower = pd.read_excel(lv1_lower_path)

print(f"LV1下册词汇表总条数：{len(df_lower)}")

# 创建难度表映射（全部单词，不区分上下册，按内容匹配）
word_map = {}
for _, row in df_diff.iterrows():
    word = str(row['单词']).strip()
    word_map[word] = {
        '难度（D）': row['难度（D）'],
        '实现成本(T)': row['实现成本(T)'],
        '单词系数': row['单词系数']
    }

# 匹配字段
def get_value(word, col):
    key = str(word).strip()
    return word_map.get(key, {}).get(col, None)

df_lower['难度（D）'] = df_lower['单词'].apply(lambda x: get_value(x, '难度（D）'))
df_lower['实现成本(T)'] = df_lower['单词'].apply(lambda x: get_value(x, '实现成本(T)'))
df_lower['单词系数'] = df_lower['单词'].apply(lambda x: get_value(x, '单词系数'))

# 保存结果
df_lower.to_excel(output_path, index=False)

match_count = df_lower['难度（D）'].notna().sum()
print(f"\nLV1下册匹配完成！结果已保存到：{output_path}")
print(f"成功匹配条数：{match_count}")
print(f"未匹配条数：{len(df_lower) - match_count}")
