mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
The provider_statistics table is no longer being populated, get rid of any reads from this table.
37 lines
934 B
Python
37 lines
934 B
Python
from sqlalchemy import func
|
|
|
|
from app import db
|
|
from app.models import (
|
|
NotificationHistory,
|
|
SMS_TYPE,
|
|
EMAIL_TYPE,
|
|
NOTIFICATION_STATUS_TYPES_BILLABLE,
|
|
KEY_TYPE_TEST
|
|
)
|
|
|
|
|
|
def get_fragment_count(service_id):
|
|
shared_filters = [
|
|
NotificationHistory.service_id == service_id,
|
|
NotificationHistory.status.in_(NOTIFICATION_STATUS_TYPES_BILLABLE),
|
|
NotificationHistory.key_type != KEY_TYPE_TEST
|
|
]
|
|
|
|
sms_count = db.session.query(
|
|
func.sum(NotificationHistory.billable_units)
|
|
).filter(
|
|
NotificationHistory.notification_type == SMS_TYPE,
|
|
*shared_filters
|
|
)
|
|
|
|
email_count = db.session.query(
|
|
func.count(NotificationHistory.id)
|
|
).filter(
|
|
NotificationHistory.notification_type == EMAIL_TYPE,
|
|
*shared_filters
|
|
)
|
|
return {
|
|
'sms_count': int(sms_count.scalar() or 0),
|
|
'email_count': email_count.scalar() or 0
|
|
}
|