update report detail

This commit is contained in:
PhanThanhTrung 2024-03-20 17:03:40 +07:00
parent c1b0ad2d52
commit 64c691b49c
4 changed files with 42 additions and 28 deletions

View File

@ -8,6 +8,7 @@ class ReportFile(models.Model):
# Metadata # Metadata
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
correspond_request_id = models.CharField(max_length=200, default="") correspond_request_id = models.CharField(max_length=200, default="")
correspond_request_created_at = models.DateTimeField(default=timezone.now, db_index=True)
correspond_redemption_id = models.CharField(max_length=200, default="") correspond_redemption_id = models.CharField(max_length=200, default="")
subsidiary = models.CharField(default="", null=True, max_length=200) subsidiary = models.CharField(default="", null=True, max_length=200)
created_at = models.DateTimeField(default=timezone.now, db_index=True) created_at = models.DateTimeField(default=timezone.now, db_index=True)

View File

@ -539,6 +539,7 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True)
data.append({ data.append({
"Subs": report_file.subsidiary, "Subs": report_file.subsidiary,
"Request ID": report_file.correspond_request_id, "Request ID": report_file.correspond_request_id,
"OCR Extraction Date": format_datetime_for_report_detail(report_file.correspond_request_created_at),
"Redemption Number": report_file.correspond_redemption_id, "Redemption Number": report_file.correspond_redemption_id,
"Image type": report_file.doc_type, "Image type": report_file.doc_type,
"IMEI_user submitted": first_of_list(report_file.feedback_result.get("imei_number", [None])) if report_file.feedback_result else None, "IMEI_user submitted": first_of_list(report_file.feedback_result.get("imei_number", [None])) if report_file.feedback_result else None,
@ -550,7 +551,7 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True)
"Invoice_Number Revised": report_file.reviewed_result.get("invoice_no", None) if report_file.reviewed_result else None, "Invoice_Number Revised": report_file.reviewed_result.get("invoice_no", None) if report_file.reviewed_result else None,
"Invoice_Number_Accuracy": first_of_list(report_file.feedback_accuracy.get("invoice_no", [None])), "Invoice_Number_Accuracy": first_of_list(report_file.feedback_accuracy.get("invoice_no", [None])),
"Invoice_Purchase Date_Consumer": report_file.feedback_result.get("purchase_date", None) if report_file.feedback_result else None, "Invoice_Purchase Date_Consumer": report_file.feedback_result.get("purchase_date", None) if report_file.feedback_result else None,
"Invoice_Purchase Date_OCR": report_file.predict_result.get("purchase_date", []), "Invoice_Purchase Date_OCR": format_purchase_date_ocr_for_report(report_file.predict_result.get("purchase_date", [])),
"Invoice_Purchase Date Revised": report_file.reviewed_result.get("purchase_date", None) if report_file.reviewed_result else None, "Invoice_Purchase Date Revised": report_file.reviewed_result.get("purchase_date", None) if report_file.reviewed_result else None,
"Invoice_Purchase Date Accuracy": first_of_list(report_file.feedback_accuracy.get("purchase_date", [None])), "Invoice_Purchase Date Accuracy": first_of_list(report_file.feedback_accuracy.get("purchase_date", [None])),
"Invoice_Retailer_Consumer": report_file.feedback_result.get("retailername", None) if report_file.feedback_result else None, "Invoice_Retailer_Consumer": report_file.feedback_result.get("retailername", None) if report_file.feedback_result else None,
@ -580,6 +581,16 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True)
data[i][key] = data[i][key]*100 data[i][key] = data[i][key]*100
return data return data
def format_datetime_for_report_detail(ocr_extraction_date):
naived_time = timezone.make_naive(ocr_extraction_date)
ocr_extraction_date = timezone.make_aware(value=naived_time, timezone=timezone.get_current_timezone())
format_to_date = '%Y/%m/%d'
ocr_extraction_date = ocr_extraction_date.strftime(format_to_date)
return ocr_extraction_date
def format_purchase_date_ocr_for_report(ocr_result):
return ", ".join(ocr_result)
def count_transactions(start_date, end_date, subsidiary="all"): def count_transactions(start_date, end_date, subsidiary="all"):
base_query = Q(created_at__range=(start_date, end_date)) base_query = Q(created_at__range=(start_date, end_date))
base_query &= Q(is_test_request=False) base_query &= Q(is_test_request=False)
@ -837,6 +848,7 @@ def calculate_a_request(report, request):
new_report_file = ReportFile(report=report, new_report_file = ReportFile(report=report,
subsidiary=_sub, subsidiary=_sub,
correspond_request_id=request.request_id, correspond_request_id=request.request_id,
correspond_request_created_at=request.created_at,
correspond_redemption_id=request.redemption_id, correspond_redemption_id=request.redemption_id,
doc_type=image.doc_type, doc_type=image.doc_type,
predict_result=image.predict_result, predict_result=image.predict_result,

View File

@ -506,33 +506,34 @@ def dict2xlsx(input: json, _type='report'):
mapping = { mapping = {
'A': 'subs', 'A': 'subs',
'B': 'request_id', 'B': 'request_id',
'C': 'redemption_number', 'C': "ocr_extraction_date",
'D': 'image_type', 'D': 'redemption_number',
'E': 'imei_user_submitted', 'E': 'image_type',
'F': "imei_ocr_retrieved", 'F': 'imei_user_submitted',
'G': "imei_revised", 'G': "imei_ocr_retrieved",
'H': "imei1_accuracy", 'H': "imei_revised",
'I': "invoice_number_user", 'I': "imei1_accuracy",
'J': "invoice_number_ocr", 'J': "invoice_number_user",
'K': "invoice_number_revised", 'K': "invoice_number_ocr",
'L': "invoice_number_accuracy", 'L': "invoice_number_revised",
'M': "invoice_purchase_date_consumer", 'M': "invoice_number_accuracy",
'N': "invoice_purchase_date_ocr", 'N': "invoice_purchase_date_consumer",
'O': "invoice_purchase_date_revised", 'O': "invoice_purchase_date_ocr",
'P': "invoice_purchase_date_accuracy", 'P': "invoice_purchase_date_revised",
'Q': "invoice_retailer_consumer", 'Q': "invoice_purchase_date_accuracy",
'R': "invoice_retailer_ocr", 'R': "invoice_retailer_consumer",
'S': 'invoice_retailer_revised', 'S': "invoice_retailer_ocr",
'T': "invoice_retailer_accuracy", 'T': 'invoice_retailer_revised',
'U': "ocr_image_accuracy", 'U': "invoice_retailer_accuracy",
'V': "ocr_image_speed_(seconds)", 'V': "ocr_image_accuracy",
'W': "is_reviewed", 'W': "ocr_image_speed_(seconds)",
'X': "bad_image_reasons", 'X': "is_reviewed",
'Y': "countermeasures", 'Y': "bad_image_reasons",
'Z': "imei_revised_accuracy", 'Z': "countermeasures",
'AA': "invoice_number_revised_accuracy", 'AA':"imei_revised_accuracy",
'AB': 'purchase_date_revised_accuracy', 'AB': "invoice_number_revised_accuracy",
'AC': 'retailer_revised_accuracy', 'AC': 'purchase_date_revised_accuracy',
'AD':'retailer_revised_accuracy',
} }
start_index = 4 start_index = 4

Binary file not shown.