wxy01giser commited on
Commit
16bdc7c
·
verified ·
1 Parent(s): 2af7bc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -69,8 +69,8 @@ def analyze_report(excel_path):
69
  return "请上传 Excel 文件", None, None, None
70
 
71
  try:
72
- sankey_fig = analyze_teacher_dashboard(excel_path=excel_path)
73
- cluster_fig, cluster_stats = cluster_and_visualize(excel_path=excel_path)
74
  advice = generate_teaching_advice(sankey_fig, cluster_stats)
75
 
76
  # 统计表格
@@ -106,7 +106,7 @@ def analyze_report(excel_path):
106
  </p>
107
  </div>
108
  """
109
- return html_report, sankey_fig, cluster_fig, cluster_stats
110
 
111
  except Exception as e:
112
  return f"<p style='color:red; text-align:center;'>分析失败:{str(e)}</p>", None, None, None
@@ -259,7 +259,7 @@ async def plugin_api(
259
  temp_file_path = temp_file.name # 拿到临时文件的真实路径(比如:C:\Users\XXX\AppData\Local\Temp\tmpxxxx.xlsx)
260
  print(df)
261
  # 调用分析函数(传临时文件的真实路径)
262
- html_report, sankey_fig, cluster_fig, stats = analyze_report(temp_file_path)
263
 
264
  print(f"{sankey_fig}生成成功!")
265
  print(f"{cluster_fig}生成成功!")
@@ -269,14 +269,16 @@ async def plugin_api(
269
  print(f"临时文件已删除:{temp_file_path}")
270
 
271
  # 按平台要求返回结果
 
272
  return {
273
  "code": 200,
274
  "message": "success",
275
  "data": {
276
  "html_report": html_report if html_report else "",
277
- "sankey_fig": sankey_fig.to_json() if sankey_fig is not None else "",
278
- "cluster_fig": cluster_fig.to_json() if cluster_fig is not None else "",
279
- "stats": stats if stats else []
 
280
  }
281
  }
282
  except Exception as e:
 
69
  return "请上传 Excel 文件", None, None, None
70
 
71
  try:
72
+ sankey_fig, sb64 = analyze_teacher_dashboard(excel_path=excel_path)
73
+ cluster_fig, cluster_stats, cb64 = cluster_and_visualize(excel_path=excel_path)
74
  advice = generate_teaching_advice(sankey_fig, cluster_stats)
75
 
76
  # 统计表格
 
106
  </p>
107
  </div>
108
  """
109
+ return html_report, sankey_fig, cluster_fig, cluster_stats, sb64, cb64
110
 
111
  except Exception as e:
112
  return f"<p style='color:red; text-align:center;'>分析失败:{str(e)}</p>", None, None, None
 
259
  temp_file_path = temp_file.name # 拿到临时文件的真实路径(比如:C:\Users\XXX\AppData\Local\Temp\tmpxxxx.xlsx)
260
  print(df)
261
  # 调用分析函数(传临时文件的真实路径)
262
+ html_report, sankey_fig, cluster_fig, stats, sb64, cb64 = analyze_report(temp_file_path)
263
 
264
  print(f"{sankey_fig}生成成功!")
265
  print(f"{cluster_fig}生成成功!")
 
269
  print(f"临时文件已删除:{temp_file_path}")
270
 
271
  # 按平台要求返回结果
272
+ # 按平台要求返回结果(用 sb64/cb64 替换 to_json())
273
  return {
274
  "code": 200,
275
  "message": "success",
276
  "data": {
277
  "html_report": html_report if html_report else "",
278
+ # 直接用已有的base64字符串,不用再转json!
279
+ "sankey_image": sb64 if sb64 else "", # 键名改成sankey_image(符合平台图片命名规范)
280
+ "cluster_image": cb64 if cb64 else "", # 键名改成cluster_image
281
+ "statistics": formatted_stats if formatted_stats else [] # 格式化后的统计数据
282
  }
283
  }
284
  except Exception as e: