This commit is contained in:
2026-05-11 15:31:10 +03:30
parent c2b6052e5c
commit 948c062b93
5 changed files with 1668 additions and 19 deletions
+15 -2
View File
@@ -16,6 +16,7 @@ import requests
from location_data.block_subdivision import create_or_get_block_subdivision
from location_data.models import BlockSubdivision, SoilLocation
from location_data.satellite_snapshot import (
build_block_layout_metric_summary,
build_location_block_satellite_snapshots,
build_location_satellite_snapshot,
)
@@ -464,6 +465,15 @@ def get_farm_details(farm_uuid: str):
)
latest_satellite = build_location_satellite_snapshot(center_location)
block_metric_snapshots = build_location_block_satellite_snapshots(
center_location,
sensor_payload=farm.sensor_payload,
)
if all(
snapshot.get("status") == "missing" and not snapshot.get("resolved_metrics")
for snapshot in block_metric_snapshots
):
block_metric_snapshots = []
soil_metrics = dict(latest_satellite.get("resolved_metrics") or {})
sensor_metrics, sensor_metric_sources = _resolve_sensor_metrics(farm.sensor_payload)
@@ -483,7 +493,10 @@ def get_farm_details(farm_uuid: str):
"lon": center_location.longitude,
"farm_boundary": center_location.farm_boundary,
"input_block_count": center_location.input_block_count,
"block_layout": center_location.block_layout,
"block_layout": build_block_layout_metric_summary(
center_location,
sensor_payload=farm.sensor_payload,
),
},
"weather": WeatherForecastDetailSerializer(weather).data if weather else None,
"sensor_payload": farm.sensor_payload or {},
@@ -491,7 +504,7 @@ def get_farm_details(farm_uuid: str):
"soil": {
"resolved_metrics": resolved_metrics,
"metric_sources": metric_sources,
"satellite_snapshots": build_location_block_satellite_snapshots(center_location),
"satellite_snapshots": block_metric_snapshots,
},
"plant_ids": [plant.backend_plant_id for plant in plant_snapshots],
"plants": PlantCatalogSnapshotSerializer(plant_snapshots, many=True).data,