From b03046b429b0528ef8412874f6c12bdacf19886d Mon Sep 17 00:00:00 2001 From: AaronStephenson Date: Mon, 13 May 2019 16:43:49 -0500 Subject: [PATCH] Include replicate_count and positive_count fields in summary statistics report when percent_positive field is requested without one or both of them --- lideservices/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lideservices/views.py b/lideservices/views.py index e04ce83..d3abf76 100644 --- a/lideservices/views.py +++ b/lideservices/views.py @@ -843,12 +843,12 @@ def summary_statistics(self, request): totals = {'target_name': 'All targets', 'target_id': None} # calculate the requested statistics per object - if 'replicate_count' in statistic_list: - # queryset = queryset.annotate(replicate_count=Count(Subquery(all_reps.values('id')))) + if ('replicate_count' in statistic_list + or ('percent_positive' in statistic_list and 'replicate_count' not in statistic_list)): queryset = queryset.annotate(replicate_count=Count('id')) totals['replicate_count'] = queryset.aggregate(Sum('replicate_count'))['replicate_count__sum'] - if 'positive_count' in statistic_list: - # queryset = queryset.annotate(positive_count=Count(Subquery(pos_reps.values('id')))) + if ('positive_count' in statistic_list + or ('percent_positive' in statistic_list and 'positive_count' not in statistic_list)): queryset = queryset.annotate(positive_count=Count('id', filter=Q(replicate_concentration__gt=0))) totals['positive_count'] = queryset.aggregate(Sum('positive_count'))['positive_count__sum'] if 'percent_positive' in statistic_list: