This commit is contained in:
2026-04-06 23:50:24 +03:30
parent a67236d45c
commit ff464cb4a5
140 changed files with 2061 additions and 2702 deletions
+5 -9
View File
@@ -4,17 +4,17 @@ from datetime import date
def load_dashboard_context(sensor_id: str) -> dict | None:
from irrigation.models import IrrigationMethod
from location_data.models import SoilDepthData
from sensor_data.models import SensorData, SensorDataHistory
from farm_data.models import SensorData
from weather.models import WeatherForecast
try:
sensor = SensorData.objects.select_related("location").prefetch_related("plants").get(
uuid_sensor=sensor_id
sensor = SensorData.objects.select_related("center_location").prefetch_related("plants").get(
farm_uuid=sensor_id
)
except SensorData.DoesNotExist:
return None
location = sensor.location
location = sensor.center_location
depths = list(
SoilDepthData.objects.filter(soil_location=location).order_by("depth_label")
)
@@ -22,9 +22,6 @@ def load_dashboard_context(sensor_id: str) -> dict | None:
WeatherForecast.objects.filter(location=location, forecast_date__gte=date.today())
.order_by("forecast_date")[:7]
)
history = list(
SensorDataHistory.objects.filter(uuid_sensor=sensor_id).order_by("-recorded_at")[:30]
)
plants = list(sensor.plants.all())
irrigation_methods = list(IrrigationMethod.objects.all()[:5])
@@ -33,8 +30,7 @@ def load_dashboard_context(sensor_id: str) -> dict | None:
"location": location,
"depths": depths,
"forecasts": forecasts,
"history": history,
"history": [],
"plants": plants,
"irrigation_methods": irrigation_methods,
}