o
    Þ!\iµ  ã                   @   s>   d Z ddlmZmZ ddlmZ ddlmZ G dd„ dƒZdS )zModel repositoryé    )ÚOptionalÚList)ÚSession)ÚModelc                   @   s€   e Zd ZdZdefdd„Zdedee fdd„Z	d	e
dee fd
d„Zdee fdd„Zdee fdd„Zdedefdd„ZdS )ÚModelRepositoryz"Repository for ML model operationsÚdbc                 C   s
   || _ d S )N)r   )Úselfr   © r	   úh/var/www/www-root/data/www/176.119.141.140/sports-predictor/app/core/db/repositories/model_repository.pyÚ__init__
   s   
zModelRepository.__init__Úmodel_idÚreturnc                 C   ó   | j  t¡ tj|k¡ ¡ S )zGet model by ID)r   Úqueryr   ÚfilterÚidÚfirst)r   r   r	   r	   r
   Ú	get_by_id   ó   zModelRepository.get_by_idÚversionc                 C   r   )zGet model by version)r   r   r   r   r   r   )r   r   r	   r	   r
   Úget_by_version   r   zModelRepository.get_by_versionc                 C   s(   | j  t¡ tjdk¡ tj ¡ ¡ ¡ S )zGet latest active modelé   )	r   r   r   r   Ú	is_activeÚorder_byÚ
trained_atÚdescr   ©r   r	   r	   r
   Ú
get_latest   s
   ÿþzModelRepository.get_latestc                 C   s   | j  t¡ tj ¡ ¡ ¡ S )zGet all models)r   r   r   r   r   r   Úallr   r	   r	   r
   Úget_all   r   zModelRepository.get_allÚmodelc                 C   s&   | j  |¡ | j  ¡  | j  |¡ |S )zCreate a new model)r   ÚaddÚcommitÚrefresh)r   r    r	   r	   r
   Úcreate   s   
zModelRepository.createN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úintr   r   r   Ústrr   r   r   r   r$   r	   r	   r	   r
   r      s    r   N)	r(   Útypingr   r   Úsqlalchemy.ormr   Úapp.core.db.models.modelr   r   r	   r	   r	   r
   Ú<module>   s
    