Changed template stats for template id

- now returns the most recent notification history row for that template ID.
- contains all the required data for the use cases for that template
This commit is contained in:
Martyn Inglis
2016-08-22 14:35:04 +01:00
parent fdd85b7dc0
commit 4e6da1ba55
4 changed files with 84 additions and 185 deletions

View File

@@ -137,7 +137,6 @@ def dao_get_7_day_agg_notification_statistics_for_service(service_id,
@statsd(namespace="dao")
def dao_get_template_usage(service_id, limit_days=None):
table = NotificationHistory
if limit_days and limit_days <= 7: # can get this data from notifications table
@@ -155,28 +154,19 @@ def dao_get_template_usage(service_id, limit_days=None):
query_filter.append(table.created_at >= days_ago(limit_days))
return query.filter(*query_filter) \
.join(Template)\
.group_by(table.template_id, Template.name, Template.template_type)\
.order_by(asc(Template.name))\
.join(Template) \
.group_by(table.template_id, Template.name, Template.template_type) \
.order_by(asc(Template.name)) \
.all()
@statsd(namespace="dao")
def dao_get_template_statistics_for_service(service_id, limit_days=None):
query_filter = [TemplateStatistics.service_id == service_id]
if limit_days is not None:
query_filter.append(TemplateStatistics.day >= days_ago(limit_days))
return TemplateStatistics.query.filter(*query_filter).order_by(
desc(TemplateStatistics.updated_at)).all()
@statsd(namespace="dao")
def dao_get_template_statistics_for_template(template_id):
return TemplateStatistics.query.filter(
TemplateStatistics.template_id == template_id
).order_by(
desc(TemplateStatistics.updated_at)
).all()
def dao_get_last_template_usage(template_id):
return NotificationHistory.query.filter(
NotificationHistory.template_id == template_id
).join(Template) \
.order_by(desc(NotificationHistory.created_at)) \
.first()
@statsd(namespace="dao")