|
@@ -325,6 +325,66 @@ def write_demand_items_to_mysql(execution_id: int, merge_level2: str) -> int:
|
|
|
return len(rows)
|
|
return len(rows)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def write_global_tree_demand_items_to_hive(execution_id: int, merge_level2: str) -> int:
|
|
|
|
|
+ """
|
|
|
|
|
+ 把 result/{execution_id}/execution_id_{execution_id}_demand_items.json
|
|
|
|
|
+ 写入 Hive 表 feature_point_data(仅全局树场景)。
|
|
|
|
|
+ """
|
|
|
|
|
+ demand_items_path = (
|
|
|
|
|
+ Path.cwd()
|
|
|
|
|
+ / "result"
|
|
|
|
|
+ / str(execution_id)
|
|
|
|
|
+ / f"execution_id_{execution_id}_demand_items.json"
|
|
|
|
|
+ )
|
|
|
|
|
+ if not demand_items_path.exists():
|
|
|
|
|
+ alt_path = (
|
|
|
|
|
+ Path(__file__).parent
|
|
|
|
|
+ / "result"
|
|
|
|
|
+ / str(execution_id)
|
|
|
|
|
+ / f"execution_id_{execution_id}_demand_items.json"
|
|
|
|
|
+ )
|
|
|
|
|
+ if alt_path.exists():
|
|
|
|
|
+ demand_items_path = alt_path
|
|
|
|
|
+ else:
|
|
|
|
|
+ log(f"[hive] 未找到需求 JSON:{demand_items_path}(也未找到 {alt_path}),跳过写入")
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ with open(demand_items_path, "r", encoding="utf-8") as f:
|
|
|
|
|
+ loaded = json.load(f)
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ log(f"[hive] 读取需求 JSON 失败:{demand_items_path},error={e}")
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+ items = loaded["items"] if isinstance(loaded, dict) and isinstance(loaded.get("items"), list) else loaded
|
|
|
|
|
+ if not isinstance(items, list):
|
|
|
|
|
+ log(f"[hive] 需求 JSON 非数组,跳过写入:type={type(items)}")
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+ names: list[str] = []
|
|
|
|
|
+ for di in items:
|
|
|
|
|
+ if not isinstance(di, dict):
|
|
|
|
|
+ continue
|
|
|
|
|
+ name = _join_element_names_to_name(di.get("element_names"))
|
|
|
|
|
+ if name:
|
|
|
|
|
+ names.append(name)
|
|
|
|
|
+
|
|
|
|
|
+ if not names:
|
|
|
|
|
+ log("[hive] 无有效 name,跳过写入")
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ # 按用户要求:Hive 写入逻辑放在 data_query_tools.py 中。
|
|
|
|
|
+ from examples.demand.data_query_tools import write_feature_point_data_to_hive
|
|
|
|
|
+
|
|
|
|
|
+ written = write_feature_point_data_to_hive(names=names)
|
|
|
|
|
+ log(f"[hive] 写入 feature_point_data 完成,rows={written}")
|
|
|
|
|
+ return written
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ log(f"[hive] 写入 feature_point_data 异常:{e}")
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async def run_once(execution_id, merge_level2, count: int = 30, task_id: Optional[int] = None) -> str:
|
|
async def run_once(execution_id, merge_level2, count: int = 30, task_id: Optional[int] = None) -> str:
|
|
|
task_log_text = ""
|
|
task_log_text = ""
|
|
|
task_status = 0
|
|
task_status = 0
|
|
@@ -397,12 +457,15 @@ async def run_once(execution_id, merge_level2, count: int = 30, task_id: Optiona
|
|
|
|
|
|
|
|
log(f"[cost] total_tokens={total_tokens}, total_cost=${total_cost:.6f}")
|
|
log(f"[cost] total_tokens={total_tokens}, total_cost=${total_cost:.6f}")
|
|
|
|
|
|
|
|
- # agent 执行完成后:把本地 result JSON 写入 MySQL 表 demand_content
|
|
|
|
|
- # element_names -> name(逗号分隔);reason -> demand_content.reason;desc -> demand_content.suggestion;dt -> demand_content.dt
|
|
|
|
|
|
|
+ # agent 执行完成后:全局树写 Hive,其他写 MySQL
|
|
|
try:
|
|
try:
|
|
|
- write_demand_items_to_mysql(execution_id=execution_id, merge_level2=merge_level2)
|
|
|
|
|
|
|
+ if str(merge_level2).strip() == "全局树":
|
|
|
|
|
+ write_global_tree_demand_items_to_hive(execution_id=execution_id, merge_level2=merge_level2)
|
|
|
|
|
+ else:
|
|
|
|
|
+ # element_names -> name(逗号分隔);reason -> demand_content.reason;desc -> demand_content.suggestion;dt -> demand_content.dt
|
|
|
|
|
+ write_demand_items_to_mysql(execution_id=execution_id, merge_level2=merge_level2)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- log(f"[mysql] 写入 demand_content 异常:{e}")
|
|
|
|
|
|
|
+ log(f"[result-write] 写入结果异常:{e}")
|
|
|
|
|
|
|
|
task_log_text = log_buffer.getvalue()
|
|
task_log_text = log_buffer.getvalue()
|
|
|
task_status = 1
|
|
task_status = 1
|
|
@@ -456,5 +519,5 @@ async def main(
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
- asyncio.run(main('贪污腐败', 'piaoquan'))
|
|
|
|
|
|
|
+ asyncio.run(main('全局树', 'piaoquan', 50))
|
|
|
# write_demand_items_to_mysql(execution_id=8, merge_level2='贪污腐败')
|
|
# write_demand_items_to_mysql(execution_id=8, merge_level2='贪污腐败')
|