mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 05:28:49 -04:00
Move DAO function for new platform stats page
Moved the `fetch_new_aggregate_stats_by_date_range_for_all_services` DAO function from the services DAO to the Notifications DAO since this function queries the `notification` and `notification_history` tables. Also added a test to check that the data returned from the function takes BST into account.
This commit is contained in:
@@ -609,3 +609,31 @@ def guess_notification_type(search_term):
|
||||
return EMAIL_TYPE
|
||||
else:
|
||||
return SMS_TYPE
|
||||
|
||||
|
||||
@statsd(namespace='dao')
|
||||
def fetch_new_aggregate_stats_by_date_range_for_all_services(start_date, end_date):
|
||||
start_date = get_london_midnight_in_utc(start_date)
|
||||
end_date = get_london_midnight_in_utc(end_date + timedelta(days=1))
|
||||
table = NotificationHistory
|
||||
|
||||
if start_date >= datetime.utcnow() - timedelta(days=7):
|
||||
table = Notification
|
||||
|
||||
query = db.session.query(
|
||||
table.notification_type,
|
||||
table.status,
|
||||
table.key_type,
|
||||
func.count(table.id).label('count')
|
||||
).filter(
|
||||
table.created_at >= start_date,
|
||||
table.created_at < end_date
|
||||
).group_by(
|
||||
table.notification_type,
|
||||
table.key_type,
|
||||
table.status
|
||||
).order_by(
|
||||
table.notification_type,
|
||||
)
|
||||
|
||||
return query.all()
|
||||
|
||||
@@ -453,34 +453,6 @@ def fetch_aggregate_stats_by_date_range_for_all_services(start_date, end_date, i
|
||||
return query.all()
|
||||
|
||||
|
||||
@statsd(namespace='dao')
|
||||
def fetch_new_aggregate_stats_by_date_range_for_all_services(start_date, end_date):
|
||||
start_date = get_london_midnight_in_utc(start_date)
|
||||
end_date = get_london_midnight_in_utc(end_date + timedelta(days=1))
|
||||
table = NotificationHistory
|
||||
|
||||
if start_date >= datetime.utcnow() - timedelta(days=7):
|
||||
table = Notification
|
||||
|
||||
query = db.session.query(
|
||||
table.notification_type,
|
||||
table.status,
|
||||
table.key_type,
|
||||
func.count(table.id).label('count')
|
||||
).filter(
|
||||
table.created_at >= start_date,
|
||||
table.created_at < end_date
|
||||
).group_by(
|
||||
table.notification_type,
|
||||
table.key_type,
|
||||
table.status
|
||||
).order_by(
|
||||
table.notification_type,
|
||||
)
|
||||
|
||||
return query.all()
|
||||
|
||||
|
||||
@transactional
|
||||
@version_class(Service)
|
||||
@version_class(ApiKey)
|
||||
|
||||
@@ -18,6 +18,7 @@ from app.dao.api_key_dao import (
|
||||
get_unsigned_secret,
|
||||
expire_api_key)
|
||||
from app.dao.inbound_numbers_dao import dao_allocate_number_for_service
|
||||
from app.dao.notifications_dao import fetch_new_aggregate_stats_by_date_range_for_all_services
|
||||
from app.dao.organisation_dao import dao_get_organisation_by_service_id
|
||||
from app.dao.service_sms_sender_dao import (
|
||||
archive_sms_sender,
|
||||
@@ -44,7 +45,6 @@ from app.dao.services_dao import (
|
||||
dao_suspend_service,
|
||||
dao_update_service,
|
||||
fetch_aggregate_stats_by_date_range_for_all_services,
|
||||
fetch_new_aggregate_stats_by_date_range_for_all_services,
|
||||
fetch_stats_by_date_range_for_all_services
|
||||
)
|
||||
from app.dao.service_whitelist_dao import (
|
||||
|
||||
Reference in New Issue
Block a user