Merge pull request #43 from SDSRV-IDP/vietanh99-request-detail
UPDATE: add field to request detail api
This commit is contained in:
commit
031d29efd4
@ -15,7 +15,7 @@ import json
|
||||
from ..exception.exceptions import InvalidException, RequiredFieldException, NotFoundException
|
||||
from ..models import SubscriptionRequest, Report, ReportFile, SubscriptionRequestFile
|
||||
from ..utils.accuracy import shadow_report, MonthReportAccumulate, first_of_list, extract_report_detail_list, IterAvg
|
||||
from ..utils.file import download_from_S3, convert_date_string
|
||||
from ..utils.file import download_from_S3, convert_date_string, build_media_url_v2, build_url
|
||||
from ..utils.redis import RedisUtils
|
||||
from ..utils.process import string_to_boolean
|
||||
from ..request.ReportCreationSerializer import ReportCreationSerializer
|
||||
@ -148,6 +148,8 @@ class AccuracyViewSet(viewsets.ViewSet):
|
||||
|
||||
subscription_requests = SubscriptionRequest.objects.filter(base_query).order_by('created_at')
|
||||
|
||||
request_count = subscription_requests.count()
|
||||
|
||||
paginator = Paginator(subscription_requests, page_size)
|
||||
page = paginator.get_page(page_number)
|
||||
|
||||
@ -192,6 +194,7 @@ class AccuracyViewSet(viewsets.ViewSet):
|
||||
'number': page.number,
|
||||
'total_pages': page.paginator.num_pages,
|
||||
'count': page.paginator.count,
|
||||
'total_requests': request_count
|
||||
}
|
||||
}
|
||||
|
||||
@ -572,27 +575,35 @@ class RequestViewSet(viewsets.ViewSet):
|
||||
subscription_request = subscription_request.first()
|
||||
|
||||
data = []
|
||||
files = []
|
||||
|
||||
subscription_request_files = SubscriptionRequestFile.objects.filter(request=subscription_request.id)
|
||||
|
||||
for subscription_request_file in subscription_request_files:
|
||||
sub = subscription_request.subscription
|
||||
user_id = sub.user.id
|
||||
sync_id = sub.user.sync_id
|
||||
sub_id = sub.id
|
||||
files.append({
|
||||
'File Name': subscription_request_file.file_name,
|
||||
'File Path': subscription_request_file.file_path,
|
||||
'File Category': subscription_request_file.file_category,
|
||||
'File URL': build_media_url_v2(subscription_request_file.file_name.split['.'][0], user_id, sub_id, sync_id),
|
||||
'Origin_Name': subscription_request_file.origin_name,
|
||||
'Is Bad Image Quality': subscription_request_file.is_bad_image_quality,
|
||||
'Doc Type': subscription_request_file.doc_type,
|
||||
'Processing Time (ms)': subscription_request_file.processing_time,
|
||||
'Reason': subscription_request_file.reason,
|
||||
'Counter Measures': subscription_request_file.counter_measures,
|
||||
'Predicted Result': subscription_request_file.predict_result,
|
||||
'Feedback Result': subscription_request_file.feedback_result,
|
||||
'Reviewed Result': subscription_request_file.reviewed_result,
|
||||
'Feedback Accuracy': subscription_request_file.feedback_accuracy,
|
||||
'Reviewed Accuracy': subscription_request_file.reviewed_accuracy,
|
||||
'Created At': subscription_request_file.created_at.isoformat(),
|
||||
'Updated At': subscription_request_file.updated_at.isoformat()
|
||||
})
|
||||
|
||||
imeis = []
|
||||
purchase_date = []
|
||||
retailer = ""
|
||||
try:
|
||||
if subscription_request.reviewed_result is not None:
|
||||
imeis = subscription_request.reviewed_result.get("imei_number", [])
|
||||
purchase_date = subscription_request.reviewed_result.get("purchase_date", [])
|
||||
retailer = subscription_request.reviewed_result.get("retailername", "")
|
||||
elif subscription_request.feedback_result is not None :
|
||||
imeis = subscription_request.feedback_result.get("imei_number", [])
|
||||
purchase_date = subscription_request.feedback_result.get("purchase_date", [])
|
||||
retailer = subscription_request.feedback_result.get("retailername", "")
|
||||
elif subscription_request.predict_result is not None:
|
||||
if subscription_request.predict_result.get("status", 404) == 200:
|
||||
imeis = subscription_request.predict_result.get("content", {}).get("document", [])[0].get("content", [])[3].get("value", [])
|
||||
purchase_date = subscription_request.predict_result.get("content", {}).get("document", [])[0].get("content", [])[2].get("value", [])
|
||||
retailer = subscription_request.predict_result.get("content", {}).get("document", [])[0].get("content", [])[0].get("value", [])
|
||||
except Exception as e:
|
||||
print(f"[ERROR]: {e}")
|
||||
print(f"[ERROR]: {subscription_request}")
|
||||
data.append({
|
||||
'Document Type': subscription_request.doc_type,
|
||||
'RequestID': subscription_request.request_id,
|
||||
@ -600,19 +611,18 @@ class RequestViewSet(viewsets.ViewSet):
|
||||
'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,
|
||||
'Files': files,
|
||||
'Reviewed Result': subscription_request.reviewed_result,
|
||||
'Feedback Result': subscription_request.feedback_result,
|
||||
'Predicted Result': subscription_request.predict_result,
|
||||
'Is Test Request': subscription_request.is_test_request,
|
||||
'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()
|
||||
'Feedback Accuracy': subscription_request.feedback_accuracy,
|
||||
'Reviewed Accuracy': subscription_request.reviewed_accuracy,
|
||||
'Created At': subscription_request.created_at.isoformat(),
|
||||
'Updated At': subscription_request.updated_at.isoformat()
|
||||
})
|
||||
|
||||
response = {
|
||||
@ -633,9 +643,7 @@ class RequestViewSet(viewsets.ViewSet):
|
||||
|
||||
subscription_request = subscription_request.first()
|
||||
|
||||
file_query = Q(request=request_id)
|
||||
|
||||
subscription_request_files = SubscriptionRequestFile.objects.filter(file_query)
|
||||
subscription_request_files = SubscriptionRequestFile.objects.filter(request=subscription_request.id)
|
||||
|
||||
reviewed_result = json.loads(data["reviewed_result"])
|
||||
|
||||
|
@ -2,7 +2,7 @@ from django.conf import settings
|
||||
from rest_framework.routers import DefaultRouter, SimpleRouter
|
||||
|
||||
from fwd_api.api.ctel_view import CtelViewSet
|
||||
from fwd_api.api.accuracy_view import AccuracyViewSet, RequestViewSet
|
||||
from fwd_api.api.accuracy_view import AccuracyViewSet, RequestViewSet, RequestImageViewSet
|
||||
|
||||
from fwd_api.api.ctel_user_view import CtelUserViewSet
|
||||
|
||||
@ -17,6 +17,7 @@ router.register("ctel", CtelViewSet, basename="CtelAPI")
|
||||
router.register("ctel", CtelUserViewSet, basename="CtelUserAPI")
|
||||
router.register("ctel", AccuracyViewSet, basename="AccuracyAPI")
|
||||
router.register("ctel", RequestViewSet, basename="RequestAPI")
|
||||
router.register("ctel", RequestImageViewSet, basename="RequestImageAPI")
|
||||
|
||||
app_name = "api"
|
||||
urlpatterns = router.urls
|
||||
|
Loading…
Reference in New Issue
Block a user