Esempio n. 1
0
    def add(self, p):
        """
        Safely add a new component to the plan.
        :param p:
        :return:
        """
        if isinstance(p, Activity):
            if self.day and not isinstance(self.day[-1],
                                           Leg):  # enforce act-leg-act seq
                raise PAMSequenceValidationError(
                    f"Failed to add to plan, next component must be Leg instance."
                )
            self.day.append(p)

        elif isinstance(p, Leg):
            if not self.day:
                raise PAMSequenceValidationError(
                    f"Failed to add to plan, first component must be Activity instance."
                )
            if not isinstance(self.day[-1],
                              Activity):  # enforce act-leg-act seq
                raise PAMSequenceValidationError(
                    f"Failed to add to plan, next component must be Activity instance."
                )
            self.day.append(p)

        else:
            raise UserWarning(f"Cannot add type: {type(p)} to plan.")
Esempio n. 2
0
File: core.py Progetto: syhwawa/pam
    def validate_sequence(self):
        """
        Check sequence of Activities and Legs.
        :return: True
        """
        if not self.plan.valid_sequence:
            raise PAMSequenceValidationError(f"Person {self.pid} has invalid plan sequence")

        return True
Esempio n. 3
0
 def validate_sequence(self):
     if not self.valid_sequence:
         raise PAMSequenceValidationError()
     return True