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
|
||||
|
||||
Reference in New Issue
Block a user