def _get_fake_timestamp(self, after, before):
        """
        Pick a time in an interval.

        Picks a microsecond after `after`, else a microsecond before `before`.

        Input and output values are ISO format strings.
        """
        # Just pick the time at the beginning of the interval.
        if after:
            # Add a microsecond to 'after'
            return add_microseconds(after, 1)
        else:
            # Subtract a microsecond from 'before'
            return add_microseconds(before, -1)
    def _reorder_within_dumps(self):
        """
        Fix the timestamp of a validation event if an enrollment event occurs during the dump.
        """
        num_events = len(self.sorted_events) - 1
        for index in range(num_events):
            event = self.sorted_events[index]
            prev_event = self.sorted_events[index + 1]
            is_nonvalidate_during_validate = (
                event.event_type == VALIDATED and
                prev_event.event_type != VALIDATED and
                event.is_during_dump(prev_event.timestamp)
            )
            if is_nonvalidate_during_validate:
                is_active_is_inconsistent = (
                    (event.is_active and prev_event.event_type == DEACTIVATED) or
                    (not event.is_active and prev_event.event_type == ACTIVATED)
                )
                mode_is_inconsistent = (event.mode != prev_event.mode and prev_event.event_type == MODE_CHANGED)

                if is_active_is_inconsistent or mode_is_inconsistent:
                    # Change the timestamp of the validation event to precede
                    # the other event, and swap them.
                    event.timestamp = add_microseconds(prev_event.timestamp, -1)
                    self.sorted_events[index] = prev_event
                    self.sorted_events[index + 1] = event
 def _validated(self, timestamp, is_active, created, mode=None, dump_duration_in_secs=300):
     """Creates a VALIDATED event."""
     dump_end = timestamp
     dump_start = add_microseconds(timestamp, int(dump_duration_in_secs) * -100000)
     validation_info = {
         'is_active': is_active,
         'created': created,
         'dump_start': dump_start,
         'dump_end': dump_end,
     }
     return (timestamp, VALIDATED, mode or self.mode, validation_info)
Beispiel #4
0
 def _validated(self, timestamp, is_active, created, mode=None, dump_duration_in_secs=300):
     """Creates a VALIDATED event."""
     dump_end = timestamp
     dump_start = add_microseconds(timestamp, int(dump_duration_in_secs) * -100000)
     validation_info = {
         'is_active': is_active,
         'created': created,
         'dump_start': dump_start,
         'dump_end': dump_end,
     }
     return (timestamp, VALIDATED, mode or self.mode, validation_info)