UPDATE: update request detail api

This commit is contained in:
daovietanh99 2024-02-22 08:36:57 +07:00
parent 532905ca78
commit 2f7505c797

View File

@ -20,6 +20,8 @@ from ..utils.redis import RedisUtils
from ..utils.process import string_to_boolean
from ..request.ReportCreationSerializer import ReportCreationSerializer
from ..utils.subsidiary import map_subsidiary_long_to_short, map_subsidiary_short_to_long
from fwd_api.utils.accuracy import predict_result_to_ready
import copy
redis_client = RedisUtils()
@ -574,6 +576,14 @@ class RequestViewSet(viewsets.ViewSet):
subscription_request = subscription_request.first()
sample_result = {
"request_id": subscription_request.request_id,
"retailername": None,
"sold_to_party": None,
"purchase_date": None,
"imei_number": []
}
data = []
files = []
@ -584,6 +594,17 @@ class RequestViewSet(viewsets.ViewSet):
user_id = sub.user.id
sync_id = sub.user.sync_id
sub_id = sub.id
reviewed_result = subscription_request_file.reviewed_result
feedback_result = subscription_request_file.feedback_result
predicted_result = subscription_request_file.predict_result
if not reviewed_result:
reviewed_result = copy.deepcopy(sample_result)
if not feedback_result:
feedback_result = copy.deepcopy(sample_result)
if not predicted_result:
predicted_result = copy.deepcopy(sample_result)
files.append({
'File Name': subscription_request_file.file_name,
'File Path': subscription_request_file.file_path,
@ -595,15 +616,26 @@ class RequestViewSet(viewsets.ViewSet):
'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,
'Predicted Result': predicted_result,
'Feedback Result': feedback_result,
'Reviewed Result': 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()
})
reviewed_result = subscription_request.reviewed_result
feedback_result = subscription_request.feedback_result
predicted_result = predict_result_to_ready(subscription_request.predict_result)
if not reviewed_result:
reviewed_result = copy.deepcopy(sample_result)
if not feedback_result:
feedback_result = copy.deepcopy(sample_result)
if not predicted_result:
predicted_result = copy.deepcopy(sample_result)
data.append({
'Document Type': subscription_request.doc_type,
'RequestID': subscription_request.request_id,
@ -612,9 +644,9 @@ class RequestViewSet(viewsets.ViewSet):
'Provider Code': subscription_request.provider_code,
'Status': subscription_request.status,
'Files': files,
'Reviewed Result': subscription_request.reviewed_result,
'Feedback Result': subscription_request.feedback_result,
'Predicted Result': subscription_request.predict_result,
'Reviewed Result': reviewed_result,
'Feedback Result': feedback_result,
'Predicted Result': predicted_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,