Sindbad~EG File Manager

Current Path : /home/numerotech/hs.numerotech.com/scan_v1/core/model/__pycache__/
Upload File :
Current File : //home/numerotech/hs.numerotech.com/scan_v1/core/model/__pycache__/QueryModel.cpython-37.pyc

B

6d��@s~ddlmZddlmZmZmZddlmZmZmZm	Z	m
Z
ddlmZm
Z
ddlmZeejdddd	�ZGd
d�d�ZdS)
�)�session)�request�	Blueprint�jsonify)�
create_engine�select�MetaData�Table�text)�and_�or_)�app�DATABASE_URITi)�
pool_pre_ping�pool_recyclec@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�
QueryModelc
Csdy4t�|_td|jdtd�|_td|jdtd�|_Wn*tk
r^}zt|�Wdd}~XYnXdS)N�abs_session_queriesT)�autoload�
autoload_with�abs_sessions)r�metar	�enginerr�	Exception�print)�self�e�r�V/home/numerote/conference.numerotech.com/food_kit_scan_badges/core/model/QueryModel.py�__init__szQueryModel.__init__cCsht��}tdt|�d|d|d�}|�|�}|��|rPdd�|D�nd}|r`|dSdSdS)Nz)select * from conference where  conf_id =z and conf_key ='z' and 'z' <= conf_end_time ;cSsg|]}t|��qSr)�dict)�.0�rrrr�
<listcomp>sz2QueryModel.getConf_open_closed.<locals>.<listcomp>r)r�connectr
�str�execute�close)r�conf_id�conf_key�
current_dt�conn�stmt�result�resultsrrr�getConf_open_closeds$
zQueryModel.getConf_open_closedcCsZt��}td|d�}|j|||d�}|��|rBdd�|D�nd}|rR|dSdSdS)Nzselect * from z? where conf_id =:conf_id and delegate_no =:delegate_no limit 1;)r'�delegate_nocSsg|]}t|��qSr)r)r r!rrrr"%sz.QueryModel.checkDelegateNo.<locals>.<listcomp>r)rr#r
r%r&)rr'r/�del_table_namer*r+r-rrr�checkDelegateNo szQueryModel.checkDelegateNocCs>t��}|�|j��|�}|��|jdr6|jdnd}|S)Nr)rr#r%r�insertr&�inserted_primary_key)r�datar*r,Zpk_idrrr�insert_delegate_query+s
z QueryModel.insert_delegate_querycCsLt��}td�}|j||d�}|��|r8dd�|D�nd}|rD|SdSdS)NzXSELECT distinct(display_dt),dt from abs_sessions where conf_id=:conf_id  order by dt asc)r'cSsg|]}t|��qSr)r)r r!rrrr"7sz&QueryModel.getDays.<locals>.<listcomp>)rr#r
r%r&)rr'r*r+r-r,rrr�getDays2szQueryModel.getDayscCsNt��}td�}|j|||d�}|��|r:dd�|D�nd}|rF|SdSdS)NzuSELECT distinct(hall),hall_id,dt,display_dt from abs_sessions where conf_id=:conf_id and dt=:conf_date order by hall;)r'�	conf_datecSsg|]}t|��qSr)r)r r!rrrr"Bsz'QueryModel.getHalls.<locals>.<listcomp>)rr#r
r%r&)rr'r7r*r+r-r,rrr�getHalls=szQueryModel.getHallscCsPt��}td�}|j||||d�}|��|r<dd�|D�nd}|rH|SdSdS)Nz�SELECT * from abs_sessions where conf_id=:conf_id and  hall_id=:hall_id and dt=:conf_date  and abs_session_id is not null order by starts_by asc)r'�hall_idr7cSsg|]}t|��qSr)r)r r!rrrr"Msz-QueryModel.getSessionName.<locals>.<listcomp>)rr#r
r%r&)rr'r9r7r*r+r-r,rrr�getSessionNameHszQueryModel.getSessionNamecCs@t��}td�}|j|||d�}|��|��}|r8|SdSdS)NzOselect * from abs_sessions where conf_id=:conf_id and asession_id=:asession_id;)r'�asession_id)rr#r
r%r&�fetchone)rr'r;r*r+r-rrr�get_sessionSszQueryModel.get_sessioncCsJt��}td|d�}|j||||d�}|��|��}|rB|SdSdS)Nz_select * from abs_sessions where conf_id =:conf_id and hall_id=:hall_id and dt=:conf_date and 'z!' between starts_by and ends_by ;)r'r9r7)rr#r
r%r&r<)rr'r)r9r7r*r+r-rrr�getCurrentSession^szQueryModel.getCurrentSessioncCsZt��}td�}|j|||d�}|��|r:dd�|D�nd}t|�|rR|dSdSdS)Nz�select * from  abs_session_queries  where asession_id=:asession_id and date(created_at)=:conf_date order by created_at desc limit 1;)r;r7cSsg|]}t|��qSr)r)r r!rrrr"nsz)QueryModel.getQueries.<locals>.<listcomp>r)rr#r
r%r&r)rr;r7r*r+r-r,rrr�
getQueriesiszQueryModel.getQueriescCsNt��}td�}|j|||d�}|��|r:dd�|D�nd}|rF|SdSdS)Nzxselect * from abs_session_queries where asession_id=:asession_id and created_at >:last_sync_at order by created_at desc;)r;�last_sync_atcSsg|]}t|��qSr)r)r r!rrrr"zsz-QueryModel.getAutoQueries.<locals>.<listcomp>)rr#r
r%r&)rr;r@r*r+r-r,rrr�getAutoQueriesuszQueryModel.getAutoQueriesc	Cs�g}z�t��}|��}|�d|g�xpdd�|jD�}g}x.|��}|dkrNPtt||��}|�|�q<W|�t	|��|�
�dkr�P|jdkr&Pq&WWd|��X|S)N�usp_get_pre_nxt_querycSsg|]}|d�qS)rr)r �crrrr"�sz4QueryModel.usp_get_pre_nxt_query.<locals>.<listcomp>)r�raw_connection�cursor�callproc�descriptionr<r�zip�append�list�nextsetr&)	rr;�sets�
connectionrE�names�set_�row_raw�rowrrrrB�s*


z QueryModel.usp_get_pre_nxt_querycCs�g}z�t��}|��}|�d||||g�xpdd�|jD�}g}	x.|��}
|
dkrTPtt||
��}|	�|�qBW|�t	|	��|�
�dkr�P|jdkr,Pq,WWd|��X|S)N�usp_get_session_querycSsg|]}|d�qS)rr)r rCrrrr"�sz4QueryModel.usp_get_session_query.<locals>.<listcomp>)rrDrErFrGr<rrHrIrJrKr&)rr'r9r7r)rLrMrErNrOrPrQrrrrR�s*


z QueryModel.usp_get_session_queryN)�__name__�
__module__�__qualname__rr.r1r5r6r8r:r=r>r?rArBrRrrrrr
s	 rN)�flaskrrrr�
sqlalchemyrrrr	r
Zsqlalchemy.sqlrr�corer
�configrrrrrr�<module>s

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists