コード例 #1
0
    def resolve(self):
        base_collisions = self.get_base_collisions()

        range_1 = self.weekly_facade_1.assignation.range_obj
        range_2 = self.weekly_facade_2.assignation.range_obj

        total_collisions = {}

        intersection = RangeOperator.get_intersection(range_1, range_2)
        aux_date = intersection.starting_date
        while aux_date <= intersection.ending_date:
            week_day = aux_date.weekday()
            main_day = self.weekly_facade_1.get_day(week_day)

            collisions = self.get_day_collisions(main_day, base_collisions)

            if collisions:
                collisions = self.filter_by_days_off(aux_date, collisions)

            if collisions:
                collisions = self.transform_collisions(collisions)

            if collisions:
                str_date = f"{aux_date}"
                total_collisions[str_date] = [main_day.day_number, collisions]

            aux_date += timedelta(days=1)

        if total_collisions:
            return total_collisions
        else:
            return None
コード例 #2
0
    def are_neighbors(assign1: AssignationProxy,
                      assign2: AssignationProxy) -> bool:
        """ To check if two assignations intersect or are
        next to the other. """

        return RangeOperator.are_neighbors(assign1.range_obj,
                                           assign2.range_obj)
コード例 #3
0
    def clean_updated_assign(self, assign: AssignationProxy,
                             assigns: List[AssignationProxy]) -> None:
        if hasattr(assign, 'was_deleted'):
            was_deleted = assign.was_deleted
        else:
            differences = assign.get_differences()
            was_deleted = differences['was_deleted']
        for aux_assign in assigns:
            are_compatible = AssignationOperator.are_compatible(
                assign, aux_assign)

            if assign != aux_assign and are_compatible:
                for del_range in was_deleted:
                    intersection = RangeOperator.get_intersection(
                        del_range, aux_assign.range_obj)
                    del_range, new_range = del_range - intersection
                    if new_range:
                        was_deleted.append(new_range)

                    if aux_assign.is_in_real_db():
                        ranges = self.remove_range_on_created_range(
                            intersection, aux_assign)
                        aux_assign.was_created = ranges
                    else:
                        ranges = self.remove_range_on_new_assign(
                            intersection, aux_assign)
                        aux_assign.was_created = ranges

        assign.was_deleted = was_deleted
コード例 #4
0
ファイル: range.py プロジェクト: mopitz199/workshift_engine
    def __sub__(self, other_range):

        if not RangeOperator.are_intersection(self, other_range):
            return self, None

        left = (other_range.starting_date - self.starting_date).days
        right = (self.ending_date - other_range.ending_date).days

        if left > 0 and right > 0:
            new = copy.deepcopy(self)
            new.starting_date = other_range.ending_date + timedelta(days=1)
            new.ending_date = self.ending_date

            self.ending_date = other_range.starting_date - timedelta(days=1)

            if len(self) < len(new):
                aux_starting_date = new.starting_date
                aux_ending_date = new.ending_date
                new.starting_date = self.starting_date
                new.ending_date = self.ending_date
                self.starting_date = aux_starting_date
                self.ending_date = aux_ending_date
            return self, new
        elif left > 0:
            self.ending_date = other_range.starting_date - timedelta(days=1)
            return self, None
        elif right > 0:
            self.starting_date = other_range.ending_date + timedelta(days=1)
            return self, None
        else:
            return None, None
コード例 #5
0
    def are_intersection(assign1: AssignationProxy,
                         assign2: AssignationProxy) -> bool:
        """
        To check if two assignations intersect.
        """

        return RangeOperator.are_intersection(assign1.range_obj,
                                              assign2.range_obj)
コード例 #6
0
 def compress_differences(
         self, differences: Dict[str,
                                 List[Range]]) -> Dict[str, List[Range]]:
     response = {}
     for key in differences:
         range_list = differences[key]
         response[key] = RangeOperator.compress_range_list(range_list)
     return response
コード例 #7
0
ファイル: range.py プロジェクト: mopitz199/workshift_engine
    def __add__(self, other_range):
        if RangeOperator.are_neighbors(self, other_range):

            self.starting_date = min(self.starting_date,
                                     other_range.starting_date)

            self.ending_date = max(self.ending_date, other_range.ending_date)
        return self
コード例 #8
0
 def _check_body(self, body_range: Range) -> bool:
     r1 = Range(self.day_off_assignation.starting_date,
                self.day_off_assignation.ending_date)
     return (RangeOperator.is_in(body_range, r1)
             and self.covers_a_whole_day())