68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
|
|
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
|