# Path: gtfspy/routing/profile_block.py
# class ProfileBlock:
# 
#     def __init__(self, start_time, end_time, distance_start, distance_end, **extra_properties):
#         self.start_time = start_time
#         self.end_time = end_time
#         assert(self.start_time < self.end_time)
#         self.distance_start = distance_start
#         self.distance_end = distance_end
#         self.extra_properties = extra_properties
# 
#     def area(self):
#         return self.width() * self.mean()
# 
#     def mean(self):
#         return 0.5 * (self.distance_start + self.distance_end)
# 
#     def width(self):
#         return self.end_time - self.start_time
# 
#     def max(self):
#         return max(self.distance_start, self.distance_end)
# 
#     def min(self):
#         return min(self.distance_start, self.distance_end)
# 
#     def is_flat(self):
#         return self.distance_start == self.distance_end
# 
#     def interpolate(self, time):
#         p = (time - self.start_time) / (self.end_time - self.start_time)
#         return (1-p) * self.distance_start + p * self.distance_end
# 
#     def __getitem__(self, extra_property_name):
#         return self.extra_properties[extra_property_name]
# 
#     def __str__(self):
#         parts = []
#         parts.append(self.start_time)
#         parts.append(self.end_time)
#         parts.append(self.distance_start)
#         parts.append(self.distance_end)
#         parts.append(self.extra_properties)
#         return str(parts)


from collections import defaultdict
from gtfspy.routing.profile_block import ProfileBlock
import numpy
                self.from_stop_I = value
            if key == "to_stop_I":
                self.to_stop_I = value

    def _apply_cutoff(self, cutoff_distance):
        for block in list(self._profile_blocks):
            block_max = max(block.distance_start, block.distance_end)
            if block_max > cutoff_distance:
                print("applying cutoff")
                blocks = []
                if block.distance_start == block.distance_end or \
                        (block.distance_start > cutoff_distance and block.distance_end > cutoff_distance):
                    blocks.append(
                        ProfileBlock(distance_end=cutoff_distance,
                                     distance_start=cutoff_distance,
                                     start_time=block.start_time,
                                     end_time=block.end_time)
                    )
                else:
                    if (block.distance_end >= cutoff_distance):
                        assert (block.distance_end < cutoff_distance)
                    split_point_x = block.start_time + (block.distance_start - cutoff_distance) / (
                        block.distance_start - block.distance_end) * block.width()
                    if block.distance_start > block.distance_end:
                        start_distance = cutoff_distance
                        end_distance = block.distance_end
                    else:
                        start_distance = block.distance_start
                        end_distance = cutoff_distance
                    first_block = ProfileBlock(block.start_time, split_point_x, start_distance, cutoff_distance)

# Path: gtfspy/routing/profile_block.py
# class ProfileBlock:
# 
#     def __init__(self, start_time, end_time, distance_start, distance_end, **extra_properties):
#         self.start_time = start_time
#         self.end_time = end_time
#         assert(self.start_time < self.end_time)
#         self.distance_start = distance_start
#         self.distance_end = distance_end
#         self.extra_properties = extra_properties
# 
#     def area(self):
#         return self.width() * self.mean()
# 
#     def mean(self):
#         return 0.5 * (self.distance_start + self.distance_end)
# 
#     def width(self):
#         return self.end_time - self.start_time
# 
#     def max(self):
#         return max(self.distance_start, self.distance_end)
# 
#     def min(self):
#         return min(self.distance_start, self.distance_end)
# 
#     def is_flat(self):
#         return self.distance_start == self.distance_end
# 
#     def interpolate(self, time):
#         p = (time - self.start_time) / (self.end_time - self.start_time)
#         return (1-p) * self.distance_start + p * self.distance_end
# 
#     def __getitem__(self, extra_property_name):
#         return self.extra_properties[extra_property_name]
# 
#     def __str__(self):
#         parts = []
#         parts.append(self.start_time)
#         parts.append(self.end_time)
#         parts.append(self.distance_start)
#         parts.append(self.distance_end)
#         parts.append(self.extra_properties)
#         return str(parts)


# Path: gtfspy/routing/profile_block_analyzer.py
from collections import defaultdict
from gtfspy.routing.profile_block import ProfileBlock
import numpy

                self.from_stop_I = value
            if key == "to_stop_I":
                self.to_stop_I = value

    def _apply_cutoff(self, cutoff_distance):
        for block in list(self._profile_blocks):
            block_max = max(block.distance_start, block.distance_end)
            if block_max > cutoff_distance:
                print("applying cutoff")
                blocks = []
                if block.distance_start == block.distance_end or \
                        (block.distance_start > cutoff_distance and block.distance_end > cutoff_distance):
                    blocks.append(
                        ProfileBlock(distance_end=cutoff_distance,
                                     distance_start=cutoff_distance,
                                     start_time=block.start_time,
                                     end_time=block.end_time)
                    )
                else:
                    if (block.distance_end >= cutoff_distance):
                        assert (block.distance_end < cutoff_distance)
                    split_point_x = block.start_time + (block.distance_start - cutoff_distance) / (
                        block.distance_start - block.distance_end) * block.width()
                    if block.distance_start > block.distance_end:
                        start_distance = cutoff_distance
                        end_distance = block.distance_end
                    else:
                        start_distance = block.distance_start
                        end_distance = cutoff_distance
                    first_block = ProfileBlock(block.start_time, split_point_x, start_distance, cutoff_distance)

                    second_block = ProfileBlock(split_point_x, block.end_time, cutoff_distance, end_distance)