修改条件存储
This commit is contained in:
@@ -100,11 +100,12 @@ async def predict_earthquake(req: EarthquakePredictRequest):
|
|||||||
record_id = None
|
record_id = None
|
||||||
if result_map:
|
if result_map:
|
||||||
try:
|
try:
|
||||||
|
# 存储经过默认值处理的条件(depth 默认值为 10.0)
|
||||||
condition = {
|
condition = {
|
||||||
"point_ids": req.point_ids,
|
"point_ids": req.point_ids,
|
||||||
"region_code": req.region_code,
|
"region_code": req.region_code,
|
||||||
"magnitude": req.magnitude,
|
"magnitude": req.magnitude,
|
||||||
"depth": req.depth,
|
"depth": req.depth, # 已有默认值 10.0
|
||||||
"epicenter_lon": req.epicenter_lon,
|
"epicenter_lon": req.epicenter_lon,
|
||||||
"epicenter_lat": req.epicenter_lat
|
"epicenter_lat": req.epicenter_lat
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-4
@@ -52,7 +52,7 @@ def _predict_sync(point_ids: Optional[List[int]], region_code: Optional[str],
|
|||||||
同步执行暴雨预测(在线程池中运行)
|
同步执行暴雨预测(在线程池中运行)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(结果map, 输入条件, 当前时间)
|
(结果map, 实际使用的降雨数据, 当前时间)
|
||||||
"""
|
"""
|
||||||
points = _fetch_points(point_ids, region_code)
|
points = _fetch_points(point_ids, region_code)
|
||||||
if not points:
|
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)
|
raw_results = model.predict_multiple_points(points, rainfall=rainfall, duration=duration)
|
||||||
result_map = _build_prediction_map(raw_results)
|
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()
|
now = datetime.now()
|
||||||
condition = {
|
condition = {
|
||||||
"point_ids": point_ids,
|
"point_ids": point_ids,
|
||||||
"region_code": region_code,
|
"region_code": region_code,
|
||||||
"rainfall": rainfall,
|
"rainfall": actual_rainfall,
|
||||||
"duration": duration
|
"duration": actual_duration
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_map, condition, now
|
return result_map, condition, now
|
||||||
|
|||||||
Reference in New Issue
Block a user