mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
return all zeros when NotificationStatistics dont exist
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import (desc, func, Integer, and_, asc)
|
||||
from sqlalchemy import (desc, func, Integer, and_, or_, asc)
|
||||
from sqlalchemy.sql.expression import cast
|
||||
|
||||
from datetime import (
|
||||
@@ -12,6 +12,7 @@ from werkzeug.datastructures import MultiDict
|
||||
|
||||
from app import db
|
||||
from app.models import (
|
||||
Service,
|
||||
Notification,
|
||||
Job,
|
||||
NotificationStatistics,
|
||||
@@ -57,6 +58,51 @@ def dao_get_notification_statistics_for_day(day):
|
||||
).all()
|
||||
|
||||
|
||||
def dao_get_potential_notification_statistics_for_day(day):
|
||||
all_services = db.session.query(
|
||||
Service.id,
|
||||
NotificationStatistics
|
||||
).outerjoin(
|
||||
Service.service_notification_stats
|
||||
).filter(
|
||||
or_(
|
||||
NotificationStatistics.day == day,
|
||||
NotificationStatistics.day == None # noqa
|
||||
)
|
||||
).order_by(
|
||||
asc(Service.created_at)
|
||||
)
|
||||
|
||||
notification_statistics = []
|
||||
for service_notification_stats_pair in all_services:
|
||||
if service_notification_stats_pair.NotificationStatistics:
|
||||
notification_statistics.append(
|
||||
service_notification_stats_pair.NotificationStatistics
|
||||
)
|
||||
else:
|
||||
notification_statistics.append(
|
||||
create_notification_statistics_dict(
|
||||
service_notification_stats_pair,
|
||||
day
|
||||
)
|
||||
)
|
||||
return notification_statistics
|
||||
|
||||
|
||||
def create_notification_statistics_dict(service_id, day):
|
||||
return {
|
||||
'id': None,
|
||||
'emails_requested': 0,
|
||||
'emails_delivered': 0,
|
||||
'emails_failed': 0,
|
||||
'sms_requested': 0,
|
||||
'sms_delivered': 0,
|
||||
'sms_failed': 0,
|
||||
'day': day.isoformat(),
|
||||
'service': service_id
|
||||
}
|
||||
|
||||
|
||||
def dao_get_7_day_agg_notification_statistics_for_service(service_id,
|
||||
date_from,
|
||||
week_count=52):
|
||||
|
||||
Reference in New Issue
Block a user