AI UPDATE
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from dashboard_data.card_utils import safe_number
|
||||
|
||||
|
||||
def build_ndvi_health_card(sensor_id: str, context: dict | None = None, ai_bundle: dict | None = None) -> dict:
|
||||
context = context or {}
|
||||
sensor = context.get("sensor")
|
||||
if sensor is None:
|
||||
return {"ndviIndex": 0, "healthData": []}
|
||||
|
||||
nitrogen = safe_number(sensor.nitrogen, 0)
|
||||
moisture = safe_number(sensor.soil_moisture, 0)
|
||||
ndvi = round(min(0.95, max(0.1, ((nitrogen / 100) * 0.4) + ((moisture / 100) * 0.6))), 2)
|
||||
|
||||
return {
|
||||
"ndviIndex": ndvi,
|
||||
"healthData": [
|
||||
{
|
||||
"title": "تنش نیتروژن",
|
||||
"value": "پایین" if nitrogen >= 30 else "بالا",
|
||||
"color": "success" if nitrogen >= 30 else "warning",
|
||||
"icon": "tabler-leaf",
|
||||
},
|
||||
{
|
||||
"title": "سلامت محصول",
|
||||
"value": "خوب" if ndvi >= 0.65 else "متوسط",
|
||||
"color": "success" if ndvi >= 0.65 else "warning",
|
||||
"icon": "tabler-plant",
|
||||
},
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user