This commit is contained in:
2026-04-30 02:10:15 +03:30
parent 46ba01e4cc
commit e2c70ec8b6
5 changed files with 141 additions and 94 deletions
+19 -6
View File
@@ -63,6 +63,15 @@ def _coerce_positive_int(value, default: int) -> int:
return max(parsed, 1)
def _fa_task_status(status_name: str) -> str:
return {
"PENDING": "در انتظار",
"PROGRESS": "در حال پردازش",
"SUCCESS": "موفق",
"FAILURE": "ناموفق",
}.get(status_name, status_name)
class PlantGrowthSimulationView(APIView):
@extend_schema(
tags=["Crop Simulation"],
@@ -153,7 +162,11 @@ class PlantGrowthSimulationStatusView(APIView):
)
def get(self, request, task_id: str):
result = _get_async_result(task_id)
payload = {"task_id": task_id, "status": result.state}
payload = {
"task_id": task_id,
"status": result.state,
"status_fa": _fa_task_status(result.state),
}
if result.state == "PENDING":
payload["message"] = "تسک در صف یا یافت نشد."
@@ -181,7 +194,7 @@ class PlantGrowthSimulationStatusView(APIView):
payload["error"] = str(result.result)
return Response(
{"code": 200, "msg": "success", "data": payload},
{"code": 200, "msg": "موفق", "data": payload},
status=status.HTTP_200_OK,
)
@@ -256,7 +269,7 @@ class CurrentFarmSimulationChartView(APIView):
)
return Response(
{"code": 200, "msg": "success", "data": result},
{"code": 200, "msg": "موفق", "data": result},
status=status.HTTP_200_OK,
)
@@ -313,7 +326,7 @@ class HarvestPredictionView(APIView):
)
return Response(
{"code": 200, "msg": "success", "data": result},
{"code": 200, "msg": "موفق", "data": result},
status=status.HTTP_200_OK,
)
@@ -355,7 +368,7 @@ class YieldPredictionView(APIView):
{"code": 500, "msg": f"خطا در پیش بینی عملکرد: {exc}", "data": None},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
return Response({"code": 200, "msg": "success", "data": result}, status=status.HTTP_200_OK)
return Response({"code": 200, "msg": "موفق", "data": result}, status=status.HTTP_200_OK)
class YieldHarvestSummaryView(APIView):
@@ -443,4 +456,4 @@ class YieldHarvestSummaryView(APIView):
crop_name=validated.get("crop_name") or "",
include_narrative=validated.get("include_narrative", False),
)
return Response({"code": 200, "msg": "success", "data": payload}, status=status.HTTP_200_OK)
return Response({"code": 200, "msg": "موفق", "data": payload}, status=status.HTTP_200_OK)