UPDATE
This commit is contained in:
+18
-16
@@ -148,7 +148,7 @@ class ChatView(APIView):
|
||||
class IrrigationRecommendationView(APIView):
|
||||
"""
|
||||
توصیه آبیاری به صورت مستقیم.
|
||||
POST با sensor_uuid، plant_name، growth_stage، irrigation_method_name.
|
||||
POST با farm_uuid، plant_name، growth_stage، irrigation_method_name.
|
||||
نتیجه همان لحظه برگشت داده میشود.
|
||||
"""
|
||||
|
||||
@@ -162,7 +162,8 @@ class IrrigationRecommendationView(APIView):
|
||||
request=inline_serializer(
|
||||
name="IrrigationRecommendationRequest",
|
||||
fields={
|
||||
"sensor_uuid": drf_serializers.CharField(help_text="شناسه یکتای سنسور (اجباری)"),
|
||||
"farm_uuid": drf_serializers.CharField(help_text="شناسه یکتای مزرعه (اجباری)"),
|
||||
"sensor_uuid": drf_serializers.CharField(required=False, help_text="نام قدیمی برای farm_uuid"),
|
||||
"plant_name": drf_serializers.CharField(required=False, help_text="نام گیاه"),
|
||||
"growth_stage": drf_serializers.CharField(required=False, help_text="مرحله رشد گیاه"),
|
||||
"irrigation_method_name": drf_serializers.CharField(required=False, help_text="نام روش آبیاری"),
|
||||
@@ -187,7 +188,7 @@ class IrrigationRecommendationView(APIView):
|
||||
OpenApiExample(
|
||||
"نمونه درخواست",
|
||||
value={
|
||||
"sensor_uuid": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"farm_uuid": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"plant_name": "گوجهفرنگی",
|
||||
"growth_stage": "میوهدهی",
|
||||
"irrigation_method_name": "آبیاری قطرهای",
|
||||
@@ -199,23 +200,23 @@ class IrrigationRecommendationView(APIView):
|
||||
def post(self, request: Request):
|
||||
from rag.services.irrigation import get_irrigation_recommendation
|
||||
|
||||
sensor_uuid = request.data.get("sensor_uuid")
|
||||
if not sensor_uuid:
|
||||
farm_uuid = request.data.get("farm_uuid") or request.data.get("sensor_uuid")
|
||||
if not farm_uuid:
|
||||
return Response(
|
||||
{"code": 400, "msg": "پارامتر sensor_uuid الزامی است.", "data": None},
|
||||
{"code": 400, "msg": "پارامتر farm_uuid الزامی است.", "data": None},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
try:
|
||||
result = get_irrigation_recommendation(
|
||||
sensor_uuid=str(sensor_uuid),
|
||||
farm_uuid=str(farm_uuid),
|
||||
plant_name=request.data.get("plant_name"),
|
||||
growth_stage=request.data.get("growth_stage"),
|
||||
irrigation_method_name=request.data.get("irrigation_method_name"),
|
||||
query=request.data.get("query"),
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Direct irrigation recommendation failed for sensor %s", sensor_uuid)
|
||||
logger.exception("Direct irrigation recommendation failed for farm %s", farm_uuid)
|
||||
return Response(
|
||||
{"code": 500, "msg": "خطا در تولید توصیه آبیاری.", "data": None},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
@@ -230,7 +231,7 @@ class IrrigationRecommendationView(APIView):
|
||||
class FertilizationRecommendationView(APIView):
|
||||
"""
|
||||
توصیه کودهی به صورت مستقیم.
|
||||
POST با sensor_uuid، plant_name، growth_stage.
|
||||
POST با farm_uuid، plant_name، growth_stage.
|
||||
نتیجه همان لحظه برگشت داده میشود.
|
||||
"""
|
||||
|
||||
@@ -244,7 +245,8 @@ class FertilizationRecommendationView(APIView):
|
||||
request=inline_serializer(
|
||||
name="FertilizationRecommendationRequest",
|
||||
fields={
|
||||
"sensor_uuid": drf_serializers.CharField(help_text="شناسه یکتای سنسور (اجباری)"),
|
||||
"farm_uuid": drf_serializers.CharField(help_text="شناسه یکتای مزرعه (اجباری)"),
|
||||
"sensor_uuid": drf_serializers.CharField(required=False, help_text="نام قدیمی برای farm_uuid"),
|
||||
"plant_name": drf_serializers.CharField(required=False, help_text="نام گیاه"),
|
||||
"growth_stage": drf_serializers.CharField(required=False, help_text="مرحله رشد گیاه"),
|
||||
"query": drf_serializers.CharField(required=False, help_text="سوال اختیاری"),
|
||||
@@ -268,7 +270,7 @@ class FertilizationRecommendationView(APIView):
|
||||
OpenApiExample(
|
||||
"نمونه درخواست",
|
||||
value={
|
||||
"sensor_uuid": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"farm_uuid": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"plant_name": "گوجهفرنگی",
|
||||
"growth_stage": "رویشی",
|
||||
},
|
||||
@@ -279,22 +281,22 @@ class FertilizationRecommendationView(APIView):
|
||||
def post(self, request: Request):
|
||||
from rag.services.fertilization import get_fertilization_recommendation
|
||||
|
||||
sensor_uuid = request.data.get("sensor_uuid")
|
||||
if not sensor_uuid:
|
||||
farm_uuid = request.data.get("farm_uuid") or request.data.get("sensor_uuid")
|
||||
if not farm_uuid:
|
||||
return Response(
|
||||
{"code": 400, "msg": "پارامتر sensor_uuid الزامی است.", "data": None},
|
||||
{"code": 400, "msg": "پارامتر farm_uuid الزامی است.", "data": None},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
try:
|
||||
result = get_fertilization_recommendation(
|
||||
sensor_uuid=str(sensor_uuid),
|
||||
farm_uuid=str(farm_uuid),
|
||||
plant_name=request.data.get("plant_name"),
|
||||
growth_stage=request.data.get("growth_stage"),
|
||||
query=request.data.get("query"),
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Direct fertilization recommendation failed for sensor %s", sensor_uuid)
|
||||
logger.exception("Direct fertilization recommendation failed for farm %s", farm_uuid)
|
||||
return Response(
|
||||
{"code": 500, "msg": "خطا در تولید توصیه کودهی.", "data": None},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user