From 5b667a16a5582eda893f52923b95dcfd6ba0124c Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 18 Nov 2024 07:09:42 -0800 Subject: [PATCH] more --- app/dao/fact_notification_status_dao.py | 30 ++++++++++++------------- app/dao/services_dao.py | 28 +++++++++++------------ app/dao/uploads_dao.py | 12 +++++----- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/app/dao/fact_notification_status_dao.py b/app/dao/fact_notification_status_dao.py index 4b238642e..a0119fd91 100644 --- a/app/dao/fact_notification_status_dao.py +++ b/app/dao/fact_notification_status_dao.py @@ -191,7 +191,7 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days( all_stats_alias = aliased(all_stats_union, name="all_stats") # Final query with optional template joins - query = select( + querie = select( *( [ TemplateFolder.name.label("folder"), @@ -214,8 +214,8 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days( ) if by_template: - query = ( - query.join(Template, all_stats_alias.c.template_id == Template.id) + querie = ( + querie.join(Template, all_stats_alias.c.template_id == Template.id) .join(User, Template.created_by_id == User.id) .outerjoin( template_folder_map, Template.id == template_folder_map.c.template_id @@ -227,7 +227,7 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days( ) # Group by all necessary fields except date_used - query = query.group_by( + querie = querie.group_by( *( [ TemplateFolder.name, @@ -245,7 +245,7 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days( ) # Execute the query using Flask-SQLAlchemy's session - result = db.session.execute(query) + result = db.session.execute(querie) return result.mappings().all() @@ -361,7 +361,7 @@ def fetch_stats_for_all_services_by_date_range( if start_date <= utc_now().date() <= end_date: today = get_midnight_in_utc(utc_now()) - subquery = ( + subquerie = ( select( Notification.notification_type.label("notification_type"), Notification.status.label("status"), @@ -377,8 +377,8 @@ def fetch_stats_for_all_services_by_date_range( ) ) if not include_from_test_key: - subquery = subquery.filter(Notification.key_type != KeyType.TEST) - subquery = subquery.subquery() + subquerie = subquerie.filter(Notification.key_type != KeyType.TEST) + subquerie = subquerie.subquery() stats_for_today = select( Service.id.label("service_id"), @@ -386,10 +386,10 @@ def fetch_stats_for_all_services_by_date_range( Service.restricted.label("restricted"), Service.active.label("active"), Service.created_at.label("created_at"), - subquery.c.notification_type.cast(db.Text).label("notification_type"), - subquery.c.status.cast(db.Text).label("status"), - subquery.c.count.label("count"), - ).outerjoin(subquery, subquery.c.service_id == Service.id) + subquerie.c.notification_type.cast(db.Text).label("notification_type"), + subquerie.c.status.cast(db.Text).label("status"), + subquerie.c.count.label("count"), + ).outerjoin(subquerie, subquerie.c.service_id == Service.id) all_stats_table = stats.union_all(stats_for_today).subquery() query = ( @@ -515,7 +515,7 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id): def get_total_notifications_for_date_range(start_date, end_date): - query = ( + querie = ( select( FactNotificationStatus.local_date.label("local_date"), func.sum( @@ -546,11 +546,11 @@ def get_total_notifications_for_date_range(start_date, end_date): .order_by(FactNotificationStatus.local_date) ) if start_date and end_date: - query = query.filter( + querie = querie.filter( FactNotificationStatus.local_date >= start_date, FactNotificationStatus.local_date <= end_date, ) - return db.session.execute(query).all() + return db.session.execute(querie).all() def fetch_monthly_notification_statuses_per_service(start_date, end_date): diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 260008193..6dd8cef91 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -514,7 +514,7 @@ def dao_fetch_todays_stats_for_all_services( start_date = get_midnight_in_utc(today) end_date = get_midnight_in_utc(today + timedelta(days=1)) - subquery = ( + subquerie = ( select( Notification.notification_type, Notification.status, @@ -530,9 +530,9 @@ def dao_fetch_todays_stats_for_all_services( ) if not include_from_test_key: - subquery = subquery.filter(Notification.key_type != KeyType.TEST) + subquerie = subquerie.filter(Notification.key_type != KeyType.TEST) - subquery = subquery.subquery() + subquerie = subquerie.subquery() stmt = ( select( @@ -541,11 +541,11 @@ def dao_fetch_todays_stats_for_all_services( Service.restricted, Service.active, Service.created_at, - subquery.c.notification_type, - subquery.c.status, - subquery.c.count, + subquerie.c.notification_type, + subquerie.c.status, + subquerie.c.count, ) - .outerjoin(subquery, subquery.c.service_id == Service.id) + .outerjoin(subquerie, subquerie.c.service_id == Service.id) .order_by(Service.id) ) @@ -617,7 +617,7 @@ def dao_find_services_sending_to_tv_numbers(start_date, end_date, threshold=500) def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=10000): - subquery = ( + subquerie = ( select( func.count(Notification.id).label("total_count"), Notification.service_id.label("service_id"), @@ -637,19 +637,19 @@ def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=10 .having(func.count(Notification.id) >= threshold) ) - subquery = subquery.subquery() + subquerie = subquerie.subquery() stmt = ( select( Notification.service_id.label("service_id"), func.count(Notification.id).label("permanent_failure_count"), - subquery.c.total_count.label("total_count"), + subquerie.c.total_count.label("total_count"), ( cast(func.count(Notification.id), Float) - / cast(subquery.c.total_count, Float) + / cast(subquerie.c.total_count, Float) ).label("permanent_failure_rate"), ) - .join(subquery, subquery.c.service_id == Notification.service_id) + .join(subquerie, subquerie.c.service_id == Notification.service_id) .filter( Notification.service_id == Service.id, Notification.created_at >= start_date, @@ -660,10 +660,10 @@ def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=10 Service.restricted == False, # noqa Service.active == True, # noqa ) - .group_by(Notification.service_id, subquery.c.total_count) + .group_by(Notification.service_id, subquerie.c.total_count) .having( cast(func.count(Notification.id), Float) - / cast(subquery.c.total_count, Float) + / cast(subquerie.c.total_count, Float) >= 0.25 ) ) diff --git a/app/dao/uploads_dao.py b/app/dao/uploads_dao.py index 1f7b7021c..4f0e65a1e 100644 --- a/app/dao/uploads_dao.py +++ b/app/dao/uploads_dao.py @@ -93,7 +93,7 @@ def dao_get_uploads_by_service_id(service_id, limit_days=None, page=1, page_size Notification.created_at >= midnight_n_days_ago(limit_days) ) - letters_subquery = ( + letters_subquerie = ( db.session.query( func.count().label("notification_count"), _naive_gmt_to_utc(_get_printing_datetime(Notification.created_at)).label( @@ -117,18 +117,18 @@ def dao_get_uploads_by_service_id(service_id, limit_days=None, page=1, page_size letters_query = db.session.query( literal(None).label("id"), literal("Uploaded letters").label("original_file_name"), - letters_subquery.c.notification_count.label("notification_count"), + letters_subquerie.c.notification_count.label("notification_count"), literal("letter").label("template_type"), literal(None).label("days_of_retention"), - letters_subquery.c.printing_at.label("created_at"), + letters_subquerie.c.printing_at.label("created_at"), literal(None).label("scheduled_for"), - letters_subquery.c.printing_at.label("processing_started"), + letters_subquerie.c.printing_at.label("processing_started"), literal(None).label("status"), literal("letter_day").label("upload_type"), literal(None).label("recipient"), ).group_by( - letters_subquery.c.notification_count, - letters_subquery.c.printing_at, + letters_subquerie.c.notification_count, + letters_subquerie.c.printing_at, ) return (