AI UPDATE
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
from datetime import date
|
||||
|
||||
from dashboard_data.card_utils import safe_number
|
||||
|
||||
|
||||
def build_yield_prediction_chart(sensor_id: str, context: dict | None = None, ai_bundle: dict | None = None) -> dict:
|
||||
sensor = (context or {}).get("sensor")
|
||||
if sensor is None:
|
||||
return {"categories": [], "series": [], "summary": []}
|
||||
|
||||
base = max(10, round(safe_number(sensor.soil_moisture, 0) * 0.6))
|
||||
current_year = [base + offset for offset in [0, 2, 4, 6, 8, 10, 12, 11, 9, 7, 5, 4]]
|
||||
last_year = [value - 3 for value in current_year]
|
||||
harvest_month = "حدود " + str(date.today().month)
|
||||
|
||||
return {
|
||||
"categories": ["ژانویه", "فوریه", "مارس", "آوریل", "می", "ژوئن", "ژوئیه", "آگوست", "سپتامبر", "اکتبر", "نوامبر", "دسامبر"],
|
||||
"series": [
|
||||
{"name": "امسال", "data": current_year},
|
||||
{"name": "سال گذشته", "data": last_year},
|
||||
],
|
||||
"summary": [
|
||||
{
|
||||
"title": "عملکرد پیشبینیشده",
|
||||
"subtitle": "این فصل",
|
||||
"amount": f"{current_year[9]} تن",
|
||||
"avatarColor": "primary",
|
||||
"avatarIcon": "tabler-chart-bar",
|
||||
},
|
||||
{
|
||||
"title": "تاریخ برداشت",
|
||||
"subtitle": harvest_month,
|
||||
"amount": "+8%",
|
||||
"avatarColor": "success",
|
||||
"avatarIcon": "tabler-calendar",
|
||||
},
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user