Ken-INOUE commited on
Commit
6e55dc4
·
1 Parent(s): dca6b1b

Refactor analyze_variability_json to streamline top 10 results extraction by consolidating DataFrame operations. Update UI button click handling to ensure consistent output across UI and MCP functionalities.

Browse files
Files changed (1) hide show
  1. app.py +10 -17
app.py CHANGED
@@ -793,17 +793,17 @@ def analyze_variability_json(
793
  )
794
 
795
  if result_df is not None and not result_df.empty:
796
- # CV(%) が NaN の場合は除外して上位10件を抽出
797
- top10 = result_df.dropna(subset=["CV(%)"]).sort_values(
798
- by="CV(%)", ascending=False
799
- ).head(10)
800
-
801
- # 必要な列だけ残す
802
- results = top10[["項目名", "平均", "CV(%)", "スパイク数", "不安定判定"]].to_dict(orient="records")
803
  else:
804
  results = []
805
 
806
- return {
807
  "meta": {
808
  "datetime_str": datetime_str,
809
  "window_minutes": window_minutes,
@@ -914,18 +914,11 @@ with gr.Blocks(css=".gradio-container {overflow: auto !important;}") as demo:
914
  summary_output4 = gr.Textbox(label="サマリー")
915
  json_output4 = gr.Json(label="JSON結果")
916
 
917
- # ✅ UI
918
- run_btn4.click(
919
- analyze_variability,
920
- inputs=[datetime_str_global, window_minutes_global, cv_threshold4, jump_threshold4, mad_sigma4],
921
- outputs=[result_df4, summary_output4, json_output4]
922
- )
923
-
924
- # ✅ MCP用
925
  run_btn4.click(
926
  analyze_variability_json,
927
  inputs=[datetime_str_global, window_minutes_global, cv_threshold4, jump_threshold4, mad_sigma4],
928
- outputs=[json_output4]
929
  )
930
 
931
  if __name__ == "__main__":
 
793
  )
794
 
795
  if result_df is not None and not result_df.empty:
796
+ # 必要なカラムだけに絞り込んで上位10件
797
+ top10 = (
798
+ result_df.dropna(subset=["CV(%)"])
799
+ .sort_values(by="CV(%)", ascending=False)
800
+ .head(10)[["項目名", "平均", "CV(%)", "スパイク数", "不安定判定"]]
801
+ )
802
+ results = top10.to_dict(orient="records")
803
  else:
804
  results = []
805
 
806
+ return result_df, summary, {
807
  "meta": {
808
  "datetime_str": datetime_str,
809
  "window_minutes": window_minutes,
 
914
  summary_output4 = gr.Textbox(label="サマリー")
915
  json_output4 = gr.Json(label="JSON結果")
916
 
917
+ # ✅ UI + MCP 共通
 
 
 
 
 
 
 
918
  run_btn4.click(
919
  analyze_variability_json,
920
  inputs=[datetime_str_global, window_minutes_global, cv_threshold4, jump_threshold4, mad_sigma4],
921
+ outputs=[result_df4, summary_output4, json_output4]
922
  )
923
 
924
  if __name__ == "__main__":