UPDATE
This commit is contained in:
@@ -13,6 +13,7 @@ from typing import Any
|
||||
from django.apps import apps
|
||||
|
||||
from farm_data.models import SensorData
|
||||
from farm_data.services import clone_snapshot_as_runtime_plant, get_farm_plant_snapshot_by_name
|
||||
from rag.api_provider import get_chat_client
|
||||
from rag.chat import (
|
||||
_complete_audit_log,
|
||||
@@ -623,7 +624,7 @@ def get_fertilization_recommendation(
|
||||
|
||||
sensor = (
|
||||
SensorData.objects.select_related("center_location")
|
||||
.prefetch_related("plants")
|
||||
.prefetch_related("plant_assignments__plant")
|
||||
.filter(farm_uuid=resolved_farm_uuid)
|
||||
.first()
|
||||
)
|
||||
@@ -635,20 +636,14 @@ def get_fertilization_recommendation(
|
||||
resolved_growth_stage = plant_config.resolve_growth_stage(growth_stage)
|
||||
|
||||
plant = None
|
||||
if not resolved_plant_name and sensor is not None:
|
||||
plant = sensor.plants.first()
|
||||
if plant is not None:
|
||||
resolved_plant_name = plant.name
|
||||
elif resolved_plant_name:
|
||||
if sensor is not None:
|
||||
plant = sensor.plants.filter(name=resolved_plant_name).first()
|
||||
if plant is None:
|
||||
Plant = apps.get_model("plant", "Plant")
|
||||
plant = Plant.objects.filter(name=resolved_plant_name).first()
|
||||
if plant is None and sensor is not None:
|
||||
plant = sensor.plants.first()
|
||||
if plant is not None:
|
||||
resolved_plant_name = plant.name
|
||||
if sensor is not None:
|
||||
selected_snapshot = get_farm_plant_snapshot_by_name(sensor, resolved_plant_name)
|
||||
plant = clone_snapshot_as_runtime_plant(
|
||||
selected_snapshot,
|
||||
growth_stage=resolved_growth_stage,
|
||||
)
|
||||
if selected_snapshot is not None:
|
||||
resolved_plant_name = selected_snapshot.name
|
||||
|
||||
forecasts = []
|
||||
optimized_result = None
|
||||
|
||||
@@ -10,6 +10,10 @@ from django.apps import apps
|
||||
from django.db import transaction
|
||||
|
||||
from farm_data.models import SensorData
|
||||
from farm_data.services import (
|
||||
clone_snapshot_as_runtime_plant,
|
||||
get_farm_plant_snapshot_by_name,
|
||||
)
|
||||
from irrigation.evapotranspiration import (
|
||||
calculate_forecast_water_needs,
|
||||
resolve_crop_profile,
|
||||
@@ -372,7 +376,7 @@ def get_irrigation_recommendation(
|
||||
|
||||
sensor = (
|
||||
SensorData.objects.select_related("center_location", "irrigation_method")
|
||||
.prefetch_related("plants")
|
||||
.prefetch_related("plant_assignments__plant")
|
||||
.filter(farm_uuid=resolved_farm_uuid)
|
||||
.first()
|
||||
)
|
||||
@@ -381,12 +385,16 @@ def get_irrigation_recommendation(
|
||||
|
||||
plant = None
|
||||
resolved_plant_name = plant_name
|
||||
if sensor is not None and plant_name:
|
||||
plant = sensor.plants.filter(name=plant_name).first()
|
||||
elif sensor is not None:
|
||||
plant = sensor.plants.first()
|
||||
if plant is not None:
|
||||
resolved_plant_name = plant.name
|
||||
if sensor is not None:
|
||||
selected_snapshot = get_farm_plant_snapshot_by_name(sensor, plant_name)
|
||||
plant = clone_snapshot_as_runtime_plant(
|
||||
selected_snapshot,
|
||||
growth_stage=growth_stage,
|
||||
)
|
||||
if selected_snapshot is not None:
|
||||
resolved_plant_name = selected_snapshot.name
|
||||
elif plant_name:
|
||||
resolved_plant_name = plant_name
|
||||
|
||||
crop_profile = resolve_crop_profile(plant, growth_stage=growth_stage)
|
||||
active_kc = resolve_kc(crop_profile, growth_stage=growth_stage)
|
||||
|
||||
Reference in New Issue
Block a user