This commit is contained in:
2026-05-13 16:45:54 +03:30
parent 948c062b93
commit 46fe62fa04
96 changed files with 3834 additions and 155 deletions
+16 -2
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
from typing import Any
from farm_data.models import SensorData
from farm_data.services import build_ai_farm_snapshot
from .services import get_forecast_for_location
@@ -39,7 +40,7 @@ def _weather_condition(weather_code):
return WMO_CONDITIONS.get(weather_code, "نامشخص")
def _build_farm_weather_card(forecasts: list[Any]) -> dict[str, Any]:
def _build_farm_weather_card(forecasts: list[Any], *, farm_uuid: str | None = None, ai_snapshot: dict[str, Any] | None = None) -> dict[str, Any]:
if not forecasts:
return {
"condition": "نامشخص",
@@ -49,6 +50,10 @@ def _build_farm_weather_card(forecasts: list[Any]) -> dict[str, Any]:
"windSpeed": 0,
"windUnit": "km/h",
"chartData": {"labels": [], "series": [[]]},
"source_metadata": {
"weather": {"source": "center_location_forecast", "policy": "center_location_latest_forecast"},
"agronomic_metrics": {"source": "build_ai_farm_snapshot", "policy": "cluster_block_farm_aggregated"},
},
}
current_forecast = forecasts[0]
@@ -66,6 +71,14 @@ def _build_farm_weather_card(forecasts: list[Any]) -> dict[str, Any]:
"labels": labels,
"series": series,
},
"source_metadata": {
"weather": {"source": "center_location_forecast", "policy": "center_location_latest_forecast"},
"agronomic_metrics": {
"source": "build_ai_farm_snapshot",
"policy": "cluster_block_farm_aggregated",
"available": bool(ai_snapshot),
},
},
}
@@ -80,4 +93,5 @@ class FarmWeatherService:
raise ValueError("Farm not found.")
forecasts = get_forecast_for_location(sensor.center_location, days=7)
return _build_farm_weather_card(forecasts)
ai_snapshot = build_ai_farm_snapshot(farm_uuid)
return _build_farm_weather_card(forecasts, farm_uuid=farm_uuid, ai_snapshot=ai_snapshot)