This commit is contained in:
2026-04-24 02:50:27 +03:30
parent 302124aa87
commit a76af4e766
20 changed files with 430 additions and 147 deletions
+24 -6
View File
@@ -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: