def travel_time_and_map_url(start, end, mode):
    # because openrouteservice has trouble finding bike-routes, e.g. from Utrecht Centraal, we try to find other locations
    # where we can bike from
    jump_closer_distance = 100
    bicycle_speed = 18 / 3.6
    local_start = deepcopy(start)
    local_end = deepcopy(end)
    for i in range(0, 3):
        try:
            if i != 0:
                logger.info('Trying again with locations ' +
                            local_start.full_str() + ', ' +
                            local_end.full_str())
            extra_time = i * jump_closer_distance / bicycle_speed
            time_sec = try_travel_time(local_start, local_end,
                                       mode) + extra_time
            return time_sec, map_url(local_start, local_end, mode)
        except ConnectionNotFoundError as error:
            distance = vincenty(local_start.gps, local_end.gps).meters
            new_start = Location.midpoint(local_start, local_end,
                                          jump_closer_distance / distance)
            new_end = Location.midpoint(local_start, local_end,
                                        (distance - jump_closer_distance) /
                                        distance)
            local_start = new_start
            local_end = new_end
    logger.error('Giving up on finding a route')
    return 99999, map_url(local_start, local_end,
                          mode)  # no bike route found, please ignore
Example #2
0
    def test_mid(self):
        loc1 = Location('a', (0.5, 1.5))
        loc2 = Location('b', (1.5, 3.5))

        mid1 = Location.midpoint(loc1, loc2)
        self.assertEqual(mid1.loc_str, 'mid_a_b')
        self.assertEqual(mid1.gps, (1.0, 2.5))

        mid2 = Location.midpoint(loc1, loc2, 0.75)
        self.assertEqual(mid2.loc_str, 'mid_a_b')
        self.assertEqual(mid2.gps, (1.25, 3.0))
Example #3
0
    def finish(self, edges):
        loc_1 = Location.midpoint(self.start.location, self.end.location, 0.01)
        loc_2 = Location.midpoint(self.start.location, self.end.location, 0.5)
        loc_3 = Location.midpoint(self.start.location, self.end.location, 0.99)
        loc_4 = self.end.location

        if self.fix_time == FixTime.START:
            start_time = self.start.time
        else:
            start_time = self.end.time - timedelta(hours=1)

        time_1 = start_time + 0.25 * timedelta(hours=1)
        time_2 = start_time + 0.5 * timedelta(hours=1)
        time_3 = start_time + 0.75 * timedelta(hours=1)
        time_4 = start_time + 0.99 * timedelta(hours=1)
        p1 = Point(loc_1, time_1)
        p2 = Point(loc_2, time_2)
        p3 = Point(loc_3, time_3)
        p4 = Point(loc_4, time_4)
        edges += [
            Segment(TransportType.BUS, p1, p2),
            Segment(TransportType.TRAIN, p2, p3),
            Segment(TransportType.WALK, p3, p4),
        ]