コード例 #1
0
ファイル: activity.py プロジェクト: syhwawa/pam
    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.")
コード例 #2
0
ファイル: core.py プロジェクト: 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
コード例 #3
0
ファイル: activity.py プロジェクト: syhwawa/pam
 def validate_sequence(self):
     if not self.valid_sequence:
         raise PAMSequenceValidationError()
     return True