def execute(download=True): res = reset_database(download) # Conexiones a todas las bases de datos, para ver que incluye el resultado descomentar la siguiente lInea # pprint(res) autorizados = connect(res[0][0], res[0][1]) flota = connect(res[1][0], res[1][1]) # 1. CORRECCION DE ELEMENTOS ERRoNEOS coches_no(flota) suprimir_no(flota) coches_no(flota) # 2. OPERACIONES flota documentos_disponibles(flota) tiempo_licencias(flota) mostrar_10_documentos(flota) media_obtencion_licencias(flota) # 3. OPERACIONES autorizados autorizados_combustible(autorizados) creacion_vehiculos(autorizados) # 4. OPERACIONES vehiculos vehiculos = connect(res[0][0], 'vehiculos') vehiculos_por_marca(vehiculos) aplanado_modelos(vehiculos) vehiculos_aplanado = connect(res[0][0], 'vehiculos_aplanado') actualizacion_vehiculos(vehiculos) mostrar_1_documento(vehiculos) limpieza_modelos_vehiculos(vehiculos) mostrar_10_documentos(vehiculos) documentos_disponibles(autorizados) vehiculo_mas_comprado(vehiculos_aplanado)
def execute(): res = reset_dataset() coll = connect(res[0], res[1]) ej1(coll) ej2(coll) ej3(coll) coll2 = connect('clase', 'datasetaplanado') ej4(coll2) ej5(coll2) ej6(coll2) ej7(coll2)
def ej3(collection): collection.aggregate([ { '$unwind': '$grades' }, { '$project': { '_id': 0, 'building': "$address.building", 'street': "$address.street", 'zipcode': '$address.zipcode', 'borough': 1, 'cuisine': 1, 'date': '$address.date', 'grade': '$grades.grade', 'score': '$grades.score', 'name': 1, 'restaurant_id': 1, }, }, { '$out': 'datasetaplanado' }, ]) print( str(connect('clase', 'datasetaplanado').count({})) + " documento/s\n")
def taxi_download(download=True): """ Donwload taxi files :param download: True to download data, False to use downloaded datasets :return: list of tuples ('database', 'collection') imported """ csv_paths = dict() json_paths = dict() csv_links = dict({ 'autorizados': 'https://datos.madrid.es/egob/catalogo/207347-1-taxi-modelo-vehiculos.csv', 'flota': 'https://datos.madrid.es/egob/catalogo/300226-0-taxi-flota-diaria.csv', }) # Download and parse csv to json files for key, csv_link in csv_links.items(): if download: json_path = csv_to_json(download_csv(csv_link)) else: json_path = get_json_path( os.path.basename(csv_link).replace('csv', 'json')) json_paths[key] = json_path # Bulk Import of json files for key, json_path in json_paths.items(): c = connect('practica', key) c.drop() bulk_file_import(c, json_path) return [('practica', key) for key in json_paths.keys()]
def execute(): coll = connect('clase', 'arts') reset_arts(coll) ej1(coll) ej2(coll) ej3(coll) ej2(coll) ej4(coll) ej5(coll)
def incidences_download(): """ Dataset of incidences downloader :return: list of tuples ('database', 'collection') imported """ link_json = 'https://datosabiertos.jcyl.es/web/jcyl/risp/es/transporte/incidencias_carreteras/1284212099243.json' json_path = download_json(link_json) c = connect('datos_abiertos', 'incidencias') c.drop() bulk_file_import(c, json_path) return [('datos_abiertos', 'incidencias')]
def twitter_download(): """ Dataset of twitter downloader :return: list of tuples ('database', 'collection') imported """ link_zip = 'https://drive.google.com/uc?export=download&id=1aqZUFkAm1EW9H8skKnhfAeAhIO28TZjl' json_path = get_json_path('twitter.json') zip_path = download_zip(link_zip) with zipfile.ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(get_json_path()) c = connect('clase', 'twitter') c.drop() bulk_file_mongoimport(c, json_path) return [('clase', 'twitter')]
def full_primer_dataset_download(): """ Dataset of full_primer-dataset downloader :return: list of tuples ('database', 'collection') imported """ link_zip = 'https://drive.google.com/uc?export=download&id=1WswYNzSv-R7ultIs7CB-xsO9WepT-YQT' json_path = get_json_path('full_primer-dataset.json') zip_path = download_zip(link_zip) with zipfile.ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(get_json_path()) c = connect('clase', 'primer') c.drop() bulk_file_mongoimport(c, json_path) return [('clase', 'primer')]
def restaurants_download(): """ Dataset of restaurants downloader :return: list of tuples ('database', 'collection') imported """ link_zip = 'https://drive.google.com/uc?export=download&id=1qUgzM5JHvnH2d1Ayh8oES9BIZPj03Nol' json_path = get_json_path('restaurants.json') zip_path = download_zip(link_zip) with zipfile.ZipFile(zip_path, 'r') as zip_ref: zip_ref.extractall(get_json_path()) c = connect('clase', 'restaurant') c.drop() bulk_file_mongoimport(c, json_path) return [('clase', 'restaurant')]
def execute(): res = reset_dataset() coll = connect(res[0], res[1]) ej1(coll) ej2(coll)
def reset_dataset(): connect('clase', 'datasetaplanado').drop() return full_primer_dataset_download()[0]
def reset_database(download=True): mas_info = 'https://datos.gob.es/en/catalogo/l01280796-taxi-tarifas-suplementos-municipios-paradas-eventuales-regimen-de-descanso-y-duracion-del-servicio' connect('practica', 'vehiculos').drop() connect('practica', 'vehiculos_aplanado').drop() return taxi_download(download)
def execute(): coll = connect('clase', 'inventory') reset_dataset(coll) ej1(coll) ej2_1(coll) ej2_2(coll)