Пример #1
0
def test_generating_requests_on_non_simplified_graphs():
    n = Network('epsg:27700')
    n.add_link('0', 1, 2, attribs={'modes': ['car']})
    n.add_link('1', 2, 3, attribs={'modes': ['car']})
    n.add_link('2', 4, 3, attribs={'modes': ['car']})
    n.add_link('3', 5, 4, attribs={'modes': ['car']})
    n.add_link('4', 1, 10, attribs={'modes': ['car']})

    for node in n.graph.nodes:
        n.apply_attributes_to_node(node, {'lat': 1, 'lon': 2})

    api_requests = google_directions.generate_requests(n)

    assert_semantically_equal(
        api_requests, {
            (1, 10): {
                'path_nodes': (1, 10),
                'path_polyline': '_ibE_seK??',
                'origin': {
                    'lat': 1,
                    'lon': 2
                },
                'destination': {
                    'lat': 1,
                    'lon': 2
                }
            },
            (1, 3): {
                'path_nodes': [1, 2, 3],
                'path_polyline': '_ibE_seK????',
                'origin': {
                    'lat': 1,
                    'lon': 2
                },
                'destination': {
                    'lat': 1,
                    'lon': 2
                }
            },
            (5, 3): {
                'path_nodes': [5, 4, 3],
                'path_polyline': '_ibE_seK????',
                'origin': {
                    'lat': 1,
                    'lon': 2
                },
                'destination': {
                    'lat': 1,
                    'lon': 2
                }
            }
        })
def test_generating_requests_on_simplified_graphs():
    n = Network('epsg:27700')
    n.add_link('0', 1, 3, attribs={'modes': ['car'],
                                   'geometry': LineString([(528915.9309752393, 181899.48948011652),
                                                           (528888.1581643537, 181892.3086225874),
                                                           (528780.3405144282, 181859.84184561518),
                                                           (528780.3405144282, 181859.84184561518)])})
    n.add_link('3', 5, 3, attribs={'modes': ['car'],
                                   'geometry': LineString([(528888.1581643537, 181892.3086225874),
                                                           (528915.9309752393, 181899.48948011652),
                                                           (528780.3405144282, 181859.84184561518)])})
    n.add_link('4', 1, 10, attribs={'modes': ['car']})
    n.add_link('5', 10, 1, attribs={'modes': ['walk']})
    n.graph.graph["simplified"] = True

    n.apply_attributes_to_nodes({1: {'x': 528915.9309752393, 'y': 181899.48948011652},
                                 3: {'x': 528780.3405144282, 'y': 181859.84184561518},
                                 5: {'x': 528888.1581643537, 'y': 181892.3086225874},
                                 10: {'x': 528780.3405144282, 'y': 181892.3086225874},
                                 })

    n.apply_attributes_to_nodes({1: {'lon': -0.14327038749428384, 'lat': 51.52130909540579},
                                 3: {'lon': -0.14523808749533396, 'lat': 51.520983695405526},
                                 5: {'lon': -0.14367308749449406, 'lat': 51.52125089540575},
                                 10: {'lon': -0.14522623292591474, 'lat': 51.521275465129236}})

    api_requests = google_directions.generate_requests(n)

    assert_semantically_equal(api_requests, {(1, 3): {'path_nodes': (1, 3),
                                                      'origin': {'x': 528915.9309752393, 'y': 181899.48948011652,
                                                                 'lon': -0.14327038749428384, 'lat': 51.52130909540579},
                                                      'destination': {'x': 528780.3405144282, 'y': 181859.84184561518,
                                                                      'lon': -0.14523808749533396,
                                                                      'lat': 51.520983695405526},
                                                      'path_polyline': 'ewmyHl~ZJnAt@xH??'},
                                             (5, 3): {'path_nodes': (5, 3),
                                                      'origin': {'x': 528888.1581643537, 'y': 181892.3086225874,
                                                                 'lon': -0.14367308749449406, 'lat': 51.52125089540575},
                                                      'destination': {'x': 528780.3405144282, 'y': 181859.84184561518,
                                                                      'lon': -0.14523808749533396,
                                                                      'lat': 51.520983695405526},
                                                      'path_polyline': 'yvmyH|`[KoA`AhK'},
                                             (1, 10): {'path_nodes': (1, 10),
                                                       'origin': {'x': 528915.9309752393, 'y': 181899.48948011652,
                                                                  'lon': -0.14327038749428384,
                                                                  'lat': 51.52130909540579},
                                                       'destination': {'x': 528780.3405144282, 'y': 181892.3086225874,
                                                                       'lon': -0.14522623292591474,
                                                                       'lat': 51.521275465129236},
                                                       'path_polyline': 'ewmyHl~ZDfK'}})