UPDATE
This commit is contained in:
@@ -11,6 +11,7 @@ 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 location_data.satellite_snapshot import build_location_satellite_snapshot
|
||||
from plant.gdd import calculate_daily_gdd, resolve_growth_profile
|
||||
from weather.models import WeatherForecast
|
||||
|
||||
@@ -188,14 +189,11 @@ def _build_weather_from_farm(sensor: SensorData) -> list[dict[str, Any]]:
|
||||
|
||||
|
||||
def _build_soil_and_site_from_farm(sensor: SensorData) -> tuple[dict[str, Any], dict[str, Any]]:
|
||||
depths = list(sensor.center_location.depths.all())
|
||||
top_depth = depths[0] if depths else None
|
||||
smfcf = _safe_float(getattr(top_depth, "wv0033", None), 0.34)
|
||||
smw = _safe_float(getattr(top_depth, "wv1500", None), 0.14)
|
||||
sm0 = _safe_float(
|
||||
_pick_first_not_none(getattr(top_depth, "porosity", None), getattr(top_depth, "wv0000", None)),
|
||||
min(max(smfcf + 0.08, smw + 0.12), 0.6),
|
||||
)
|
||||
satellite_metrics = build_location_satellite_snapshot(sensor.center_location).get("resolved_metrics") or {}
|
||||
ndwi = _safe_float(satellite_metrics.get("ndwi"), 0.28)
|
||||
smfcf = _safe_float(ndwi, 0.34)
|
||||
smw = max(round(smfcf * 0.45, 3), 0.12)
|
||||
sm0 = min(max(smfcf + 0.08, smw + 0.12), 0.6)
|
||||
soil_moisture = None
|
||||
payload = sensor.sensor_payload or {}
|
||||
if isinstance(payload, dict):
|
||||
@@ -292,7 +290,6 @@ def build_growth_context(payload: dict[str, Any]) -> GrowthSimulationContext:
|
||||
if payload.get("farm_uuid"):
|
||||
sensor = (
|
||||
SensorData.objects.select_related("center_location")
|
||||
.prefetch_related("center_location__depths")
|
||||
.filter(farm_uuid=payload["farm_uuid"])
|
||||
.first()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user