This commit is contained in:
2026-04-06 23:50:24 +03:30
parent a67236d45c
commit ff464cb4a5
140 changed files with 2061 additions and 2702 deletions
+4 -4
View File
@@ -6,7 +6,7 @@ import json
import logging
from irrigation.evapotranspiration import calculate_forecast_water_needs, resolve_crop_profile, resolve_kc
from sensor_data.models import SensorData
from farm_data.models import SensorData
from rag.api_provider import get_chat_client
from rag.chat import build_rag_context, _load_service_tone
from rag.config import load_rag_config, RAGConfig, get_service_config
@@ -77,7 +77,7 @@ def get_irrigation_recommendation(
user_query = query or "توصیه آبیاری برای مزرعه من چیست؟"
sensor = SensorData.objects.select_related("location").prefetch_related("plants").filter(uuid_sensor=sensor_uuid).first()
sensor = SensorData.objects.select_related("center_location").prefetch_related("plants").filter(farm_uuid=sensor_uuid).first()
plant = None
if sensor is not None and plant_name:
plant = sensor.plants.filter(name=plant_name).first()
@@ -89,7 +89,7 @@ def get_irrigation_recommendation(
daily_water_needs = []
if sensor is not None:
forecasts = list(
WeatherForecast.objects.filter(location=sensor.location, forecast_date__isnull=False)
WeatherForecast.objects.filter(location=sensor.center_location, forecast_date__isnull=False)
.order_by("forecast_date")[:7]
)
efficiency_percent = None
@@ -100,7 +100,7 @@ def get_irrigation_recommendation(
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.location.latitude),
latitude_deg=float(sensor.center_location.latitude),
crop_profile=crop_profile,
growth_stage=growth_stage,
irrigation_efficiency_percent=efficiency_percent,
+15 -15
View File
@@ -1,6 +1,6 @@
"""
ساخت دیتای خاک و هواشناسی کاربر از sensor_data، location_data و weather — Schema-agnostic
هر سنسور = یک کاربر. شناسایی با uuid_sensor.
ساخت دیتای خاک و هواشناسی کاربر از farm_data، location_data و weather — Schema-agnostic
هر سنسور = یک کاربر. شناسایی با farm_uuid.
مدل‌های Django داخل توابع import می‌شوند تا از AppRegistryNotReady جلوگیری شود.
"""
@@ -43,12 +43,12 @@ def build_user_soil_text(sensor_uuid: str) -> str | None:
Returns:
متن متنی قابل چانک، یا None اگر سنسور یافت نشد.
"""
from sensor_data.models import SensorData
from farm_data.models import SensorData
from location_data.models import SoilDepthData
try:
sensor = SensorData.objects.select_related("location").get(
uuid_sensor=sensor_uuid
sensor = SensorData.objects.select_related("center_location").get(
farm_uuid=sensor_uuid
)
except SensorData.DoesNotExist:
return None
@@ -56,17 +56,17 @@ def build_user_soil_text(sensor_uuid: str) -> str | None:
parts: list[str] = []
# شناسه سنسور
parts.append(f"سنسور: {sensor.uuid_sensor}")
parts.append(f"سنسور: {sensor.farm_uuid}")
# موقعیت مزرعه
loc = sensor.location
loc = sensor.center_location
parts.append(
f"موقعیت مزرعه: عرض {loc.latitude}، طول {loc.longitude}"
)
# خوانش‌های سنسور (schema-agnostic)
sensor_fields = _model_to_data_fields(
sensor, exclude={"uuid_sensor", "location_id", "location"}
sensor, exclude={"farm_uuid", "center_location_id", "center_location", "location"}
)
if sensor_fields:
sensor_lines = [f" {k}: {v}" for k, v in sorted(sensor_fields.items())]
@@ -94,12 +94,12 @@ def build_user_soil_text(sensor_uuid: str) -> str | None:
def get_all_sensor_uuids() -> list[str]:
"""لیست همه uuid_sensor های موجود."""
from sensor_data.models import SensorData
"""لیست همه farm_uuid های موجود."""
from farm_data.models import SensorData
return [
str(u) for u in
SensorData.objects.values_list("uuid_sensor", flat=True).distinct()
SensorData.objects.values_list("farm_uuid", flat=True).distinct()
]
@@ -111,17 +111,17 @@ def build_user_weather_text(sensor_uuid: str) -> str | None:
Returns:
متن فارسی ساختاریافته، یا None اگر داده‌ای نباشد.
"""
from sensor_data.models import SensorData
from farm_data.models import SensorData
from weather.models import WeatherForecast
try:
sensor = SensorData.objects.select_related("location").get(
uuid_sensor=sensor_uuid
sensor = SensorData.objects.select_related("center_location").get(
farm_uuid=sensor_uuid
)
except SensorData.DoesNotExist:
return None
loc = sensor.location
loc = sensor.center_location
forecasts = (
WeatherForecast.objects.filter(
location=loc,