def GetSortedEvents(self, time_range=None): """Retrieves the events in increasing chronological order. Args: time_range (Optional[TimeRange]): time range used to filter events that fall in a specific period. Returns: generator(EventObject): event generator. Raises: IOError: when the storage writer is closed. OSError: when the storage writer is closed. """ if not self._is_open: raise IOError('Unable to read from closed storage writer.') event_heap = event_heaps.EventHeap() for event in self._events: if (time_range and ( event.timestamp < time_range.start_timestamp or event.timestamp > time_range.end_timestamp)): continue # Make a copy of the event before adding the event data. event = copy.deepcopy(event) # TODO: refactor this into psort. self._ReadEventDataIntoEvent(event) event_heap.PushEvent(event) return iter(event_heap.PopEvents())
def GetSortedEvents(self, time_range=None): """Retrieves the events in increasing chronological order. Args: time_range (Optional[TimeRange]): time range used to filter events that fall in a specific period. Returns: generator(EventObject): event generator. Raises: IOError: when the storage writer is closed. OSError: when the storage writer is closed. """ if not self._is_open: raise IOError('Unable to read from closed storage writer.') event_heap = event_heaps.EventHeap() for event_index, event in enumerate(self._events): if (time_range and (event.timestamp < time_range.start_timestamp or event.timestamp > time_range.end_timestamp)): continue # The event index is used to ensure to sort events with the same date and # time and description in the order they were added to the store. event_heap.PushEvent(event, event_index) return iter(event_heap.PopEvents())
def testPushEvent(self): """Tests the PushEvent function.""" event_heap = event_heaps.EventHeap() self.assertEqual(len(event_heap._heap), 0) event = containers_test_lib.TestEvent(5134324321) event_heap.PushEvent(event) self.assertEqual(len(event_heap._heap), 1)
def testPushEvent(self): """Tests the PushEvent function.""" event_heap = event_heaps.EventHeap() self.assertEqual(len(event_heap._heap), 0) event, _ = containers_test_lib.CreateEventFromValues( self._TEST_EVENTS[0]) event_heap.PushEvent(event, 0) self.assertEqual(len(event_heap._heap), 1)
def testPushEvents(self): """Tests the PushEvents function.""" event_heap = event_heaps.EventHeap() self.assertEqual(len(event_heap._heap), 0) event1 = containers_test_lib.TestEvent(5134324321) event2 = containers_test_lib.TestEvent(2345871286) event_heap.PushEvents([event1, event2]) self.assertEqual(len(event_heap._heap), 2)
def testPopEvents(self): """Tests the PopEvents function.""" event_heap = event_heaps.EventHeap() self.assertEqual(len(event_heap._heap), 0) test_events = list(event_heap.PopEvents()) self.assertEqual(len(test_events), 0) for event, _ in containers_test_lib.CreateEventsFromValues( self._TEST_EVENTS): event_heap.PushEvent(event) self.assertEqual(len(event_heap._heap), 2) test_events = list(event_heap.PopEvents()) self.assertEqual(len(test_events), 2) self.assertEqual(len(event_heap._heap), 0)
def testPopEvent(self): """Tests the PopEvent function.""" event_heap = event_heaps.EventHeap() self.assertEqual(len(event_heap._heap), 0) test_event = event_heap.PopEvent() self.assertIsNone(test_event) event_index = 0 for event, _ in containers_test_lib.CreateEventsFromValues( self._TEST_EVENTS): event_heap.PushEvent(event, event_index) event_index += 1 self.assertEqual(len(event_heap._heap), 2) test_event = event_heap.PopEvent() self.assertIsNotNone(test_event) self.assertEqual(len(event_heap._heap), 1)
def testPopEvents(self): """Tests the PopEvents function.""" event_heap = event_heaps.EventHeap() self.assertEqual(len(event_heap._heap), 0) test_events = list(event_heap.PopEvents()) self.assertEqual(len(test_events), 0) event1 = containers_test_lib.TestEvent(5134324321) event_heap.PushEvent(event1) event2 = containers_test_lib.TestEvent(2345871286) event_heap.PushEvent(event2) self.assertEqual(len(event_heap._heap), 2) test_events = list(event_heap.PopEvents()) self.assertEqual(len(test_events), 2) self.assertEqual(len(event_heap._heap), 0)
def testPopEvent(self): """Tests the PopEvent function.""" event_heap = event_heaps.EventHeap() self.assertEqual(len(event_heap._heap), 0) test_event = event_heap.PopEvent() self.assertIsNone(test_event) event1 = containers_test_lib.TestEvent(5134324321) event_heap.PushEvent(event1) event2 = containers_test_lib.TestEvent(2345871286) event_heap.PushEvent(event2) self.assertEqual(len(event_heap._heap), 2) test_event = event_heap.PopEvent() self.assertIsNotNone(test_event) self.assertEqual(len(event_heap._heap), 1)
def GetSortedEvents(self, time_range=None): """Retrieves the events in increasing chronological order. Args: time_range (Optional[TimeRange]): time range used to filter events that fall in a specific period. Returns: generator(EventObject): event generator. """ event_heap = event_heaps.EventHeap() for event in self._GetAttributeContainerList('event'): if (time_range and (event.timestamp < time_range.start_timestamp or event.timestamp > time_range.end_timestamp)): continue event_heap.PushEvent(event) return iter(event_heap.PopEvents())
def testNumberOfEvents(self): """Tests the number_of_events property.""" event_heap = event_heaps.EventHeap() self.assertEqual(event_heap.number_of_events, 0)