UPDATE
This commit is contained in:
+20
-13
@@ -9,6 +9,7 @@ from django.utils import timezone
|
||||
|
||||
from farm_data.context import load_farm_context
|
||||
from farm_data.models import SensorData
|
||||
from location_data.satellite_snapshot import build_location_satellite_snapshot
|
||||
from rag.services import get_soil_anomaly_insight
|
||||
|
||||
from .anomaly_detection import build_anomaly_detection_card
|
||||
@@ -198,7 +199,6 @@ def _load_sensor_network(current_sensor: Any) -> list[Any]:
|
||||
)
|
||||
queryset = SensorData.objects.select_related("center_location").prefetch_related(
|
||||
"plant_assignments__plant",
|
||||
"center_location__depths",
|
||||
)
|
||||
if plant_ids:
|
||||
queryset = queryset.filter(
|
||||
@@ -208,20 +208,27 @@ def _load_sensor_network(current_sensor: Any) -> list[Any]:
|
||||
|
||||
|
||||
def _soil_profile(sensor: Any) -> list[dict[str, Any]]:
|
||||
depths = sensor.center_location.depths.all()
|
||||
snapshot = build_location_satellite_snapshot(sensor.center_location)
|
||||
metrics = snapshot.get("resolved_metrics") or {}
|
||||
if not metrics:
|
||||
return []
|
||||
return [
|
||||
{
|
||||
"depth_label": depth.depth_label,
|
||||
"field_capacity": depth.wv0033,
|
||||
"wilting_point": depth.wv1500,
|
||||
"saturation": depth.wv0010,
|
||||
"nitrogen": depth.nitrogen,
|
||||
"ph": depth.phh2o,
|
||||
"sand": depth.sand,
|
||||
"silt": depth.silt,
|
||||
"clay": depth.clay,
|
||||
"depth_label": "surface_30x30_remote_sensing",
|
||||
"field_capacity": metrics.get("ndwi"),
|
||||
"wilting_point": None,
|
||||
"saturation": None,
|
||||
"nitrogen": None,
|
||||
"ph": None,
|
||||
"sand": None,
|
||||
"silt": None,
|
||||
"clay": None,
|
||||
"ndvi": metrics.get("ndvi"),
|
||||
"lst_c": metrics.get("lst_c"),
|
||||
"soil_vv_db": metrics.get("soil_vv_db"),
|
||||
"dem_m": metrics.get("dem_m"),
|
||||
"slope_deg": metrics.get("slope_deg"),
|
||||
}
|
||||
for depth in depths
|
||||
]
|
||||
|
||||
|
||||
@@ -277,7 +284,7 @@ class SoilMoistureHeatmapService:
|
||||
def get_heatmap(self, *, farm_uuid: str) -> dict[str, Any]:
|
||||
current_sensor = (
|
||||
SensorData.objects.select_related("center_location")
|
||||
.prefetch_related("plant_assignments__plant", "center_location__depths")
|
||||
.prefetch_related("plant_assignments__plant")
|
||||
.filter(farm_uuid=farm_uuid)
|
||||
.first()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user