mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-23 05:24:18 +00:00
35 lines
1.7 KiB
Python
35 lines
1.7 KiB
Python
"""
|
|
This module defines the BoolOperation database class.
|
|
"""
|
|
|
|
from ..base import Base, backref
|
|
from .Enums import OperationType
|
|
|
|
|
|
class BoolOperation(Base.Model):
|
|
__tablename__ = "bool_operation"
|
|
id = Base.Column(Base.Integer, primary_key=True)
|
|
operation = Base.Column(Base.Enum(OperationType), nullable=False)
|
|
is_root = Base.Column(Base.Boolean, default=False, nullable=False)
|
|
# Foreign Keys
|
|
condition_id = Base.Column(Base.Integer, Base.ForeignKey("condition.id"))
|
|
node_1_id = Base.Column(Base.Integer, Base.ForeignKey("bool_operation.id"))
|
|
node_2_id = Base.Column(Base.Integer, Base.ForeignKey("bool_operation.id"))
|
|
alert_id = Base.Column(Base.Integer, Base.ForeignKey("alert.id"))
|
|
# Relationships
|
|
condition = Base.relationship("Condition", back_populates="operations")
|
|
node_1 = Base.relationship("BoolOperation", primaryjoin=("bool_operation.c.node_1_id==bool_operation.c.id"),
|
|
remote_side="BoolOperation.id", backref=backref("father_1", uselist=False))
|
|
node_2 = Base.relationship("BoolOperation", primaryjoin=("bool_operation.c.node_2_id==bool_operation.c.id"),
|
|
remote_side="BoolOperation.id", backref=backref("father_2", uselist=False))
|
|
alert = Base.relationship("Alert", back_populates="operations")
|
|
|
|
def to_json(self):
|
|
return {"id": self.id,
|
|
"operation": self.operation,
|
|
"is_root": self.is_root,
|
|
"alert_id": self.alert_id,
|
|
"condition": self.condition.to_json() if self.condition else None,
|
|
"node_1": self.node_1.to_json() if self.node_1 else None,
|
|
"node_2": self.node_2.to_json() if self.node_2 else None
|
|
}
|