Merge branch 'master' into remove-initial-update-sms-sender

This commit is contained in:
Rebecca Law
2017-11-14 16:27:10 +00:00
36 changed files with 1113 additions and 157 deletions

View File

@@ -1,7 +1,7 @@
import uuid
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, time
from sqlalchemy import asc, func
from sqlalchemy import asc, func, extract
from sqlalchemy.orm import joinedload
from flask import current_app
@@ -519,3 +519,25 @@ def dao_fetch_active_users_for_service(service_id):
)
return query.all()
@statsd(namespace="dao")
def dao_fetch_monthly_historical_stats_by_template():
month = get_london_month_from_utc_column(NotificationHistory.created_at)
year = func.date_trunc("year", NotificationHistory.created_at)
end_date = datetime.combine(date.today(), time.min)
return db.session.query(
NotificationHistory.template_id,
extract('month', month).label('month'),
extract('year', year).label('year'),
func.count().label('count')
).filter(
NotificationHistory.created_at < end_date
).group_by(
NotificationHistory.template_id,
month,
year
).order_by(
NotificationHistory.template_id
).all()