Return financial year not calendar and ensure double precision values

are not returned from queries

- Updated stats_template_usage_by_month_dao.py to return the results for
financial year not calendar, as the report os for FY only and hence
only the FY data is required
- Updated services_dao.py to ensure double precision values are converted
to an int as the 'exact' function returns double precision from the
database query, as the admin code requires the value for month to be an
int
This commit is contained in:
Richard Chapman
2017-11-20 10:01:45 +00:00
parent b56825a680
commit 58b0658a13
4 changed files with 210 additions and 31 deletions

View File

@@ -550,7 +550,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year)
results = dao_get_template_usage_stats_by_service(service_id, year)
stats = list()
stats = []
for result in results:
stat = type("", (), {})()
stat.template_id = result.template_id
@@ -575,7 +575,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year)
).join(
Template, Notification.template_id == Template.id,
).filter(
Notification.created_at >= start_date
Notification.created_at >= start_date,
).group_by(
Notification.template_id,
Template.name,
@@ -599,8 +599,8 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year)
new_stat.template_id = today_result.template_id
new_stat.template_type = today_result.template_type
new_stat.name = today_result.name
new_stat.month = today_result.month
new_stat.year = today_result.year
new_stat.month = int(today_result.month)
new_stat.year = int(today_result.year)
new_stat.count = today_result.count
stats.append(new_stat)

View File

@@ -1,3 +1,5 @@
from sqlalchemy import or_, and_
from app import db
from app.statsd_decorators import statsd
from app.dao.dao_utils import transactional
@@ -41,6 +43,15 @@ def dao_get_template_usage_stats_by_service(service_id, year):
).join(
Template, StatsTemplateUsageByMonth.template_id == Template.id
).filter(
Template.service_id == service_id,
StatsTemplateUsageByMonth.year == year
Template.service_id == service_id
).filter(
or_(
and_(
StatsTemplateUsageByMonth.month.in_([4, 5, 6, 7, 8, 9, 10, 11, 12]),
StatsTemplateUsageByMonth.year == year
), and_(
StatsTemplateUsageByMonth.month.in_([1, 2, 3]),
StatsTemplateUsageByMonth.year == year + 1
)
)
).all()