UPDATE
This commit is contained in:
@@ -2,6 +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 irrigation.evapotranspiration import calculate_forecast_water_needs, resolve_crop_profile
|
||||
|
||||
from farm_data.models import SensorData
|
||||
@@ -12,8 +13,7 @@ from .services import get_forecast_for_location
|
||||
|
||||
def build_water_need_prediction_payload(*, sensor: Any, forecasts: list[Any]) -> dict[str, Any]:
|
||||
location = getattr(sensor, "center_location", None)
|
||||
plants = list(sensor.plants.all()) if hasattr(sensor, "plants") else []
|
||||
plant = plants[0] if plants else None
|
||||
plant = clone_snapshot_as_runtime_plant(get_primary_plant_snapshot(sensor))
|
||||
irrigation_method = getattr(sensor, "irrigation_method", None)
|
||||
|
||||
if not forecasts or location is None:
|
||||
@@ -53,7 +53,7 @@ class WaterNeedPredictionService:
|
||||
def get_water_need_prediction(self, *, farm_uuid: str) -> dict[str, Any]:
|
||||
sensor = (
|
||||
SensorData.objects.select_related("center_location", "irrigation_method")
|
||||
.prefetch_related("plants")
|
||||
.prefetch_related("plant_assignments__plant")
|
||||
.filter(farm_uuid=farm_uuid)
|
||||
.first()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user