This commit is contained in:
2026-05-13 22:28:56 +03:30
parent 46fe62fa04
commit 45fee1dfd3
26 changed files with 2329 additions and 878 deletions
+7 -5
View File
@@ -10,8 +10,8 @@ import logging
from django.apps import apps
from django.core.paginator import EmptyPage, Paginator
from farm_data.models import SensorData
from farm_data.services import get_canonical_farm_record, get_runtime_plant_for_farm
from farm_data.models import PlantCatalogSnapshot, SensorData
from farm_data.services import clone_snapshot_as_runtime_plant, get_canonical_farm_record, get_runtime_plant_for_farm
from location_data.satellite_snapshot import build_location_satellite_snapshot
from plant.gdd import calculate_daily_gdd, resolve_growth_profile
from weather.models import WeatherForecast
@@ -277,9 +277,11 @@ def _resolve_plant_simulation_defaults(plant: Any) -> tuple[dict[str, Any] | Non
def build_growth_context(payload: dict[str, Any]) -> GrowthSimulationContext:
plant_name = apps.get_app_config("plant").resolve_plant_name(payload["plant_name"]) or payload["plant_name"]
from plant.models import Plant
plant = Plant.objects.filter(name=plant_name).first()
snapshot = (
PlantCatalogSnapshot.objects.filter(name=plant_name).first()
or PlantCatalogSnapshot.objects.filter(name__iexact=plant_name).first()
)
plant = clone_snapshot_as_runtime_plant(snapshot)
if plant is None:
raise GrowthSimulationError("Plant not found.")
@@ -6,7 +6,7 @@ from unittest.mock import patch
from django.test import TestCase, override_settings
from rest_framework.test import APIClient
from plant.models import Plant
from farm_data.models import PlantCatalogSnapshot
from .growth_simulation import paginate_growth_stages, run_growth_simulation
@@ -15,7 +15,8 @@ from .growth_simulation import paginate_growth_stages, run_growth_simulation
class PlantGrowthSimulationApiTests(TestCase):
def setUp(self):
self.client = APIClient()
self.plant = Plant.objects.create(
self.plant = PlantCatalogSnapshot.objects.create(
backend_plant_id=301,
name="گوجه‌فرنگی",
growth_profile={
"base_temperature": 10,
+2 -1
View File
@@ -12,6 +12,7 @@ from rest_framework.test import APIRequestFactory
from .models import SimulationRun, SimulationScenario
from farm_data.models import PlantCatalogSnapshot, SensorData
from farm_data.services import assign_farm_plants_from_backend_ids
from irrigation.models import IrrigationMethod
from location_data.models import SoilLocation
from weather.models import WeatherForecast
@@ -393,7 +394,7 @@ class CropSimulationCanonicalSnapshotTests(TestCase):
weather_forecast=self.weather,
irrigation_method=self.irrigation_method,
)
self.farm.plants.add(self.plant)
assign_farm_plants_from_backend_ids(self.farm, [self.plant.backend_plant_id])
@patch("crop_simulation.services.build_ai_farm_snapshot")
def test_build_simulation_payload_from_farm_uses_aggregated_metrics(self, mock_snapshot):