Commit 031dfa1e by tinywell

1设备传感器数量查询接口接入;问题类型识别参数说明优化;工具返回数据结构精简

parent a086b59c
...@@ -161,7 +161,7 @@ class MonitorClient(BaseHttpClient): ...@@ -161,7 +161,7 @@ class MonitorClient(BaseHttpClient):
"deviceType": device_type "deviceType": device_type
} }
) )
return BaseResponse[List](**data) return BaseResponse[Dict](**data)
# 示例:添加新的数据接口客户端 # 示例:添加新的数据接口客户端
class RateClient(BaseHttpClient): class RateClient(BaseHttpClient):
......
...@@ -124,6 +124,20 @@ class RegionRateTool(BaseRateTool): ...@@ -124,6 +124,20 @@ class RegionRateTool(BaseRateTool):
for item in df.resultdata: for item in df.resultdata:
rate_date = self._extract_rate_data(item) rate_date = self._extract_rate_data(item)
result_data.append(rate_date) result_data.append(rate_date)
sorted_data = [rate_date[0]]
if len(result_data) > 1:
sorted_data.extend(sorted(result_data[1:], key=lambda x: x['在线率']))
# 将数据改成表格形式,表头提取之后,数据一行行显示
table_header = list(result_data[0].keys())
table_data = []
for item in result_data:
table_data.append(list(item.values()))
result_data = {
'table_header': table_header,
'table_data': table_data
}
data = { data = {
'region': region_name, 'region': region_name,
...@@ -161,6 +175,16 @@ class RegionRateTool(BaseRateTool): ...@@ -161,6 +175,16 @@ class RegionRateTool(BaseRateTool):
self.logger.debug(f"查询结果: {df.resultdata}") self.logger.debug(f"查询结果: {df.resultdata}")
# markdown = self.to_markdown(df.resultdata) # markdown = self.to_markdown(df.resultdata)
table_header = list(result_data[0].keys())
table_data = []
for item in result_data:
table_data.append(list(item.values()))
result_data = {
'table_header': table_header,
'table_data': table_data
}
data = { data = {
'region': region_name, 'region': region_name,
'region_code': code, 'region_code': code,
......
...@@ -26,7 +26,7 @@ DEFAULT_CONFIG = { ...@@ -26,7 +26,7 @@ DEFAULT_CONFIG = {
"API_BASE": "http://192.168.10.14:8000/v1", "API_BASE": "http://192.168.10.14:8000/v1",
"TOOL_BASE_URL": "http://localhost:5001", "TOOL_BASE_URL": "http://localhost:5001",
"API_KEY": "xxxxxxxxxxxxx", "API_KEY": "xxxxxxxxxxxxx",
"LOG_LEVEL": "DEBUG" "LOG_LEVEL": "INFO"
} }
def get_config(key: str, args: Optional[argparse.Namespace] = None) -> str: def get_config(key: str, args: Optional[argparse.Namespace] = None) -> str:
......
...@@ -80,10 +80,20 @@ def run_examples(): ...@@ -80,10 +80,20 @@ def run_examples():
"expected": { "expected": {
"tool": "monitor_points_query", "tool": "monitor_points_query",
"params": { "params": {
"key": "甘肃省陇南市" "key": "甘肃省"
}
}
},{
"query": "贵阳市的雨量传感器有多少",
"expected": {
"tool": "monitor_points_query",
"params": {
"key": "贵阳市",
"device_type": "雨量",
"query_type": "2",
}
} }
} }
},
] ]
# 为每个测试案例创建一个表格 # 为每个测试案例创建一个表格
...@@ -120,10 +130,10 @@ def run_examples(): ...@@ -120,10 +130,10 @@ def run_examples():
"✓" if expected_value == actual_value else "✗" "✓" if expected_value == actual_value else "✗"
) )
# run tool # # run tool
tool = tools_dict[actual_tool] # tool = tools_dict[actual_tool]
result = tool.invoke(result["params"]) # result = tool.invoke(result["params"])
print(result) # print(result)
except Exception as e: except Exception as e:
table.add_row("错误", "", str(e), "✗") table.add_row("错误", "", str(e), "✗")
......
...@@ -44,6 +44,7 @@ def run_examples(): ...@@ -44,6 +44,7 @@ def run_examples():
"start_time": "2024-04-01 00:00:00", "start_time": "2024-04-01 00:00:00",
"end_time": "2024-05-31 23:59:59", "end_time": "2024-05-31 23:59:59",
"region_name": "甘肃省", "region_name": "甘肃省",
"query_type": "1",
} }
} }
},{ },{
...@@ -64,6 +65,7 @@ def run_examples(): ...@@ -64,6 +65,7 @@ def run_examples():
"start_time": "2024-01-01 00:00:00", "start_time": "2024-01-01 00:00:00",
"end_time": "2024-12-31 23:59:59", "end_time": "2024-12-31 23:59:59",
"region_name": "甘肃省", "region_name": "甘肃省",
"query_type": "2",
} }
} }
},{ },{
...@@ -74,6 +76,7 @@ def run_examples(): ...@@ -74,6 +76,7 @@ def run_examples():
"start_time": "2024-01-01 00:00:00", "start_time": "2024-01-01 00:00:00",
"end_time": "2024-06-30 23:59:59", "end_time": "2024-06-30 23:59:59",
"region_name": "甘肃省", "region_name": "甘肃省",
"query_type": "1",
} }
} }
} }
...@@ -113,11 +116,11 @@ def run_examples(): ...@@ -113,11 +116,11 @@ def run_examples():
"✓" if expected_value == actual_value else "✗" "✓" if expected_value == actual_value else "✗"
) )
tool = tool_dict[result["tool"]] # tool = tool_dict[result["tool"]]
params = result["params"] # params = result["params"]
result = tool.invoke(params) # result = tool.invoke(params)
print(result) # print(result)
except Exception as e: except Exception as e:
table.add_row("错误", "", str(e), "✗") table.add_row("错误", "", str(e), "✗")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment