添加降雨量与持续时间接口

This commit is contained in:
wzy-warehouse
2026-06-28 09:26:13 +08:00
parent 54f7300557
commit 1f01ceb062
6 changed files with 240 additions and 16 deletions
+20 -1
View File
@@ -195,6 +195,7 @@ class DbnRepository:
COUNT(*) as record_count
FROM xian_meteorology
WHERE datetime BETWEEN %s AND %s
AND is_delete = 0
AND rainfall_1h IS NOT NULL
AND CAST(rainfall_1h AS DOUBLE PRECISION) > 0
GROUP BY lon, lat
@@ -259,6 +260,7 @@ class DbnRepository:
ST_SetSRID(ST_MakePoint(%s, %s), 4326)
) as dist
FROM xian_meteorology
WHERE is_delete = 0
) t
WHERE dist < 50000
ORDER BY dist
@@ -283,6 +285,7 @@ class DbnRepository:
CAST(rainfall_1h AS DOUBLE PRECISION) as rainfall
FROM xian_meteorology
WHERE lon = %s AND lat = %s
AND is_delete = 0
AND datetime BETWEEN %s AND %s
ORDER BY datetime DESC
"""
@@ -326,7 +329,7 @@ class DbnRepository:
"""一次性加载所有气象站点坐标到内存(188个站点,约2KB)"""
if cls._cached_stations is not None:
return cls._cached_stations
sql = "SELECT DISTINCT lon, lat FROM xian_meteorology"
sql = "SELECT DISTINCT lon, lat FROM xian_meteorology WHERE is_delete = 0"
cls._cached_stations = db_helper.execute_query(sql)
logger.info(f"已缓存 {len(cls._cached_stations)} 个气象站点坐标")
return cls._cached_stations
@@ -407,6 +410,7 @@ class DbnRepository:
SELECT lon, lat, datetime, CAST(rainfall_1h AS DOUBLE PRECISION) as rainfall
FROM xian_meteorology
WHERE (lon, lat) IN ({placeholders})
AND is_delete = 0
AND datetime BETWEEN %s AND %s
ORDER BY lon, lat, datetime DESC
"""
@@ -688,6 +692,21 @@ class DbnRepository:
return float(result['aspect'])
return None
@staticmethod
def get_inference_result(inference_id: int) -> Optional[Dict[str, Any]]:
"""
根据ID获取推理结果
Returns:
{id, name, event_type, occurred_time, operation_type, condition, result}
"""
sql = """
SELECT id, name, event_type, occurred_time, operation_type, condition, result
FROM xian_inference_result
WHERE id = %s AND is_delete = 0
"""
return db_helper.execute_query_one(sql, (inference_id,))
@staticmethod
def save_inference_result(disaster_name: str, event_type: str, occurred_time, operation_type: str,
condition: dict, result: list) -> int: