示例#1
0
    def get_nearest_prev_point(self, point):
        """Return the largest point < some arbitrary point."""
        if self.is_on_sequence(point):
            return self.get_prev_point(point)
        p_iso_point = point_parse(point.value)
        prev_cycle_point = None

        for recurrence_iso_point in self.recurrence:

            # Is recurrence point greater than arbitrary point?
            if recurrence_iso_point > p_iso_point:
                break
            recurrence_cycle_point = ISO8601Point(str(recurrence_iso_point))
            if self.exclusions and recurrence_cycle_point in self.exclusions:
                break
            prev_cycle_point = recurrence_cycle_point

        if prev_cycle_point is None:
            return None
        if prev_cycle_point == point:
            raise SequenceDegenerateError(self.recurrence,
                                          WorkflowSpecifics.DUMP_FORMAT,
                                          prev_cycle_point, point)
        # Check all exclusions
        if self.exclusions and prev_cycle_point in self.exclusions:
            return self.get_prev_point(prev_cycle_point)
        return prev_cycle_point
示例#2
0
 def get_next_point_on_sequence(self, point):
     """Return the on-sequence point > point assuming that point is
     on-sequence, or None if out of bounds."""
     result = None
     next_point = self.recurrence.get_next(point_parse(point.value))
     if next_point:
         result = ISO8601Point(str(next_point))
         if result == point:
             raise SequenceDegenerateError(self.recurrence,
                                           WorkflowSpecifics.DUMP_FORMAT,
                                           point, result)
     # Check it is in the exclusions list now
     if result and result in self.exclusions:
         return self.get_next_point_on_sequence(result)
     return result
示例#3
0
    def _check_and_cache_next_point(self, point, next_point):
        """Verify and cache the get_next_point return info."""
        # Verify next_point != point.
        if next_point == point:
            raise SequenceDegenerateError(self.recurrence,
                                          WorkflowSpecifics.DUMP_FORMAT,
                                          next_point, point)

        # Cache the answer for point -> next_point.
        if (len(self._cached_next_point_values) > self._MAX_CACHED_POINTS):
            self._cached_next_point_values.popitem()
        self._cached_next_point_values[point.value] = next_point.value

        # Cache next_point as a valid starting point for this recurrence.
        if (len(self._cached_next_point_values) > self._MAX_CACHED_POINTS):
            self._cached_recent_valid_points.pop(0)
        self._cached_recent_valid_points.append(next_point)
示例#4
0
 def get_prev_point(self, point):
     """Return the previous point < point, or None if out of bounds."""
     # may be None if out of the recurrence bounds
     res = None
     prev_point = self.recurrence.get_prev(point_parse(point.value))
     if prev_point:
         res = ISO8601Point(str(prev_point))
         if res == point:
             raise SequenceDegenerateError(self.recurrence,
                                           WorkflowSpecifics.DUMP_FORMAT,
                                           res, point)
         # Check if res point is in the list of exclusions
         # If so, check the previous point by recursion.
         # Once you have found a point that is *not* in the exclusion
         # list, you can return it.
         if self.exclusions and res in self.exclusions:
             return self.get_prev_point(res)
     return res