more code review feedback

This commit is contained in:
Kenneth Kehl
2024-12-20 08:09:19 -08:00
parent a77343ebc7
commit 3c0621f472
22 changed files with 125 additions and 133 deletions
+16 -16
View File
@@ -33,7 +33,7 @@ def update_fact_notification_status(process_day, notification_type, service_id):
end_date = get_midnight_in_utc(process_day + timedelta(days=1))
# delete any existing rows in case some no longer exist e.g. if all messages are sent
stmt = delete(FactNotificationStatus).filter(
stmt = delete(FactNotificationStatus).where(
FactNotificationStatus.local_date == process_day,
FactNotificationStatus.notification_type == notification_type,
FactNotificationStatus.service_id == service_id,
@@ -55,7 +55,7 @@ def update_fact_notification_status(process_day, notification_type, service_id):
func.count().label("notification_count"),
)
.select_from(NotificationAllTimeView)
.filter(
.where(
NotificationAllTimeView.created_at >= start_date,
NotificationAllTimeView.created_at < end_date,
NotificationAllTimeView.notification_type == notification_type,
@@ -97,7 +97,7 @@ def fetch_notification_status_for_service_by_month(start_date, end_date, service
func.count(NotificationAllTimeView.id).label("count"),
)
.select_from(NotificationAllTimeView)
.filter(
.where(
NotificationAllTimeView.service_id == service_id,
NotificationAllTimeView.created_at >= start_date,
NotificationAllTimeView.created_at < end_date,
@@ -122,7 +122,7 @@ def fetch_notification_status_for_service_for_day(fetch_day, service_id):
func.count().label("count"),
)
.select_from(Notification)
.filter(
.where(
Notification.created_at >= get_midnight_in_utc(fetch_day),
Notification.created_at
< get_midnight_in_utc(fetch_day + timedelta(days=1)),
@@ -260,7 +260,7 @@ def fetch_notification_status_totals_for_all_services(start_date, end_date):
func.sum(FactNotificationStatus.notification_count).label("count"),
)
.select_from(FactNotificationStatus)
.filter(
.where(
FactNotificationStatus.local_date >= start_date,
FactNotificationStatus.local_date <= end_date,
)
@@ -279,7 +279,7 @@ def fetch_notification_status_totals_for_all_services(start_date, end_date):
Notification.key_type.cast(db.Text),
func.count().label("count"),
)
.filter(Notification.created_at >= today)
.where(Notification.created_at >= today)
.group_by(
Notification.notification_type,
Notification.status,
@@ -313,7 +313,7 @@ def fetch_notification_statuses_for_job(job_id):
func.sum(FactNotificationStatus.notification_count).label("count"),
)
.select_from(FactNotificationStatus)
.filter(
.where(
FactNotificationStatus.job_id == job_id,
)
.group_by(FactNotificationStatus.notification_status)
@@ -338,7 +338,7 @@ def fetch_stats_for_all_services_by_date_range(
func.sum(FactNotificationStatus.notification_count).label("count"),
)
.select_from(FactNotificationStatus)
.filter(
.where(
FactNotificationStatus.local_date >= start_date,
FactNotificationStatus.local_date <= end_date,
FactNotificationStatus.service_id == Service.id,
@@ -357,7 +357,7 @@ def fetch_stats_for_all_services_by_date_range(
)
)
if not include_from_test_key:
stats = stats.filter(FactNotificationStatus.key_type != KeyType.TEST)
stats = stats.where(FactNotificationStatus.key_type != KeyType.TEST)
if start_date <= utc_now().date() <= end_date:
today = get_midnight_in_utc(utc_now())
@@ -369,7 +369,7 @@ def fetch_stats_for_all_services_by_date_range(
func.count(Notification.id).label("count"),
)
.select_from(Notification)
.filter(Notification.created_at >= today)
.where(Notification.created_at >= today)
.group_by(
Notification.notification_type,
Notification.status,
@@ -377,7 +377,7 @@ def fetch_stats_for_all_services_by_date_range(
)
)
if not include_from_test_key:
substmt = substmt.filter(Notification.key_type != KeyType.TEST)
substmt = substmt.where(Notification.key_type != KeyType.TEST)
substmt = substmt.subquery()
stats_for_today = select(
@@ -435,7 +435,7 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
func.sum(FactNotificationStatus.notification_count).label("count"),
)
.join(Template, FactNotificationStatus.template_id == Template.id)
.filter(
.where(
FactNotificationStatus.service_id == service_id,
FactNotificationStatus.local_date >= start_date,
FactNotificationStatus.local_date <= end_date,
@@ -473,7 +473,7 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
Template,
Notification.template_id == Template.id,
)
.filter(
.where(
Notification.created_at >= today,
Notification.service_id == service_id,
Notification.key_type != KeyType.TEST,
@@ -539,14 +539,14 @@ def get_total_notifications_for_date_range(start_date, end_date):
)
).label("sms"),
)
.filter(
.where(
FactNotificationStatus.key_type != KeyType.TEST,
)
.group_by(FactNotificationStatus.local_date)
.order_by(FactNotificationStatus.local_date)
)
if start_date and end_date:
stmt = stmt.filter(
stmt = stmt.where(
FactNotificationStatus.local_date >= start_date,
FactNotificationStatus.local_date <= end_date,
)
@@ -629,7 +629,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
).label("count_sent"),
)
.join(Service, FactNotificationStatus.service_id == Service.id)
.filter(
.where(
FactNotificationStatus.notification_status != NotificationStatus.CREATED,
Service.active.is_(True),
FactNotificationStatus.key_type != KeyType.TEST,