mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
fix tuples
This commit is contained in:
@@ -515,6 +515,36 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
||||
start_date = get_midnight_in_utc(start_date)
|
||||
end_date = get_midnight_in_utc(end_date + timedelta(days=1))
|
||||
|
||||
total_substmt = (
|
||||
select(
|
||||
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
||||
Job.notification_count.label("notification_count"),
|
||||
)
|
||||
.join(Job, NotificationAllTimeView.job_id == Job.id)
|
||||
.where(
|
||||
NotificationAllTimeView.service_id == service_id,
|
||||
NotificationAllTimeView.key_type != KeyType.TEST,
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
NotificationAllTimeView.created_at < end_date,
|
||||
NotificationAllTimeView.created_by_id == user_id,
|
||||
)
|
||||
.group_by(
|
||||
Job.id,
|
||||
Job.notification_count,
|
||||
func.date_trunc("day", NotificationAllTimeView.created_at),
|
||||
)
|
||||
.subquery()
|
||||
)
|
||||
|
||||
total_stmt = select(
|
||||
total_substmt.c.day,
|
||||
func.sum(total_substmt.c.notification_count).label("total_notifications"),
|
||||
).group_by(total_substmt.c.day)
|
||||
|
||||
total_notifications = {
|
||||
row.day: row.total_notifications for row in db.session.execute(total_stmt).all()
|
||||
}
|
||||
|
||||
stmt = (
|
||||
select(
|
||||
NotificationAllTimeView.notification_type,
|
||||
@@ -522,8 +552,7 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
||||
func.date_trunc("day", NotificationAllTimeView.created_at).label("day"),
|
||||
func.count(NotificationAllTimeView.id).label("count"),
|
||||
)
|
||||
.select_from(NotificationAllTimeView)
|
||||
.filter(
|
||||
.where(
|
||||
NotificationAllTimeView.service_id == service_id,
|
||||
NotificationAllTimeView.key_type != KeyType.TEST,
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
@@ -536,7 +565,10 @@ def dao_fetch_stats_for_service_from_days_for_user(
|
||||
func.date_trunc("day", NotificationAllTimeView.created_at),
|
||||
)
|
||||
)
|
||||
return db.session.execute(stmt).scalars().all()
|
||||
|
||||
data = db.session.execute(stmt).all()
|
||||
|
||||
return total_notifications, data
|
||||
|
||||
|
||||
def dao_fetch_todays_stats_for_all_services(
|
||||
|
||||
@@ -268,12 +268,16 @@ def get_service_statistics_for_specific_days_by_user(
|
||||
end_date = datetime.strptime(start, "%Y-%m-%d")
|
||||
start_date = end_date - timedelta(days=days - 1)
|
||||
|
||||
results = dao_fetch_stats_for_service_from_days_for_user(
|
||||
total_notifications, results = dao_fetch_stats_for_service_from_days_for_user(
|
||||
service_id, start_date, end_date, user_id
|
||||
)
|
||||
|
||||
stats = get_specific_days_stats(results, start_date, days=days)
|
||||
|
||||
stats = get_specific_days_stats(
|
||||
results,
|
||||
start_date,
|
||||
days=days,
|
||||
total_notifications=total_notifications,
|
||||
)
|
||||
return stats
|
||||
|
||||
|
||||
@@ -663,11 +667,11 @@ def get_single_month_notification_stats_by_user(service_id, user_id):
|
||||
month_year = datetime(year, month, 10, 00, 00, 00)
|
||||
start_date, end_date = get_month_start_and_end_date_in_utc(month_year)
|
||||
|
||||
results = dao_fetch_stats_for_service_from_days_for_user(
|
||||
total_notifications, results = dao_fetch_stats_for_service_from_days_for_user(
|
||||
service_id, start_date, end_date, user_id
|
||||
)
|
||||
|
||||
stats = get_specific_days_stats(results, start_date, end_date=end_date)
|
||||
stats = get_specific_days_stats(results, start_date, end_date=end_date, total_notifications=total_notifications,)
|
||||
return jsonify(stats)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user