mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Adjust attribute key names and data types to work with format_statistics
This commit is contained in:
@@ -4,7 +4,7 @@ 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 sqlalchemy.types import DateTime, Integer
|
||||
|
||||
from app import db
|
||||
from app.models import Notification, NotificationHistory, FactNotificationStatus, KEY_TYPE_TEST
|
||||
@@ -113,12 +113,12 @@ def fetch_notification_status_for_service_for_day(bst_day, service_id):
|
||||
).all()
|
||||
|
||||
|
||||
def fetch_notification_status_for_service_for_today_and_7_previous_days(service_id):
|
||||
start_date = midnight_n_days_ago(7)
|
||||
def fetch_notification_status_for_service_for_today_and_7_previous_days(service_id, limit_days=7):
|
||||
start_date = midnight_n_days_ago(limit_days)
|
||||
now = datetime.utcnow()
|
||||
stats_for_7_days = db.session.query(
|
||||
FactNotificationStatus.notification_type.label('notification_type'),
|
||||
FactNotificationStatus.notification_status.label('notification_status'),
|
||||
FactNotificationStatus.notification_status.label('status'),
|
||||
FactNotificationStatus.notification_count.label('count')
|
||||
).filter(
|
||||
FactNotificationStatus.service_id == service_id,
|
||||
@@ -128,7 +128,7 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days(service_
|
||||
|
||||
stats_for_today = db.session.query(
|
||||
Notification.notification_type.cast(db.Text),
|
||||
Notification.status.label('notification_status'),
|
||||
Notification.status,
|
||||
func.count().label('count')
|
||||
).filter(
|
||||
Notification.created_at >= get_london_midnight_in_utc(now),
|
||||
@@ -141,9 +141,9 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days(service_
|
||||
all_stats_table = stats_for_7_days.union_all(stats_for_today).subquery()
|
||||
return db.session.query(
|
||||
all_stats_table.c.notification_type,
|
||||
all_stats_table.c.notification_status,
|
||||
func.sum(all_stats_table.c.count).label('count')
|
||||
all_stats_table.c.status,
|
||||
func.cast(func.sum(all_stats_table.c.count), Integer).label('count'),
|
||||
).group_by(
|
||||
all_stats_table.c.notification_type,
|
||||
all_stats_table.c.notification_status,
|
||||
all_stats_table.c.status,
|
||||
).all()
|
||||
|
||||
Reference in New Issue
Block a user