Merge branch 'master' into bump_utils_2301

This commit is contained in:
Athanasios Voutsadakis
2017-11-20 17:40:45 +00:00
6 changed files with 270 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()