This commit is contained in:
2026-04-24 22:20:15 +03:30
parent f7dc05dc9e
commit 569d520a5c
24 changed files with 687 additions and 152 deletions
+1
View File
@@ -12,6 +12,7 @@ class IrrigationConfig(AppConfig):
@cached_property
def optimizer_defaults(self):
return {
"simulation_model": "Wofost81_NWLP_CWB_CNB",
"validity_days": 3,
"minimum_event_mm": 4.0,
"significant_rain_threshold_mm": 4.0,
+9 -1
View File
@@ -28,7 +28,8 @@ class IrrigationMethodSerializer(serializers.ModelSerializer):
class IrrigationRecommendRequestSerializer(serializers.Serializer):
"""سریالایزر ورودی برای درخواست توصیه آبیاری."""
sensor_uuid = serializers.CharField(help_text="شناسه یکتای سنسور (اجباری)")
farm_uuid = serializers.CharField(required=False, help_text="شناسه یکتای مزرعه (اجباری)")
sensor_uuid = serializers.CharField(required=False, help_text="نام قدیمی برای farm_uuid")
plant_name = serializers.CharField(required=False, allow_blank=True, help_text="نام گیاه")
growth_stage = serializers.CharField(required=False, allow_blank=True, help_text="مرحله رشد گیاه")
irrigation_method_name = serializers.CharField(
@@ -36,6 +37,13 @@ class IrrigationRecommendRequestSerializer(serializers.Serializer):
)
query = serializers.CharField(required=False, allow_blank=True, help_text="سوال اختیاری")
def validate(self, attrs):
farm_uuid = attrs.get("farm_uuid") or attrs.get("sensor_uuid")
if not farm_uuid:
raise serializers.ValidationError({"farm_uuid": "farm_uuid الزامی است."})
attrs["farm_uuid"] = farm_uuid
return attrs
class IrrigationPlanSerializer(serializers.Serializer):
"""سریالایزر خروجی برای پلن توصیه آبیاری."""
+4 -4
View File
@@ -107,7 +107,7 @@ class IrrigationMethodListCreateView(APIView):
class IrrigationRecommendView(APIView):
"""
توصیه آبیاری به صورت مستقیم.
POST با sensor_uuid، plant_name، growth_stage، irrigation_method_name.
POST با farm_uuid، plant_name، growth_stage، irrigation_method_name.
اطلاعات گیاه از plant app و روش آبیاری از irrigation app دریافت می‌شود.
"""
@@ -139,7 +139,7 @@ class IrrigationRecommendView(APIView):
OpenApiExample(
"نمونه درخواست",
value={
"sensor_uuid": "550e8400-e29b-41d4-a716-446655440000",
"farm_uuid": "550e8400-e29b-41d4-a716-446655440000",
"plant_name": "گوجه‌فرنگی",
"growth_stage": "گلدهی",
"irrigation_method_name": "آبیاری قطره‌ای",
@@ -159,7 +159,7 @@ class IrrigationRecommendView(APIView):
)
validated = serializer.validated_data
sensor_uuid = validated["sensor_uuid"]
farm_uuid = validated["farm_uuid"]
plant_name = validated.get("plant_name")
growth_stage = validated.get("growth_stage")
irrigation_method_name = validated.get("irrigation_method_name")
@@ -167,7 +167,7 @@ class IrrigationRecommendView(APIView):
try:
result = get_irrigation_recommendation(
sensor_uuid=sensor_uuid,
farm_uuid=farm_uuid,
plant_name=plant_name,
growth_stage=growth_stage,
irrigation_method_name=irrigation_method_name,