import pandas as pd
from openpyxl import Workbook
from openpyxl.styles import Font, Alignment, PatternFill

# 创建工作簿
wb = Workbook()
wb.remove(wb.active)  # 删除默认sheet

# ================== Sheet1: 基本信息 ==================
ws1 = wb.create_sheet("基本信息")
ws1.append(["字段", "内容"])
basic_info = [
    ["学员ID", "1185"],
    ["学习级别", "Level 1"],
    ["已学单元", "Unit49 ~ Unit54（共6个单元）"],
    ["学习周期", "2025年6月 ~ 2026年4月11日"],
    ["总有效学习时长", "约62分钟（平均每单元10~15分钟）"]
]
for row in basic_info:
    ws1.append(row)
# 样式设置
header_fill = PatternFill(start_color="FFC000", end_color="FFC000", fill_type="solid")
for col in range(1, 3):
    cell = ws1.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# ================== Sheet2: 整体学习概览 ==================
ws2 = wb.create_sheet("整体学习概览")
ws2.append(["字段", "内容"])
overview = [
    ["总互动答题次数", "644次（覆盖20+种题型）"],
    ["已掌握核心知识点", "182个（单词+句型）"],
    ["单元整体掌握率", "88%（良好水平）"],
    ["单元挑战完成情况", "听力6次全Perfect，口语6次（2Perfect/2Good/2Oops）"]
]
for row in overview:
    ws2.append(row)
for col in range(1, 3):
    cell = ws2.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# ================== Sheet3: 互动组件表现 ==================
ws3 = wb.create_sheet("互动组件表现")
ws3.append(["结果等级", "数量", "占比"])
interactive = [
    ["Perfect", 437, "67.8%"],
    ["Good", 78, "12.1%"],
    ["Pass", 102, "15.8%"],
    ["Oops", 15, "2.3%"],
    ["Failed", 12, "1.9%"]
]
for row in interactive:
    ws3.append(row)
for col in range(1, 4):
    cell = ws3.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# ================== Sheet4: 薄弱知识点 ==================
ws4 = wb.create_sheet("薄弱知识点")
ws4.append(["知识点英文", "中文意思", "错误占比"])
weak_points = [
    ["carrot", "胡萝卜", "33.3%"],
    ["story", "故事", "25%"],
    ["right", "右边", "30%"],
    ["dirty", "脏的", "33.3%"],
    ["coconut", "椰子", "33.3%"],
    ["favourite", "最喜欢的", "33.3%"]
]
for row in weak_points:
    ws4.append(row)
for col in range(1, 4):
    cell = ws4.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# ================== Sheet5: 单元挑战表现 ==================
ws5 = wb.create_sheet("单元挑战表现")
ws5.append(["题型", "测试次数", "Perfect次数", "Good次数", "Oops次数", "整体表现"])
challenge = [
    ["听力", 6, 6, 0, 0, "🌟 满分水平，听音辨音、听力理解能力极强"],
    ["口语", 6, 2, 2, 2, "📈 良好水平，发音准确率约80%，句子完整度有待提升"]
]
for row in challenge:
    ws5.append(row)
for col in range(1, 7):
    cell = ws5.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# ================== Sheet6: 优势总结 ==================
ws6 = wb.create_sheet("优势总结")
ws6.append(["序号", "优势内容"])
strengths = [
    [1, "听力能力突出：所有单元听力挑战全满分，对语音、语调、连读的识别准确率100%"],
    [2, "基础单词掌握牢固：85%的核心单词Perfect比例100%，词义、发音记忆扎实"],
    [3, "学习韧性强：所有Oops/Failed题目最终都通过多次尝试完成，无放弃作答情况"],
    [4, "核心句型掌握稳定：90%以上的常用句型（问候、询问、指令等）掌握率100%，能够准确理解和应用"]
]
for row in strengths:
    ws6.append(row)
for col in range(1, 3):
    cell = ws6.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# ================== Sheet7: 待提升方向 ==================
ws7 = wb.create_sheet("待提升方向")
ws7.append(["序号", "提升方向"])
improve = [
    [1, "口语表达完整度：2次口语挑战Oops均因为句子表述不完整，遗漏核心成分"],
    [2, "发音准确率：部分长单词（如coconut、favourite）发音准确率低于70%"],
    [3, "生僻词记忆：低频出现的名词类单词遗忘率较高，需要定期复习"],
    [4, "句子结构排序：巩固练习中句子排序题错误率较高，对句型结构的熟练度有待加强"]
]
for row in improve:
    ws7.append(row)
for col in range(1, 3):
    cell = ws7.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# ================== Sheet8: 个性化学习建议 ==================
ws8 = wb.create_sheet("个性化学习建议")
ws8.append(["序号", "建议内容"])
suggestions = [
    [1, "口语强化训练：每天花5分钟做句子跟读练习，重点训练完整句子的流利度和完整度，每次录音后对照参考答案自查"],
    [2, "单词复习计划：每周复习1次当月所学生僻单词，每次10分钟，采用闪卡记忆法强化"],
    [3, "句型专项训练：每天做3道句子排序题，连续练习2周，强化句型结构记忆"],
    [4, "发音纠正：针对发音准确率低的单词，每天跟读3遍，对比标准发音调整口型和语调"]
]
for row in suggestions:
    ws8.append(row)
for col in range(1, 3):
    cell = ws8.cell(row=1, column=col)
    cell.font = Font(bold=True)
    cell.fill = header_fill
    cell.alignment = Alignment(horizontal="center")

# 调整列宽
for ws in wb.worksheets:
    for col in ws.columns:
        max_length = 0
        column = col[0].column_letter
        for cell in col:
            try:
                if len(str(cell.value)) > max_length:
                    max_length = len(str(cell.value))
            except:
                pass
        adjusted_width = (max_length + 2) * 1.2
        ws.column_dimensions[column].width = adjusted_width

# 保存文件
output_path = "/root/.openclaw/workspace-xiaoban/user_1185_study_analysis_report.xlsx"
wb.save(output_path)
print(f"Excel报告已生成，保存路径：{output_path}")
