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