This commit is contained in:
2026-04-11 03:54:15 +03:30
parent 883573004c
commit 36d6b05a7f
68 changed files with 3487 additions and 841 deletions
+1
View File
@@ -0,0 +1 @@
+7
View File
@@ -0,0 +1,7 @@
from django.apps import AppConfig
class CropHealthConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "crop_health"
verbose_name = "Crop Health"
+19
View File
@@ -0,0 +1,19 @@
FARM_HEALTH_SCORE = {
"id": "farm_health_score",
"title": "امتیاز سلامت مزرعه",
"subtitle": "تحلیل هوشمند",
"stats": "87%",
"avatarColor": "success",
"avatarIcon": "tabler-heartbeat",
"chipText": "خوب",
"chipColor": "success",
}
NDVI_HEALTH_CARD = {
"ndviIndex": 0.78,
"healthData": [
{"title": "تنش نیتروژن", "value": "پایین", "color": "success", "icon": "tabler-leaf"},
{"title": "سلامت محصول", "value": "خوب", "color": "success", "icon": "tabler-plant"},
],
}
+2
View File
@@ -0,0 +1,2 @@
from django.db import models
+29
View File
@@ -0,0 +1,29 @@
from rest_framework import serializers
class HealthDataItemSerializer(serializers.Serializer):
title = serializers.CharField(required=False, allow_blank=True)
value = serializers.CharField(required=False, allow_blank=True)
color = serializers.CharField(required=False, allow_blank=True)
icon = serializers.CharField(required=False, allow_blank=True)
class NdviHealthCardSerializer(serializers.Serializer):
ndviIndex = serializers.FloatField(required=False)
healthData = HealthDataItemSerializer(many=True, required=False)
class FarmHealthScoreSerializer(serializers.Serializer):
id = serializers.CharField(required=False, allow_blank=True)
title = serializers.CharField(required=False, allow_blank=True)
subtitle = serializers.CharField(required=False, allow_blank=True)
stats = serializers.CharField(required=False, allow_blank=True)
avatarColor = serializers.CharField(required=False, allow_blank=True)
avatarIcon = serializers.CharField(required=False, allow_blank=True)
chipText = serializers.CharField(required=False, allow_blank=True)
chipColor = serializers.CharField(required=False, allow_blank=True)
class CropHealthSummarySerializer(serializers.Serializer):
ndviHealthCard = NdviHealthCardSerializer(required=False)
farmHealthScore = FarmHealthScoreSerializer(required=False)
+10
View File
@@ -0,0 +1,10 @@
from copy import deepcopy
from .mock_data import FARM_HEALTH_SCORE, NDVI_HEALTH_CARD
def get_crop_health_summary_data(farm=None):
return {
"ndviHealthCard": deepcopy(NDVI_HEALTH_CARD),
"farmHealthScore": deepcopy(FARM_HEALTH_SCORE),
}
+7
View File
@@ -0,0 +1,7 @@
from django.urls import path
from .views import CropHealthSummaryView
urlpatterns = [
path("summary/", CropHealthSummaryView.as_view(), name="crop-health-summary"),
]
+31
View File
@@ -0,0 +1,31 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, extend_schema
from config.swagger import status_response
from .serializers import CropHealthSummarySerializer
from .services import get_crop_health_summary_data
class CropHealthSummaryView(APIView):
@extend_schema(
tags=["Crop Health"],
parameters=[
OpenApiParameter(
name="farm_uuid",
type=OpenApiTypes.UUID,
location=OpenApiParameter.QUERY,
required=False,
description="UUID of the farm for crop health data.",
default="11111111-1111-1111-1111-111111111111",
),
],
responses={200: status_response("CropHealthSummaryResponse", data=CropHealthSummarySerializer())},
)
def get(self, request):
return Response(
{"status": "success", "data": get_crop_health_summary_data()},
status=status.HTTP_200_OK,
)