cleanup, get rid of print statements, etc.

This commit is contained in:
Kenneth Kehl
2023-06-15 10:45:03 -07:00
parent 95a2db6991
commit e4a98dfcc2
5 changed files with 35 additions and 39 deletions

View File

@@ -23,6 +23,7 @@ from app.models import (
NOTIFICATION_TEMPORARY_FAILURE,
FactNotificationStatus,
Notification,
NotificationAllTimeView,
Service,
Template,
)
@@ -37,7 +38,6 @@ from app.utils import (
def update_fact_notification_status(process_day, notification_type, service_id):
start_date = get_midnight_in_utc(process_day)
end_date = get_midnight_in_utc(process_day + timedelta(days=1))
print(f"fact start {start_date} and end {end_date}")
# delete any existing rows in case some no longer exist e.g. if all messages are sent
FactNotificationStatus.query.filter(
@@ -48,25 +48,25 @@ def update_fact_notification_status(process_day, notification_type, service_id):
query = db.session.query(
literal(process_day).label("process_day"),
Notification.template_id,
NotificationAllTimeView.template_id,
literal(service_id).label("service_id"),
func.coalesce(Notification.job_id, '00000000-0000-0000-0000-000000000000').label('job_id'),
func.coalesce(NotificationAllTimeView.job_id, '00000000-0000-0000-0000-000000000000').label('job_id'),
literal(notification_type).label("notification_type"),
Notification.key_type,
Notification.status,
NotificationAllTimeView.key_type,
NotificationAllTimeView.status,
func.count().label('notification_count')
).filter(
Notification.created_at >= start_date,
Notification.created_at < end_date,
Notification.notification_type == notification_type,
Notification.service_id == service_id,
Notification.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
NotificationAllTimeView.created_at >= start_date,
NotificationAllTimeView.created_at < end_date,
NotificationAllTimeView.notification_type == notification_type,
NotificationAllTimeView.service_id == service_id,
NotificationAllTimeView.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
).group_by(
Notification.template_id,
Notification.template_id,
NotificationAllTimeView.template_id,
NotificationAllTimeView.template_id,
'job_id',
Notification.key_type,
Notification.status
NotificationAllTimeView.key_type,
NotificationAllTimeView.status
)
db.session.connection().execute(
@@ -167,14 +167,12 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days(service_
if by_template:
query = query.filter(all_stats_table.c.template_id == Template.id)
x = query.group_by(
return query.group_by(
*([Template.name, all_stats_table.c.template_id] if by_template else []),
all_stats_table.c.notification_type,
all_stats_table.c.status,
).all()
return x
def fetch_notification_status_totals_for_all_services(start_date, end_date):
stats = db.session.query(

View File

@@ -238,7 +238,6 @@ def get_notifications_for_service(
query = Notification.query.filter(*filters)
query = _filter_query(query, filter_dict)
print(f"QUERY IS {query}")
if personalisation:
query = query.options(
joinedload('template')
@@ -262,16 +261,10 @@ def _filter_query(query, filter_dict=None):
statuses = multidict.getlist('status')
if statuses:
statuses = Notification.substitute_status(statuses)
# TODO WHY
if len(statuses) == 5 and 'temporary-failure' in statuses:
statuses = ['failed']
elif len(statuses) == 10:
statuses = ['failed', 'sending', 'delivered']
elif statuses == ['pending']:
statuses = ['sending']
print(f"STATUSES = {statuses}")
# statuses = Notification.substitute_status(statuses)
if statuses == ['pending']:
statuses = ['sending']
query = query.filter(Notification.status.in_(statuses))
# filter by template