This commit is contained in:
2026-04-10 16:12:51 +03:30
parent 20fd3842b6
commit 883573004c
143 changed files with 1380 additions and 2332 deletions
+67
View File
@@ -0,0 +1,67 @@
import uuid as uuid_lib
from django.db import models
from farm_hub.models import FarmHub
SEVERITY_CHOICES = [
("info", "Info"),
("warning", "Warning"),
("error", "Error"),
("success", "Success"),
]
class FarmAlert(models.Model):
uuid = models.UUIDField(default=uuid_lib.uuid4, unique=True, editable=False, db_index=True)
farm = models.ForeignKey(FarmHub, on_delete=models.CASCADE, related_name="farm_alerts", null=True, blank=True)
title = models.CharField(max_length=255)
description = models.TextField(blank=True, default="")
color = models.CharField(max_length=32, default="info", choices=SEVERITY_CHOICES)
avatar_icon = models.CharField(max_length=64, blank=True, default="")
avatar_color = models.CharField(max_length=32, blank=True, default="")
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "farm_alerts"
ordering = ["-created_at"]
def __str__(self):
return f"{self.title} ({self.color})"
class AnomalyDetection(models.Model):
uuid = models.UUIDField(default=uuid_lib.uuid4, unique=True, editable=False, db_index=True)
farm = models.ForeignKey(FarmHub, on_delete=models.CASCADE, related_name="anomalies", null=True, blank=True)
sensor = models.CharField(max_length=255)
value = models.CharField(max_length=64)
expected = models.CharField(max_length=64)
deviation = models.CharField(max_length=64)
severity = models.CharField(max_length=32, default="warning", choices=SEVERITY_CHOICES)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "farm_anomaly_detections"
ordering = ["-created_at"]
def __str__(self):
return f"{self.sensor}: {self.value}"
class Recommendation(models.Model):
uuid = models.UUIDField(default=uuid_lib.uuid4, unique=True, editable=False, db_index=True)
farm = models.ForeignKey(FarmHub, on_delete=models.CASCADE, related_name="recommendations", null=True, blank=True)
title = models.CharField(max_length=255)
subtitle = models.TextField(blank=True, default="")
avatar_icon = models.CharField(max_length=64, blank=True, default="")
avatar_color = models.CharField(max_length=32, blank=True, default="")
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = "farm_recommendations"
ordering = ["-created_at"]
def __str__(self):
return self.title