网友小郑 9 mesi fa
parent
commit
1ceca4acc0
1 ha cambiato i file con 25 aggiunte e 25 eliminazioni
  1. 25 25
      app.py

+ 25 - 25
app.py

@@ -50,6 +50,7 @@ def inputMsg():
     # 生成提示信息
     # 定义输入信息变量
     # 生成提示信息
+
     prompt = f"""请扮演地理领域的智能选址文本提取工具,基于以下因子选择、选择范围和用地类型提取其对应的相关数据,提取结果中如景点转换为风景名胜区,农田转换为永久基本农田等,提取结果进行近义词转换为以下因子选择、选择范围和用地类型的相关数据
     因子选择:['天涯区','崖州区','海棠区','吉阳区' ,'抱坡区'],
     用地类型:['规划因子', '永久基本农田', '城镇开发边界内', '生态保护红线', '文化保护区', '自然保护地', '风景名胜区', '权属因子', '国有使用权', '防控因子', '河道管理线', '水库', '公益林', '地形因子', '坡度', '邻避因子', '火葬场', '垃圾处理场', '污水处理场', '高压线', '变电站', '古树', '市政设施', '交通', '城市道路', '主要出入口', '管线', '排水', '供水', '燃气', '电力', '电信', '公共服务设施', '十五分钟社区生活圈邻里中心', '社区服务设施', '零售商业场所', '医疗卫生设施', '教育场所', '幼儿园服务半径', '小学服务半径', '为老服务设施', '文化活动设施', '体育运动场所'],
@@ -60,6 +61,7 @@ def inputMsg():
     yxyz是因子选择,公里、千米的单位转换为米,
     输入以下信息:"{msg}",请基于因子选择、选址范围和用地类型,提取其对应的相关数据。结果以下面格式输出:
     {{"districtName":"天涯区","landType":"林地","area": {{ "min": 50,"max": 80}},"factors": [{{"type": "水库","condition": "大于","value": "100"}},{{"type": "小学服务半径","condition": "小于","value": "1000"}},{{"type": "永久基本农田","condition": "不相交" }}, {{"type": "城镇开发边界内","condition": "包含"}}]}},
+    结果中因子选择、选址范围和用地类型对应的数据,并进行近义词转换。
     """
 
     try:
@@ -85,6 +87,7 @@ def inputMsg():
 
 
 # 将大模型解析的结果转换为选址需要的数据格式
+
 def jsonResToDict(json_res):
     # 1.查询选址范围信息
     districtName = json_res["districtName"]
@@ -93,10 +96,12 @@ def jsonResToDict(json_res):
     geomId = saveGeom(ewkt)
     # 3.获取用地类型信息
     landType = json_res["landType"]
-    landType = getLandType(landType)
+    landType = getLandType(landType, "YDYHFLDM")
     # 4.获取模板信息
     factorTemplates = getTemplateByCode(landType)
 
+    # TODO 以哪个因子列表为准,模版和因子个数怎么匹配
+
     now = datetime.datetime.now()
     formatted_time = now.strftime("%Y%m%d%H%M%S")
     res = {
@@ -105,7 +110,7 @@ def jsonResToDict(json_res):
         "jsdw": "建设单位",
         "ydxz_bsm": landType,
         "ydmjbegin": json_res["ydmjbegin"],
-        "ydmjend":  json_res["ydmjbegin"],
+        "ydmjend":  json_res["ydmjend"],
         "geomId": geomId,
         "yxyz": [],
         # TODO: 循环遍历
@@ -124,8 +129,8 @@ def jsonResToDict(json_res):
         #         }
         #     }
         # ],
-        "useMultiple": json_res["multipleDistance"],
-        "useLandType": json_res["multipleDistance"],
+        "useMultiple": json_res["useMultiple"],
+        "useLandType": json_res["useLandType"],
         "multipleDistance": json_res["multipleDistance"]
     }
     # 循环遍历输入因子
@@ -133,6 +138,8 @@ def jsonResToDict(json_res):
     input_factors = {}
     for factor in factors:
         factorInfo = getFactorByName(factor["name"])
+        if factorInfo == None:
+            continue
         factorId = factorInfo["id"]
         factorBsm = factorInfo["bsm"]
         conditionInfo = factorInfo["condition_info"]
@@ -154,21 +161,12 @@ def jsonResToDict(json_res):
         input_factors[factor_info["id"]] = factor_info
     # 循环遍历模板
     for factorTemplate in factorTemplates:
-        factor_info = {
-            "id": factorId,
-            "name": factor["name"],
-            "bsm": factorBsm,
-            "conditionInfo": {
-                "spatial_type": conditionObj["spatial_type"],
-                "default": factor["default"],
-                "hasValue": conditionObj["hasValue"],
-                "defaultValue": factor["defaultValue"],
-                "unit": conditionObj["unit"],
-                "clip": conditionObj["clip"]
-            }
-        }
-        res["yxyz"].append(factor_info)
-
+        factorId = factorTemplate["factor_id"]
+        if factorId in input_factors:
+            res["yxyz"].append(input_factors[factorId])
+        else:
+            factorTemplate["condition_info"]=json.loads(factorTemplate["condition_info"])
+            res["yxyz"].append(factorTemplate)
     return res
 
 # 获取因子信息
@@ -193,7 +191,9 @@ def getTemplateByCode(code):
         logger.info(f"Executing SQL: {complete_sql}")
         cur.execute(sql, (code,))
         res = cur.fetchall()
-    return res
+        # 将查询结果转换为字典列表
+        result_list = [dict(row) for row in res]
+    return result_list
 
 # 获取选址范围信息
 
@@ -224,13 +224,13 @@ def saveGeom(ewkt):
 # 获取用地类型信息
 
 
-def getLandType(landName):
+def getLandType(landName, fzbs):
     with conn.cursor(cursor_factory=DictCursor) as cur:
-        sql = "SELECT dm,mc,fzbs FROM base.t_fzss_fzxz_dict WHERE mc = %s"
-        complete_sql = cur.mogrify(sql, (landName)).decode('utf-8')
+        sql = "SELECT dm,mc,fzbs FROM base.t_fzss_fzxz_dict WHERE mc = %s and fzbs=%s"
+        complete_sql = cur.mogrify(sql, (landName, fzbs)).decode('utf-8')
         logger.info(f"Executing SQL: {complete_sql}")
-        cur.execute(sql, (landName,))
-        res = cur.fetchall()
+        cur.execute(sql, (landName, fzbs))
+        res = cur.fetchone()
     return res["dm"]