Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Change Results Summary Report to be on a Sample basis, not PCR Replic…
Browse files Browse the repository at this point in the history
…ate basis, and fix totals/all targets row per cooperator instructions
  • Loading branch information
aaronstephenson committed Jun 11, 2019
1 parent a13dcbd commit 4a04284
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 101 deletions.
2 changes: 1 addition & 1 deletion code.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "lide",
"organization": "U.S. Geological Survey",
"description": "Web services for LILI (LIDE (Laboratory for Infectious Disease and the Environment) Information Management System)",
"version": "v0.100.0",
"version": "v0.101.0",
"status": "Release Candidate",

"permissions": {
Expand Down
104 changes: 4 additions & 100 deletions lideservices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,17 @@ def summary_statistics(self, request):
if ('sample_count' in statistic_list
or ('percent_positive' in statistic_list and 'sample_count' not in statistic_list)):
queryset = queryset.annotate(sample_count=Count('id'))
totals['sample_count'] = queryset.aggregate(Sum('sample_count'))['sample_count__sum']
totals['sample_count'] = totals_queryset.aggregate(Count('sample_id', distinct=True))['sample_id__count']
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(final_sample_mean_concentration__gt=0)))
totals['positive_count'] = queryset.aggregate(Sum('positive_count'))['positive_count__sum']
totals['positive_count'] = queryset.aggregate(Count('positive_count'))['positive_count__count']
if 'percent_positive' in statistic_list:
queryset = queryset.annotate(
percent_positive=(Cast('positive_count', FloatField()) / Cast('sample_count', FloatField()) * 100))
totals['percent_positive'] = (queryset.aggregate(
Sum('positive_count'))['positive_count__sum'] / queryset.aggregate(
Sum('sample_count'))['sample_count__sum']) * 100
Count('positive_count'))['positive_count__count'] / totals_queryset.aggregate(
Count('sample_id', distinct=True))['sample_id__count']) * 100
if 'max_concentration' in statistic_list:
queryset = queryset.annotate(max_concentration=Max('final_sample_mean_concentration'))
totals['max_concentration'] = totals_queryset.aggregate(
Expand Down Expand Up @@ -912,102 +912,6 @@ def destroy(self, request, *args, **kwargs):
class PCRReplicateViewSet(HistoryViewSet):
serializer_class = PCRReplicateSerializer

# @action(detail=False)
# def summary_statistics(self, request):
#
# STATISTICS = ['replicate_count', 'positive_count', 'percent_positive', 'max_concentration', 'min_concentration',
# 'median_concentration', 'average_concentration', 'min_concentration_positive',
# 'median_concentration_positive', 'average_concentration_positive']
#
# queryset = PCRReplicate.objects.all()
# query_params = request.query_params
# # filter by sample IDs, exact list
# sample = query_params.get('sample', None)
# if sample is not None:
# if LIST_DELIMETER in sample:
# sample_list = sample.split(LIST_DELIMETER)
# queryset = queryset.filter(sample_extraction__sample__id__in=sample_list)
# else:
# queryset = queryset.filter(sample_extraction__sample__id__exact=sample)
# # filter by target IDs, exact list
# target = query_params.get('target', None)
# if target is not None:
# if LIST_DELIMETER in target:
# target_list = target.split(LIST_DELIMETER)
# queryset = queryset.filter(pcrreplicate_batch__target__id__in=target_list)
# else:
# queryset = queryset.filter(pcrreplicate_batch__target__id__exact=target)
# # get the requested statistics, exact list
# statistic = query_params.get('statistic', None)
# statistic_list = statistic.split(LIST_DELIMETER) if statistic is not None else STATISTICS
#
# # set aside a parallel query for totals
# totals_queryset = queryset
#
# # group by target name
# queryset = queryset.values(target_name=F('pcrreplicate_batch__target__name')).order_by('target_name')
#
# # include the target id
# queryset = queryset.annotate(target_id=F('pcrreplicate_batch__target__id'))
#
# # initialize the totals row and include the totals target id field to match the main queryset for later merging
# totals = {'target_name': 'All targets', 'target_id': None}
#
# # calculate the requested statistics per object
# 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
# 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:
# queryset = queryset.annotate(
# percent_positive=Cast('positive_count', FloatField()) / Cast('replicate_count', FloatField()))
# totals['percent_positive'] = queryset.aggregate(
# Sum('positive_count'))['positive_count__sum'] / queryset.aggregate(
# Sum('replicate_count'))['replicate_count__sum']
# if 'max_concentration' in statistic_list:
# queryset = queryset.annotate(max_concentration=Max('replicate_concentration'))
# totals['max_concentration'] = totals_queryset.aggregate(
# Max('replicate_concentration'))['replicate_concentration__max']
# if 'min_concentration' in statistic_list:
# queryset = queryset.annotate(min_concentration=Min('replicate_concentration'))
# totals['min_concentration'] = totals_queryset.aggregate(
# Min('replicate_concentration'))['replicate_concentration__min']
# if 'median_concentration' in statistic_list:
# queryset = queryset.annotate(median_concentration=Median('replicate_concentration'))
# totals['median_concentration'] = totals_queryset.aggregate(
# Median('replicate_concentration'))['replicate_concentration__median']
# if 'average_concentration' in statistic_list:
# queryset = queryset.annotate(average_concentration=Avg('replicate_concentration'))
# totals['average_concentration'] = totals_queryset.aggregate(
# Avg('replicate_concentration'))['replicate_concentration__avg']
# if 'min_concentration_positive' in statistic_list:
# queryset = queryset.annotate(
# min_concentration_positive=Min('replicate_concentration', filter=Q(replicate_concentration__gt=0)))
# totals['min_concentration_positive'] = totals_queryset.aggregate(
# replicate_concentration__min=Min('replicate_concentration', filter=Q(
# replicate_concentration__gt=0)))['replicate_concentration__min']
# if 'median_concentration_positive' in statistic_list:
# queryset = queryset.annotate(median_concentration_positive=Median(
# 'replicate_concentration', filter=Q(replicate_concentration__gt=0)))
# totals['median_concentration_positive'] = totals_queryset.aggregate(
# replicate_concentration__median=Median('replicate_concentration', filter=Q(
# replicate_concentration__gt=0)))['replicate_concentration__median']
# if 'average_concentration_positive' in statistic_list:
# queryset = queryset.annotate(
# average_concentration_positive=Avg('replicate_concentration', filter=Q(replicate_concentration__gt=0)))
# totals['average_concentration_positive'] = totals_queryset.aggregate(
# replicate_concentration__avg=Avg('replicate_concentration', filter=Q(
# replicate_concentration__gt=0)))['replicate_concentration__avg']
#
# resp = list(queryset)
# resp.append(totals)
#
# return Response(resp)

def get_serializer(self, *args, **kwargs):
if 'data' in kwargs:
data = kwargs['data']
Expand Down

0 comments on commit 4a04284

Please sign in to comment.