From a282e9c5052a2ecdf0bce576db60dfaf5fd80a7a Mon Sep 17 00:00:00 2001 From: TannedCung Date: Thu, 28 Nov 2024 16:44:39 +0700 Subject: [PATCH] Add: filter to search --- cope2n-api/fwd_api/api/accuracy_view.py | 42 ++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index e4295f0..ec48e65 100755 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -112,6 +112,34 @@ class AccuracyViewSet(viewsets.ViewSet): type=OpenApiTypes.FLOAT, required=False ), + OpenApiParameter( + name='predict_result', + location=OpenApiParameter.QUERY, + description='Filter by predict result', + type=OpenApiTypes.STR, + required=False + ), + OpenApiParameter( + name='feedback_result', + location=OpenApiParameter.QUERY, + description='Filter by feedback result', + type=OpenApiTypes.STR, + required=False + ), + OpenApiParameter( + name='reviewed_result', + location=OpenApiParameter.QUERY, + description='Filter by reviewed result', + type=OpenApiTypes.STR, + required=False + ), + OpenApiParameter( + name='doc_type', + location=OpenApiParameter.QUERY, + description='Filter by document type', + type=OpenApiTypes.STR, + required=False + ), ], responses=None, tags=['Accuracy'] ) @@ -129,7 +157,10 @@ class AccuracyViewSet(viewsets.ViewSet): include_test = request.GET.get('includes_test', False) subsidiary = request.GET.get("subsidiary", "all") max_accuracy = float(request.GET.get("max_accuracy", 100)) - # subsidiary = map_subsidiary_long_to_short(subsidiary) + predict_result = request.GET.get('predict_result', None) + feedback_result = request.GET.get('feedback_result', None) + reviewed_result = request.GET.get('reviewed_result', None) + doc_type = request.GET.get('doc_type', None) base_query = Q(status=200) if start_date_str or end_date_str: @@ -193,6 +224,15 @@ class AccuracyViewSet(viewsets.ViewSet): base_query &= Q( redemption_id__startswith=map_subsidiary_long_to_short(subsidiary)) + if predict_result: + base_query &= Q(predict_result__icontains=predict_result) + if feedback_result: + base_query &= Q(feedback_result__icontains=feedback_result) + if reviewed_result: + base_query &= Q(reviewed_result__icontains=reviewed_result) + if doc_type: + base_query &= Q(doc_type__icontains=doc_type) + if isinstance(max_accuracy, float): base_query &= Q(raw_accuracy__lt=( max_accuracy/100)) | Q(raw_accuracy__isnull=True)