U
    —âñjÉ  ã                   @   s0   d dl mZ d dlmZmZ dd„ Zdd„ ZdS )é    )Ú
Collection)ÚDictÚAnyc                 C   s   t | ƒ d S )N)Úprint)Útext© r   úR/var/www/itgmanager/itgmanager/Analytic/scapp_database/utils/db_colection_utils.pyÚmain_logger   s    r	   c                 C   sž   ||   ¡ kr(|  |¡}td|› d�ƒ n| | }ddg}d}| ¡ }| ¡ D ]*\}}| d¡|krL| dd¡rLd} qxqL|sš|j|dd	� td
|› d�ƒ dS )u»  
    Verifica que la colecciÃ³n exista y que tenga un Ã­ndice Ãºnico compuesto
    por ('day', 1) y ('camera_id', 1). Si la colecciÃ³n o el Ã­ndice no existen,
    se crean.

    Args:
        db (pymongo.database.Database): Objeto de base de datos de PyMongo.
        visitas_collection_name (str): Nombre de la colecciÃ³n a utilizar.

    Returns:
        pymongo.collection.Collection: La colecciÃ³n garantizada con el Ã­ndice deseado.
    u   Creada la colecciÃ³n 'z'.)Údayé   )Ú	camera_idr   FÚkeyÚuniqueT)r   u   Ã�ndice Ãºnico u    creado en la colecciÃ³n.N)Úlist_collection_namesÚcreate_collectionr	   Úindex_informationÚitemsÚgetÚcreate_index)ÚdbZvisitas_collection_nameÚ
collectionZdesired_index_specZindex_existsÚindexesÚ
index_nameZ
index_infor   r   r   Úensure_visitas_coll_and_index   s    
r   N)Úpymongo.collectionr   Útypingr   r   r	   r   r   r   r   r   Ú<module>   s   