def nearbyStations(database, longitude, latitude): aspir = queue.newQueue() queue.enqueue( aspir, orderedmap.ceiling(database['position']['latitude'], latitude)) queue.enqueue( aspir, orderedmap.ceiling(database['position']['longitude'], longitude)) queue.enqueue( aspir, orderedmap.floor(database['position']['longitude'], longitude)) queue.enqueue(aspir, orderedmap.floor(database['position']['latitude'], latitude)) val = None wID = None while not queue.isEmpty(aspir): id = queue.dequeue(aspir) id = mapentry.getValue(id) element = map.get(database['station'], id) element = mapentry.getValue(element) dist = abs( Calc.distance(element['latitude'], latitude, element['longitude'], longitude)) if val is None: val = dist wID = id if dist < val: val = dist wID = id return wID
def test_ceil_floor(tree): tree = om.put(tree, 23, 'book21') tree = om.put(tree, 7, 'book7') tree = om.put(tree, 30, 'book30') tree = om.put(tree, 5, 'book5') tree = om.put(tree, 4, 'book4') tree = om.put(tree, 3, 'book3') tree = om.put(tree, 20, 'book20') tree = om.put(tree, 25, 'book25') tree = om.put(tree, 35, 'book35') tree = om.put(tree, 29, 'book29') tree = om.put(tree, 11, 'book11') tree = om.put(tree, 15, 'book15') tree = om.put(tree, 10, 'book10') assert om.floor(tree, 21) == 20 assert om.floor(tree, 25) == 25 assert om.floor(tree, 18) == 15 assert om.ceiling(tree, 16) == 20 assert om.ceiling(tree, 15) == 15 assert om.ceiling(tree, 27) == 29