mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 14:08:47 -04:00
[WIP]
This commit is contained in:
@@ -413,8 +413,7 @@ def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_fro
|
||||
|
||||
if start_date >= datetime.utcnow() - timedelta(days=7):
|
||||
table = Notification
|
||||
|
||||
query = db.session.query(
|
||||
subquery = db.session.query(
|
||||
table.notification_type,
|
||||
table.status,
|
||||
table.service_id,
|
||||
@@ -426,12 +425,23 @@ def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_fro
|
||||
table.notification_type,
|
||||
table.status,
|
||||
table.service_id
|
||||
).order_by(
|
||||
table.service_id
|
||||
)
|
||||
|
||||
if not include_from_test_key:
|
||||
query = query.filter(table.key_type != KEY_TYPE_TEST)
|
||||
subquery = subquery.filter(table.key_type != KEY_TYPE_TEST)
|
||||
subquery = subquery.subquery()
|
||||
|
||||
query = db.session.query(
|
||||
Service.id.label('service_id'),
|
||||
Service.name,
|
||||
Service.restricted,
|
||||
Service.research_mode,
|
||||
subquery.c.notification_type,
|
||||
subquery.c.status,
|
||||
subquery.c.count
|
||||
).join(
|
||||
subquery,
|
||||
subquery.c.service_id == Service.id
|
||||
).order_by(Service.id)
|
||||
|
||||
return query.all()
|
||||
|
||||
|
||||
@@ -409,7 +409,7 @@ def get_detailed_service(service_id, today_only=False):
|
||||
|
||||
|
||||
def get_detailed_services(start_date, end_date, only_active=False, include_from_test_key=True):
|
||||
services = {service.id: service for service in dao_fetch_all_services(only_active)}
|
||||
services_old = {service.id: service for service in dao_fetch_all_services(only_active)}
|
||||
if start_date == datetime.utcnow().date():
|
||||
stats = dao_fetch_todays_stats_for_all_services(include_from_test_key=include_from_test_key)
|
||||
else:
|
||||
@@ -417,15 +417,18 @@ def get_detailed_services(start_date, end_date, only_active=False, include_from_
|
||||
stats = fetch_stats_by_date_range_for_all_services(start_date=start_date,
|
||||
end_date=end_date,
|
||||
include_from_test_key=include_from_test_key)
|
||||
|
||||
services = {service.service_id: service for service in stats}
|
||||
for service_id, rows in itertools.groupby(stats, lambda x: x.service_id):
|
||||
services[service_id].statistics = statistics.format_statistics(rows)
|
||||
|
||||
# for service_id, rows in itertools.groupby(stats, lambda x: x.service_id):
|
||||
# services[service_id].statistics = statistics.format_statistics(rows)
|
||||
|
||||
# if service has not sent anything, query will not have set statistics correctly
|
||||
for service in services.values():
|
||||
if not hasattr(service, 'statistics'):
|
||||
service.statistics = statistics.create_zeroed_stats_dicts()
|
||||
return detailed_service_schema.dump(services.values(), many=True).data
|
||||
return services
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/whitelist', methods=['GET'])
|
||||
|
||||
Reference in New Issue
Block a user