UPDATE
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
from farm_data.models import SensorData
|
||||
from rag.api_provider import get_chat_client
|
||||
from rag.chat import (
|
||||
_complete_audit_log,
|
||||
@@ -78,13 +79,24 @@ def get_fertilization_recommendation(
|
||||
|
||||
user_query = query or "توصیه کودهی برای مزرعه من چیست؟"
|
||||
|
||||
sensor = (
|
||||
SensorData.objects.prefetch_related("plants")
|
||||
.filter(farm_uuid=sensor_uuid)
|
||||
.first()
|
||||
)
|
||||
resolved_plant_name = plant_name
|
||||
if not resolved_plant_name and sensor is not None:
|
||||
plant = sensor.plants.first()
|
||||
if plant is not None:
|
||||
resolved_plant_name = plant.name
|
||||
|
||||
context = build_rag_context(
|
||||
user_query, sensor_uuid, config=cfg, limit=limit, kb_name=KB_NAME, service_id=SERVICE_ID,
|
||||
)
|
||||
|
||||
extra_parts: list[str] = []
|
||||
if plant_name and growth_stage:
|
||||
plant_text = build_plant_text(plant_name, growth_stage)
|
||||
if resolved_plant_name and growth_stage:
|
||||
plant_text = build_plant_text(resolved_plant_name, growth_stage)
|
||||
if plant_text:
|
||||
extra_parts.append("[اطلاعات گیاه]\n" + plant_text)
|
||||
if extra_parts:
|
||||
|
||||
@@ -83,12 +83,20 @@ def get_irrigation_recommendation(
|
||||
|
||||
user_query = query or "توصیه آبیاری برای مزرعه من چیست؟"
|
||||
|
||||
sensor = SensorData.objects.select_related("center_location").prefetch_related("plants").filter(farm_uuid=sensor_uuid).first()
|
||||
sensor = (
|
||||
SensorData.objects.select_related("center_location", "irrigation_method")
|
||||
.prefetch_related("plants")
|
||||
.filter(farm_uuid=sensor_uuid)
|
||||
.first()
|
||||
)
|
||||
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
|
||||
crop_profile = resolve_crop_profile(plant, growth_stage=growth_stage)
|
||||
active_kc = resolve_kc(crop_profile, growth_stage=growth_stage)
|
||||
forecasts = []
|
||||
@@ -99,11 +107,18 @@ def get_irrigation_recommendation(
|
||||
.order_by("forecast_date")[:7]
|
||||
)
|
||||
efficiency_percent = None
|
||||
resolved_irrigation_method_name = irrigation_method_name
|
||||
method = None
|
||||
if irrigation_method_name:
|
||||
from irrigation.models import IrrigationMethod
|
||||
|
||||
method = IrrigationMethod.objects.filter(name=irrigation_method_name).first()
|
||||
efficiency_percent = getattr(method, "water_efficiency_percent", None) if method else None
|
||||
elif sensor is not None:
|
||||
method = sensor.irrigation_method
|
||||
if method is not None:
|
||||
resolved_irrigation_method_name = method.name
|
||||
|
||||
efficiency_percent = getattr(method, "water_efficiency_percent", None) if method else None
|
||||
daily_water_needs = calculate_forecast_water_needs(
|
||||
forecasts=forecasts,
|
||||
latitude_deg=float(sensor.center_location.latitude),
|
||||
@@ -117,12 +132,15 @@ def get_irrigation_recommendation(
|
||||
)
|
||||
|
||||
extra_parts: list[str] = []
|
||||
if plant_name and growth_stage:
|
||||
plant_text = build_plant_text(plant_name, growth_stage)
|
||||
resolved_irrigation_method_name = irrigation_method_name or (
|
||||
sensor.irrigation_method.name if sensor is not None and sensor.irrigation_method else None
|
||||
)
|
||||
if resolved_plant_name and growth_stage:
|
||||
plant_text = build_plant_text(resolved_plant_name, growth_stage)
|
||||
if plant_text:
|
||||
extra_parts.append("[اطلاعات گیاه]\n" + plant_text)
|
||||
if irrigation_method_name:
|
||||
method_text = build_irrigation_method_text(irrigation_method_name)
|
||||
if resolved_irrigation_method_name:
|
||||
method_text = build_irrigation_method_text(resolved_irrigation_method_name)
|
||||
if method_text:
|
||||
extra_parts.append("[روش آبیاری انتخابی]\n" + method_text)
|
||||
if daily_water_needs:
|
||||
|
||||
Reference in New Issue
Block a user