rcpch / rcpch-audit-engine

Epilepsy12 Audit Platform
https://e12.rcpch.ac.uk/
GNU Affero General Public License v3.0
5 stars 5 forks source link

KPI download fails in freshly seeded dev environment #900

Closed mbarton closed 4 months ago

mbarton commented 4 months ago

1) Wipe your local instance 2) Seed new cases in cohort 6 3) Download the KPI report

django-1   | ERROR [django.request] Internal Server Error: /kpi_download_file
django-1   | Traceback (most recent call last):
django-1   |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
django-1   |     response = get_response(request)
django-1   |                ^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
django-1   |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
django-1   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/epilepsy12/decorator.py", line 371, in wrapper
django-1   |     return view(request, *args, **kwargs)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/usr/local/lib/python3.11/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapper_view
django-1   |     return view_func(request, *args, **kwargs)
django-1   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/epilepsy12/views/organisation_views.py", line 450, in kpi_download_file
django-1   |     country_df, trust_hb_df, icb_df, region_df, network_df, national_df, reference_df = download_kpi_summary_as_csv(cohort=6)
django-1   |                                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   |   File "/app/epilepsy12/kpi.py", line 130, in download_kpi_summary_as_csv
django-1   |     "Percentage": national_kpi_aggregation[f"{kpi}_passed"]
django-1   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django-1   | ZeroDivisionError: division by zero
django-1   | ERROR [django.server] "GET /kpi_download_file HTTP/1.1" 500 118695
mbarton commented 4 months ago

I can see the national aggregations should have been created from the logs

django-1   | DEBUG [epilepsy12.common_view_functions.aggregate_by:401] updated National KPIAggregations for England and Wales (Cohort 6)

I can also view it in the Django admin.

It appears to be barfing on sodium_valproate and indeed the values are zero here:

'sodium_valproate_passed': 0, 'sodium_valproate_total_eligible': 0, 'sodium_valproate_ineligible': 92, 'sodium_valproate_incomplete': 0

The calculations within create_KPI_aggregation_dataframe have division by zero protection so I suspect the same needs to be applied at the national level here too