remove old monthly stats function

This commit is contained in:
Leo Hemsted
2018-06-28 15:20:48 +01:00
parent 2463cd8fb5
commit 75fdb0290f
3 changed files with 5 additions and 107 deletions

View File

@@ -3,6 +3,8 @@ from datetime import datetime, timedelta, time
from flask import current_app
from sqlalchemy import func
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.sql.expression import literal
from sqlalchemy.types import DateTime
from app import db
from app.models import Notification, NotificationHistory, FactNotificationStatus
@@ -95,19 +97,15 @@ def fetch_notification_status_for_service_by_month(start_date, end_date, service
def fetch_notification_status_for_service_for_day(bst_day, service_id):
return db.session.query(
# return current month as a datetime so the data has the same shape as the ft_notification_status query
get_london_month_from_utc_column(func.current_date()),
literal(bst_day.replace(day=1), type_=DateTime).label('month'),
Notification.notification_type,
Notification.status,
func.count()
Notification.status.label('notification_status'),
func.count().label('count')
).filter(
Notification.created_at >= get_london_midnight_in_utc(bst_day),
Notification.created_at < get_london_midnight_in_utc(bst_day + timedelta(days=1)),
Notification.service_id == service_id
).group_by(
Notification.template_id,
Notification.service_id,
'job_id',
Notification.notification_type,
Notification.key_type,
Notification.status
).all()

View File

@@ -291,48 +291,6 @@ def _stats_for_service_query(service_id):
)
@statsd(namespace="dao")
def dao_fetch_monthly_historical_stats_for_service(service_id, year):
month = get_london_month_from_utc_column(NotificationHistory.created_at)
start_date, end_date = get_financial_year(year)
rows = db.session.query(
NotificationHistory.notification_type,
NotificationHistory.status,
month,
func.count(NotificationHistory.id).label('count')
).filter(
NotificationHistory.service_id == service_id,
NotificationHistory.created_at.between(start_date, end_date)
).group_by(
NotificationHistory.notification_type,
NotificationHistory.status,
month
).order_by(
month
)
months = {
datetime.strftime(created_date, '%Y-%m'): {
template_type: dict.fromkeys(
NOTIFICATION_STATUS_TYPES,
0
)
for template_type in TEMPLATE_TYPES
}
for created_date in [
datetime(year, month, 1) for month in range(4, 13)
] + [
datetime(year + 1, month, 1) for month in range(1, 4)
]
}
for notification_type, status, created_date, count in rows:
months[datetime.strftime(created_date, "%Y-%m")][notification_type][status] = count
return months
@statsd(namespace='dao')
def dao_fetch_todays_stats_for_all_services(include_from_test_key=True, only_active=True):
today = date.today()