Ejemplo n.º 1
0
def get_ways(min_lvl, max_lvl, name):
    db = get_mongo()[DB_NAME]
    ways = db.ways
    speed_limit = (get_speed_from_lvl(max_lvl)[0], get_speed_from_lvl(min_lvl)[1])
    print(name)
    if name == "":
        res = ways.find(
            {
                'avg_speed':
                    {
                        '$gte': speed_limit[0],
                        '$lte': speed_limit[1]
                    }
            }
        )
    else:
        res = ways.find(
            {
                'tags.name': {'$regex': name},
                'avg_speed':
                    {
                        '$gte': speed_limit[0],
                        '$lte': speed_limit[1]
                    }
            }
        )
    return res
Ejemplo n.º 2
0
def create_db(name):
    client = get_mongo()
    db = client[name]
    dbnodes = db.nodes
    dbways = db.ways
    dbrelations = db.relations
    db_clear(db)
    return db
Ejemplo n.º 3
0
def get_lvl_count(lvl):
    speed = get_speed_from_lvl(lvl)
    ways = get_mongo()[DB_NAME].ways
    res = ways.find({
        'avg_speed': {
            '$gte': speed[0],
            '$lte': speed[1]
        }
    }).count()
    return res
Ejemplo n.º 4
0
def update_data():
    time.sleep(60)
    mongo = get_mongo()
    db = mongo[DB_NAME]
    if mongo is None:
        print("Starting second thread failed")
        return None
    count = db.ways.count()
    print("Second thread started")
    while True:
        update_all_at_once(db.ways.find(), db)
Ejemplo n.º 5
0
def write_data_to_json(collection_name, path='./'):
    try:
        os.mkdir(path)
    except OSError:
        pass
    db = get_mongo()[DB_NAME]
    collection = db.get_collection(collection_name)
    doc_list = list(collection.find())
    filename = f'{path}/{collection_name}.json'
    with open(filename, 'w') as outfile:
        json.dump(doc_list, outfile, ensure_ascii=False)
    return filename
Ejemplo n.º 6
0
def get_ways(nodes, category):
    db = get_mongo()[DB_NAME]
    node_pairs = []
    for i in range(len(nodes) - 1):
        node_pairs.append({'nodes': {'$all': [nodes[i], nodes[i + 1]]}})
    speed_limit = (get_speed_from_lvl(category[1])[0],
                   get_speed_from_lvl(category[0])[1])
    ways = db.ways.find({
        '$and': [{
            '$or': node_pairs
        }, {
            'avg_speed': {
                '$gte': speed_limit[0],
                '$lte': speed_limit[1]
            }
        }]
    })
    return list(ways)
Ejemplo n.º 7
0
def pls_import_collection(collection_name, data):
    db = get_mongo()[DB_NAME]
    collection = db.get_collection(collection_name)
    print('Import started')
    try:
        update_el = [
            UpdateOne({'_id': el['_id']}, {'$set': el}, upsert=True)
            for el in data
        ]
        result = collection.bulk_write(update_el)
        print(f"(Import) Values updated, errors: {result.bulk_api_result}")
    except BulkWriteError as bwe:
        print(bwe.details)
        return {'error': str(bwe.details)}
    except BaseException as err:
        print("Unrecognized error in import:\n {}".format(err))
        return {'error': "Unrecognized error in import:\n {}".format(err)}
    return None
Ejemplo n.º 8
0
from models.get_model import get_mongo, DB_NAME
from math import radians
import json
import numpy
import time

# this is mongo!
db = get_mongo()[DB_NAME]
FIND_RANGE = 0.001

CORRECT_HIGHWAY_TAGS = [
    'motorway', 'motorway_link', 'trunk', 'trunk_link', 'primary',
    'primary_link', 'secondary', 'secondary_link', 'tertiary', 'tertiary_link',
    'unclassified', 'unclassified_link'
]

TIMEOUT = 30


def find_paths(x0, y0, x1, y1):
    nodeid_from = find_nearest_node(x0, y0)
    nodeid_to = find_nearest_node(x1, y1)
    way = find_way(nodeid_from, nodeid_to)
    if (nodeid_from is None) or (nodeid_to is None) or (way == []):
        return [[x0, y0], [x1, y1]]
    else:
        return [[x0, y0]] + way + [[x1, y1]]


def find_nearest_node(x, y):
    dbnodes = db.nodes