Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. from pydantic import validator, BaseModel
  3. from million.model.message import Message
  4. import million.analyze.message_evaluation as msg_val
  5. class Sequence(BaseModel):
  6. start_message: Message
  7. end_message: Message | None = None
  8. @validator('end_message', pre=True, always=True)
  9. def default_end_message(cls, v, *, values):
  10. return v or values['start_message']
  11. def start(self) -> int:
  12. return msg_val.get(self.start_message)
  13. def end(self) -> int:
  14. return msg_val.get(self.end_message)
  15. def length(self) -> int:
  16. return self.end() - self.start() + 1
  17. def merge(self, other: Sequence) -> None:
  18. if other.start() < self.start(): self.start_message = other.start_message
  19. if other.end() > self.end(): self.end_message = other.end_message
  20. def overlaps(self, other: Sequence) -> bool:
  21. return self.start() <= other.end() + 1 and \
  22. other.start() <= self.end() + 1