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
+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,