UPDATE
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from farm_data.services import clone_snapshot_as_runtime_plant, get_primary_plant_snapshot
|
||||
from farm_data.services import build_ai_farm_snapshot, clone_snapshot_as_runtime_plant, get_primary_plant_snapshot, get_ai_snapshot_weather
|
||||
from irrigation.evapotranspiration import calculate_forecast_water_needs, resolve_crop_profile
|
||||
|
||||
from farm_data.models import SensorData
|
||||
@@ -11,7 +11,7 @@ from rag.services import get_water_need_prediction_insight
|
||||
from .services import get_forecast_for_location
|
||||
|
||||
|
||||
def build_water_need_prediction_payload(*, sensor: Any, forecasts: list[Any]) -> dict[str, Any]:
|
||||
def build_water_need_prediction_payload(*, sensor: Any, forecasts: list[Any], ai_snapshot: dict[str, Any] | None = None) -> dict[str, Any]:
|
||||
location = getattr(sensor, "center_location", None)
|
||||
plant = clone_snapshot_as_runtime_plant(get_primary_plant_snapshot(sensor))
|
||||
irrigation_method = getattr(sensor, "irrigation_method", None)
|
||||
@@ -46,6 +46,17 @@ def build_water_need_prediction_payload(*, sensor: Any, forecasts: list[Any]) ->
|
||||
"dailyBreakdown": daily,
|
||||
"cropProfile": crop_profile,
|
||||
"irrigationEfficiencyPercent": efficiency,
|
||||
"source_metadata": {
|
||||
"agronomic_metrics": {
|
||||
"source": "build_ai_farm_snapshot",
|
||||
"policy": "cluster_block_farm_aggregated",
|
||||
"available": bool(ai_snapshot),
|
||||
},
|
||||
"weather": {
|
||||
"source": "center_location_forecast",
|
||||
"policy": "center_location_latest_forecast",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +72,8 @@ class WaterNeedPredictionService:
|
||||
raise ValueError("Farm not found.")
|
||||
|
||||
forecasts = get_forecast_for_location(sensor.center_location, days=7)
|
||||
payload = build_water_need_prediction_payload(sensor=sensor, forecasts=forecasts)
|
||||
ai_snapshot = build_ai_farm_snapshot(farm_uuid)
|
||||
payload = build_water_need_prediction_payload(sensor=sensor, forecasts=forecasts, ai_snapshot=ai_snapshot)
|
||||
insight = get_water_need_prediction_insight(
|
||||
farm_uuid=farm_uuid,
|
||||
prediction_payload=payload,
|
||||
|
||||
Reference in New Issue
Block a user