mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Add dao method to get template stats per month in financial year for service
This commit is contained in:
@@ -29,6 +29,7 @@ from app.models import (
|
||||
NOTIFICATION_STATUS_TYPES,
|
||||
TEMPLATE_TYPES,
|
||||
)
|
||||
from app.service.statistics import format_monthly_template_notification_stats
|
||||
from app.statsd_decorators import statsd
|
||||
from app.utils import get_london_month_from_utc_column
|
||||
|
||||
@@ -224,6 +225,38 @@ def _stats_for_service_query(service_id):
|
||||
)
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_fetch_monthly_historical_stats_by_template_for_service(service_id, year):
|
||||
month = get_london_month_from_utc_column(NotificationHistory.created_at)
|
||||
|
||||
sq = db.session.query(
|
||||
NotificationHistory.template_id,
|
||||
NotificationHistory.status,
|
||||
month.label('month'),
|
||||
func.count().label('count')
|
||||
).filter(
|
||||
NotificationHistory.service_id == service_id,
|
||||
NotificationHistory.created_at.between(*get_financial_year(year))
|
||||
).group_by(
|
||||
month,
|
||||
NotificationHistory.template_id,
|
||||
NotificationHistory.status
|
||||
).subquery()
|
||||
|
||||
rows = db.session.query(
|
||||
Template.id.label('template_id'),
|
||||
Template.name,
|
||||
sq.c.status,
|
||||
sq.c.count.label('count'),
|
||||
sq.c.month
|
||||
).join(
|
||||
sq,
|
||||
sq.c.template_id == Template.id
|
||||
).all()
|
||||
|
||||
return format_monthly_template_notification_stats(year, rows)
|
||||
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_fetch_monthly_historical_stats_for_service(service_id, year):
|
||||
month = get_london_month_from_utc_column(NotificationHistory.created_at)
|
||||
|
||||
Reference in New Issue
Block a user