添加灾害名称
This commit is contained in:
@@ -88,6 +88,7 @@ async def predict_earthquake(req: EarthquakePredictRequest):
|
||||
"""
|
||||
根据震级、震源深度和震中位置,批量预测隐患点/风险点的次生灾害概率和等级。
|
||||
|
||||
- **disaster_name**: 灾害名称
|
||||
- **point_ids**: 点位ID列表(可选,不传则查询所有点)
|
||||
- **region_code**: 行政区划代码(可选,不传则不限区域)
|
||||
- **magnitude**: 震级(Richter)
|
||||
@@ -123,6 +124,7 @@ async def predict_earthquake(req: EarthquakePredictRequest):
|
||||
"epicenter_lat": req.epicenter_lat
|
||||
}
|
||||
record_id = dbn_repository.save_inference_result(
|
||||
disaster_name=req.disaster_name,
|
||||
event_type="earthquake",
|
||||
occurred_time=req.occurred_time,
|
||||
operation_type=req.operation_type,
|
||||
|
||||
@@ -121,6 +121,7 @@ async def predict_rainfall(req: RainfallPredictRequest):
|
||||
"""
|
||||
根据降雨量和持续时间,批量预测隐患点/风险点的灾害概率和等级。
|
||||
|
||||
- **disaster_name**: 灾害名称
|
||||
- **point_ids**: 点位ID列表(可选,不传则查询所有点)
|
||||
- **region_code**: 行政区划代码(可选,不传则不限区域)
|
||||
- **rainfall**: 累计降雨量(mm),不传则从气象表自动获取
|
||||
@@ -145,6 +146,7 @@ async def predict_rainfall(req: RainfallPredictRequest):
|
||||
if save_results:
|
||||
try:
|
||||
record_id = dbn_repository.save_inference_result(
|
||||
disaster_name=req.disaster_name,
|
||||
event_type="rainfall",
|
||||
occurred_time=now,
|
||||
operation_type=req.operation_type,
|
||||
|
||||
@@ -689,12 +689,13 @@ class DbnRepository:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def save_inference_result(event_type: str, occurred_time, operation_type: str,
|
||||
def save_inference_result(disaster_name: str, event_type: str, occurred_time, operation_type: str,
|
||||
condition: dict, result: list) -> int:
|
||||
"""
|
||||
保存推理结果到 inference_result 表
|
||||
|
||||
Args:
|
||||
disaster_name: 灾害名称
|
||||
event_type: 事件类型('rainfall' 或 'earthquake')
|
||||
occurred_time: 事件发生时间
|
||||
operation_type: 操作类型
|
||||
@@ -706,11 +707,12 @@ class DbnRepository:
|
||||
"""
|
||||
import json
|
||||
sql = """
|
||||
INSERT INTO xian_inference_result (event_type, occurred_time, operation_type, condition, result)
|
||||
VALUES (%s, %s, %s, %s::jsonb, %s::jsonb)
|
||||
INSERT INTO xian_inference_result (name, event_type, occurred_time, operation_type, condition, result)
|
||||
VALUES (%s, %s, %s, %s, %s::jsonb, %s::jsonb)
|
||||
RETURNING id
|
||||
"""
|
||||
row = db_helper.execute_query_one(sql, (
|
||||
disaster_name,
|
||||
event_type,
|
||||
occurred_time,
|
||||
operation_type,
|
||||
|
||||
@@ -12,6 +12,7 @@ from pydantic import BaseModel, Field
|
||||
|
||||
class RainfallPredictRequest(BaseModel):
|
||||
"""暴雨灾害链预测请求"""
|
||||
disaster_name: str = Field(min_length=1, max_length=255)
|
||||
point_ids: Optional[List[int]] = Field(None, max_length=500,
|
||||
description="点位ID列表,不传则查询所有点")
|
||||
region_code: Optional[str] = Field(None, description="行政区划代码(如 '610104'),不传则不限区域")
|
||||
@@ -29,6 +30,7 @@ class RainfallPredictRequest(BaseModel):
|
||||
|
||||
class EarthquakePredictRequest(BaseModel):
|
||||
"""地震灾害链预测请求"""
|
||||
disaster_name: str = Field(min_length=1, max_length=255)
|
||||
point_ids: Optional[List[int]] = Field(None, max_length=500,
|
||||
description="点位ID列表,不传则查询所有点")
|
||||
region_code: Optional[str] = Field(None, description="行政区划代码(如 '610104'),不传则不限区域")
|
||||
|
||||
Reference in New Issue
Block a user