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)
|
||||
|
||||
+5
-25
@@ -166,36 +166,16 @@ def load_user_sources() -> list[tuple[str, str]]:
|
||||
|
||||
def build_plant_text(plant_name: str, growth_stage: str) -> str | None:
|
||||
"""
|
||||
ساخت متن اطلاعات گیاه از جدول Plant برای استفاده در context LLM.
|
||||
ساخت متن اطلاعات گیاه از snapshotهای `farm_data` برای استفاده در context LLM.
|
||||
"""
|
||||
from plant.models import Plant
|
||||
from farm_data.models import PlantCatalogSnapshot
|
||||
from farm_data.services import build_plant_text_from_snapshot
|
||||
|
||||
plant = Plant.objects.filter(name=plant_name).first()
|
||||
plant = PlantCatalogSnapshot.objects.filter(name=plant_name).first()
|
||||
if not plant:
|
||||
return None
|
||||
|
||||
lines = [
|
||||
f"نام گیاه: {plant.name}",
|
||||
f"مرحله رشد: {growth_stage}",
|
||||
]
|
||||
if plant.light:
|
||||
lines.append(f"نور مورد نیاز: {plant.light}")
|
||||
if plant.watering:
|
||||
lines.append(f"آبیاری: {plant.watering}")
|
||||
if plant.soil:
|
||||
lines.append(f"خاک مناسب: {plant.soil}")
|
||||
if plant.temperature:
|
||||
lines.append(f"دمای مناسب: {plant.temperature}")
|
||||
if plant.planting_season:
|
||||
lines.append(f"فصل کاشت: {plant.planting_season}")
|
||||
if plant.harvest_time:
|
||||
lines.append(f"زمان برداشت: {plant.harvest_time}")
|
||||
if plant.spacing:
|
||||
lines.append(f"فاصله کاشت: {plant.spacing}")
|
||||
if plant.fertilizer:
|
||||
lines.append(f"کود مناسب: {plant.fertilizer}")
|
||||
|
||||
return "\n".join(lines)
|
||||
return build_plant_text_from_snapshot(plant, growth_stage)
|
||||
|
||||
|
||||
def build_irrigation_method_text(method_name: str) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user