diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index abeb682..96177de 100644 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -10,7 +10,7 @@ from django.db.models import Q from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes # from drf_spectacular.types import OpenApiString from ..models import SubscriptionRequest -from ..exception.exceptions import RequiredFieldException +from ..exception.exceptions import RequiredFieldException, NotFoundException import json @@ -184,7 +184,7 @@ class AccuracyViewSet(viewsets.ViewSet): return JsonResponse(response) return JsonResponse({'error': 'Invalid request method.'}, status=405) - + class RequestViewSet(viewsets.ViewSet): lookup_field = "username" @@ -205,7 +205,12 @@ class RequestViewSet(viewsets.ViewSet): if request.method == 'GET': base_query = Q(request_id=request_id) - subscription_request = SubscriptionRequest.objects.filter(base_query).first() + subscription_request = SubscriptionRequest.objects.filter(base_query) + + if subscription_request.count() == 0: + raise NotFoundException(excArgs=request_id) + + subscription_request = subscription_request.first() data = [] @@ -230,16 +235,26 @@ class RequestViewSet(viewsets.ViewSet): print(f"[ERROR]: {e}") print(f"[ERROR]: {subscription_request}") data.append({ + 'Document Type': subscription_request.doc_type, 'RequestID': subscription_request.request_id, 'RedemptionID': subscription_request.redemption_id, + 'Process Type': subscription_request.process_type, + 'Provider Code': subscription_request.provider_code, + 'Status': subscription_request.status, 'IMEIs': imeis, 'Purchase Date': purchase_date, 'Retailer': retailer, 'Reviewed result': subscription_request.reviewed_result, 'Feedback result': subscription_request.feedback_result, + 'Is Test Request': subscription_request.is_test_request, + 'IMEI Accuracy': subscription_request.imei_accuracy, + 'Purchase Date Accuracy': subscription_request.purchase_date_accuracy, + 'Retailer Name Accuracy': subscription_request.retailer_name_accuracy, + 'Sold To Party Accuracy': subscription_request.sold_to_party_accuracy, 'Client Request Time (ms)': subscription_request.client_request_time, 'Server Processing Time (ms)': subscription_request.preprocessing_time + subscription_request.ai_inference_time, 'Is Reviewed': subscription_request.is_reviewed, + # 'Is Bad Quality': subscription_request.is_bad_image_quality, 'created_at': subscription_request.created_at.isoformat(), 'updated_at': subscription_request.updated_at.isoformat() @@ -256,7 +271,12 @@ class RequestViewSet(viewsets.ViewSet): base_query = Q(request_id=request_id) - subscription_request = SubscriptionRequest.objects.filter(base_query).first() + subscription_request = SubscriptionRequest.objects.filter(base_query) + + if subscription_request.count() == 0: + raise NotFoundException(excArgs=request_id) + + subscription_request = subscription_request.first() reviewed_result = json.loads(data["reviewed_result"][1:-1]) for field in ['retailername', 'sold_to_party', 'purchase_date', 'imei_number']: diff --git a/cope2n-api/fwd_api/utils/file.py b/cope2n-api/fwd_api/utils/file.py index bd0b4c8..9a2a429 100644 --- a/cope2n-api/fwd_api/utils/file.py +++ b/cope2n-api/fwd_api/utils/file.py @@ -428,7 +428,7 @@ def dict2xlsx(input: json, _type='report'): elif key_index >= 4 and key_index <= 8: ws[key + str(start_index)].fill = fill_yellow elif _type == 'report_detail': - if 'accuracy' in mapping[key] and type(value) in [int, float] and value < 95: + if 'accuracy' in mapping[key] and type(value) in [int, float] and value < 75: ws[key + str(start_index)].style = normal_cell_red elif 'speed' in mapping[key] and type(value) in [int, float] and value > 2.0: ws[key + str(start_index)].style = normal_cell_red