File: //home/arjun/projects/buyercall/buyercall/blueprints/admin/__pycache__/models.cpython-310.pyc
o
�we� � @ sl d dl mZmZ d dlmZ d dlmZ d dlmZ d dl m
Z
d dlmZ d dl
mZ G dd � d e�Zd
S )� )�and_�func)�text)�db)�User)�Issue)�Subscription)�PartnershipAccountc @ sT e Zd Zedd� �Zedd� �Zedd� �Zedd� �Zed d
� �Zedd� �Z d
S )� Dashboardc C sd t j�t��tj�d���� }t j�t�tj ���
� }|dkr"d}nt|t|� d d�}|||fS )z`
Obtain coupon usage statistics across all subscribers.
:return: tuple
Nr �d � )
r �session�queryr �filter�coupon�isnot�countr �id�scalar�round�float)�cls�not_null�total�percent� r �C/home/arjun/projects/buyercall/buyercall/blueprints/admin/models.py�group_and_count_coupons s
��
z!Dashboard.group_and_count_couponsc C sz |j dkr+tj�tj��tj|jktjdk��� }t tj�
|�tjtjktj
dk�}n
|j dv r5tj
dk}t�ttj|�S )zZ
Perform a group by/count on all subscriber types.
:return: dict
�partnerT�active)�sysadmin�
limitsysadmin)�roler r �
with_entitiesr r �partnership_idr �allr �in_�subscription_idr �statusr
�group_and_count�plan)r �current_user�ids�
filter_expr r r �group_and_count_plans s
��
�
zDashboard.group_and_count_plansc C s t �ttj�S )zT
Perform a group by/count on all user types.
:return: dict
)r
�_group_and_countr r"