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
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 |
-
#
|
| 797 |
-
top10 =
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
results = top10
|
| 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__":
|