Updates after review

- Modified the services_dao to return an int instead of a datetime to
make usage easier and removed the BST function on year as it is not
relevant for year
- Improved tests do there is less logic by ordering the result so there
is less reliance on the template id
- Renamed variable in stats_template_usage_by_month_dao.py to make it
consistent with the method
This commit is contained in:
Richard Chapman
2017-11-09 14:13:42 +00:00
parent 59df6bdbb6
commit b78d989d4e
14 changed files with 76 additions and 148 deletions

View File

@@ -40,7 +40,7 @@ from app.models import (
)
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, get_london_midnight_in_utc, get_london_year_from_utc_column
from app.utils import get_london_month_from_utc_column, get_london_midnight_in_utc
from app.dao.annual_billing_dao import dao_insert_annual_billing
DEFAULT_SERVICE_PERMISSIONS = [
@@ -525,13 +525,13 @@ def dao_fetch_active_users_for_service(service_id):
@statsd(namespace="dao")
def dao_fetch_monthly_historical_stats_by_template():
month = get_london_month_from_utc_column(NotificationHistory.created_at)
year = get_london_year_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,
month.label('month'),
year.label('year'),
extract('month', month).label('month'),
extract('year', year).label('year'),
func.count().label('count')
).filter(
NotificationHistory.created_at < end_date