mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Add an endpoint to return all the data required for the performance
platform page.
This commit is contained in:
@@ -442,6 +442,37 @@ def get_total_sent_notifications_for_day_and_type(day, notification_type):
|
||||
return result or 0
|
||||
|
||||
|
||||
def get_total_notifications_for_date_range(start_date, end_date):
|
||||
|
||||
result = db.session.query(
|
||||
FactNotificationStatus.bst_date.cast(db.Text).label("bst_date"),
|
||||
func.sum(case(
|
||||
[
|
||||
(FactNotificationStatus.notification_type == 'email', FactNotificationStatus.notification_count)
|
||||
],
|
||||
else_=0)).label('emails'),
|
||||
func.sum(case(
|
||||
[
|
||||
(FactNotificationStatus.notification_type == 'sms', FactNotificationStatus.notification_count)
|
||||
],
|
||||
else_=0)).label('sms'),
|
||||
func.sum(case(
|
||||
[
|
||||
(FactNotificationStatus.notification_type == 'letter', FactNotificationStatus.notification_count)
|
||||
],
|
||||
else_=0)).label('letters'),
|
||||
).filter(
|
||||
FactNotificationStatus.key_type != KEY_TYPE_TEST,
|
||||
FactNotificationStatus.bst_date >= start_date,
|
||||
FactNotificationStatus.bst_date <= end_date
|
||||
).group_by(
|
||||
FactNotificationStatus.bst_date
|
||||
).order_by(
|
||||
FactNotificationStatus.bst_date
|
||||
)
|
||||
return result.all()
|
||||
|
||||
|
||||
def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
return db.session.query(
|
||||
func.date_trunc('month', FactNotificationStatus.bst_date).cast(Date).label('date_created'),
|
||||
|
||||
@@ -30,3 +30,18 @@ def insert_update_processing_time(processing_time):
|
||||
}
|
||||
)
|
||||
db.session.connection().execute(stmt)
|
||||
|
||||
|
||||
def get_processing_time_percentage_for_date_range(start_date, end_date):
|
||||
query = db.session.query(
|
||||
FactProcessingTime.bst_date.cast(db.Text).label("date"),
|
||||
FactProcessingTime.messages_total,
|
||||
FactProcessingTime.messages_within_10_secs,
|
||||
((FactProcessingTime.messages_within_10_secs / FactProcessingTime.messages_total.cast(
|
||||
db.Float)) * 100).label("percentage")
|
||||
).filter(
|
||||
FactProcessingTime.bst_date >= start_date,
|
||||
FactProcessingTime.bst_date <= end_date
|
||||
).order_by(FactProcessingTime.bst_date)
|
||||
|
||||
return query.all()
|
||||
|
||||
@@ -614,3 +614,23 @@ def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=10
|
||||
)
|
||||
|
||||
return query.all()
|
||||
|
||||
|
||||
def get_live_services_with_organisation():
|
||||
query = db.session.query(
|
||||
Service.id.label("service_id"),
|
||||
Service.name.label("service_name"),
|
||||
Organisation.id.label("organisation_id"),
|
||||
Organisation.name.label("organisation_name")
|
||||
).outerjoin(
|
||||
Service.organisation
|
||||
).filter(
|
||||
Service.count_as_live.is_(True),
|
||||
Service.active.is_(True),
|
||||
Service.restricted.is_(False)
|
||||
).order_by(
|
||||
Organisation.name,
|
||||
Service.name
|
||||
)
|
||||
|
||||
return query.all()
|
||||
Reference in New Issue
Block a user