UPDATE
This commit is contained in:
+16
-6
@@ -193,10 +193,17 @@ def _grid_axis(min_value: float, max_value: float) -> list[float]:
|
||||
|
||||
|
||||
def _load_sensor_network(current_sensor: Any) -> list[Any]:
|
||||
plant_ids = list(current_sensor.plants.values_list("id", flat=True))
|
||||
queryset = SensorData.objects.select_related("center_location").prefetch_related("plants", "center_location__depths")
|
||||
plant_ids = list(
|
||||
current_sensor.plant_assignments.values_list("plant__backend_plant_id", flat=True)
|
||||
)
|
||||
queryset = SensorData.objects.select_related("center_location").prefetch_related(
|
||||
"plant_assignments__plant",
|
||||
"center_location__depths",
|
||||
)
|
||||
if plant_ids:
|
||||
queryset = queryset.filter(plants__id__in=plant_ids).distinct()
|
||||
queryset = queryset.filter(
|
||||
plant_assignments__plant__backend_plant_id__in=plant_ids
|
||||
).distinct()
|
||||
return list(queryset)
|
||||
|
||||
|
||||
@@ -270,7 +277,7 @@ class SoilMoistureHeatmapService:
|
||||
def get_heatmap(self, *, farm_uuid: str) -> dict[str, Any]:
|
||||
current_sensor = (
|
||||
SensorData.objects.select_related("center_location")
|
||||
.prefetch_related("plants", "center_location__depths")
|
||||
.prefetch_related("plant_assignments__plant", "center_location__depths")
|
||||
.filter(farm_uuid=farm_uuid)
|
||||
.first()
|
||||
)
|
||||
@@ -438,7 +445,7 @@ class SoilHealthService:
|
||||
def get_health_summary(self, *, farm_uuid: str) -> dict[str, Any]:
|
||||
sensor = (
|
||||
SensorData.objects.select_related("center_location")
|
||||
.prefetch_related("plants")
|
||||
.prefetch_related("plant_assignments__plant")
|
||||
.filter(farm_uuid=farm_uuid)
|
||||
.first()
|
||||
)
|
||||
@@ -446,7 +453,10 @@ class SoilHealthService:
|
||||
raise ValueError("Farm not found.")
|
||||
return {
|
||||
"farm_uuid": str(sensor.farm_uuid),
|
||||
**build_soil_health_summary(sensor, list(sensor.plants.all())),
|
||||
**build_soil_health_summary(
|
||||
sensor,
|
||||
list(sensor.plant_snapshots),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user