Пример #1
0
 def _try_create_new_match(self, first_partial_match: PartialMatch,
                           second_partial_match: PartialMatch,
                           first_event_defs: List[Tuple[int, QItem]],
                           second_event_defs: List[Tuple[int, QItem]]):
     """
     Verifies all the conditions for creating a new partial match and creates it if all constraints are satisfied.
     """
     # We need this because clean_expired doesn't necessarily clean old partial matches.
     if self._sliding_window != timedelta.max and (
             abs(first_partial_match.last_timestamp -
                 second_partial_match.first_timestamp) >
             self._sliding_window
             or abs(first_partial_match.first_timestamp -
                    second_partial_match.last_timestamp) >
             self._sliding_window):
         return
     events_for_new_match = self._merge_events_for_new_match(
         first_event_defs, second_event_defs, first_partial_match.events,
         second_partial_match.events)
     # events merged
     if not self._validate_new_match(events_for_new_match):
         return
     self.add_partial_match(PartialMatch(events_for_new_match))
     if self._parent is not None:
         self._parent.handle_new_partial_match(self)
Пример #2
0
    def handle_event(self, event: Event):
        """
        Inserts the given event to this leaf.
        """
        self.clean_expired_partial_matches(event.timestamp)

        # get event's qitem and make a binding to evaluate formula for the new event.
        binding = {self.__event_name: event.payload}

        if not self._condition.eval(binding):
            return

        self.add_partial_match(PartialMatch([event]))
        if self._parent is not None:
            self._parent.handle_new_partial_match(self)
Пример #3
0
    def _try_create_new_match(self, first_partial_match: PartialMatch,
                              second_partial_match: PartialMatch,
                              first_event_defs: List[Tuple[int, QItem]],
                              second_event_defs: List[Tuple[int, QItem]]):
        """
        Verifies all the conditions for creating a new partial match and creates it if all constraints are satisfied.
        """
        if self._sliding_window != timedelta.max and \
                abs(first_partial_match.last_timestamp - second_partial_match.first_timestamp) > self._sliding_window:
            return
        events_for_new_match = self._merge_events_for_new_match(
            first_event_defs, second_event_defs, first_partial_match.events,
            second_partial_match.events)

        if not self._validate_new_match(events_for_new_match):
            return
        self.add_partial_match(PartialMatch(events_for_new_match))
        if self._parent is not None:
            self._parent.handle_new_partial_match(self)
Пример #4
0
 def __init__(self):
     self.dt = datetime(2020, 1, 1)
     self.pm_list = []
     for i in range(10):
         self.pm_list.append(
             PartialMatch([Event(i, "type", self.dt + timedelta(i * 10))]))
Пример #5
0
 def __init__(self):
     self.dt = datetime(2020, 1, 1)
     self.pm1 = PartialMatch([Event(1, "type", self.dt)])
     self.pm2 = PartialMatch([Event(5, "type", self.dt + timedelta(4))])
     self.pm3 = PartialMatch([Event(17, "type", self.dt + timedelta(16))])
     self.pm4 = PartialMatch([Event(33, "type", self.dt + timedelta(32))])