From c375cd33d9daea96799e5e6f05b76b7b8388fa30 Mon Sep 17 00:00:00 2001 From: wzy-warehouse <18135009705@163.com> Date: Sun, 14 Jun 2026 15:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9D=A1=E4=BB=B6=E5=AD=98?= =?UTF-8?q?=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/earthquake.py | 3 ++- app/api/rainfall.py | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/api/earthquake.py b/app/api/earthquake.py index 03ee1f6..4625375 100644 --- a/app/api/earthquake.py +++ b/app/api/earthquake.py @@ -100,11 +100,12 @@ async def predict_earthquake(req: EarthquakePredictRequest): record_id = None if result_map: try: + # 存储经过默认值处理的条件(depth 默认值为 10.0) condition = { "point_ids": req.point_ids, "region_code": req.region_code, "magnitude": req.magnitude, - "depth": req.depth, + "depth": req.depth, # 已有默认值 10.0 "epicenter_lon": req.epicenter_lon, "epicenter_lat": req.epicenter_lat } diff --git a/app/api/rainfall.py b/app/api/rainfall.py index 6cb691e..0414a9a 100644 --- a/app/api/rainfall.py +++ b/app/api/rainfall.py @@ -52,7 +52,7 @@ def _predict_sync(point_ids: Optional[List[int]], region_code: Optional[str], 同步执行暴雨预测(在线程池中运行) Returns: - (结果map, 输入条件, 当前时间) + (结果map, 实际使用的降雨数据, 当前时间) """ points = _fetch_points(point_ids, region_code) if not points: @@ -62,13 +62,26 @@ def _predict_sync(point_ids: Optional[List[int]], region_code: Optional[str], raw_results = model.predict_multiple_points(points, rainfall=rainfall, duration=duration) result_map = _build_prediction_map(raw_results) - # 构建条件和结果用于保存 + # 获取实际使用的降雨数据(如果未传递,模型会从数据库查询) + actual_rainfall = rainfall + actual_duration = duration + if actual_rainfall is None or actual_duration is None: + # 获取第一个点的降雨数据作为参考 + from app.repositories.dbn_repository import DbnRepository + first_point = points[0] + rain_data = DbnRepository.get_rainfall_data_with_duration(first_point['lon'], first_point['lat']) + if actual_rainfall is None: + actual_rainfall = rain_data.get('accum_rain', 0.0) + if actual_duration is None: + actual_duration = rain_data.get('duration_hours', 0) + + # 构建经过默认值处理的条件用于保存 now = datetime.now() condition = { "point_ids": point_ids, "region_code": region_code, - "rainfall": rainfall, - "duration": duration + "rainfall": actual_rainfall, + "duration": actual_duration } return result_map, condition, now