From 64c691b49c10722a0f0381d9f3e10f2e5e6abefa Mon Sep 17 00:00:00 2001 From: PhanThanhTrung Date: Wed, 20 Mar 2024 17:03:40 +0700 Subject: [PATCH] update report detail --- cope2n-api/fwd_api/models/ReportFile.py | 1 + cope2n-api/fwd_api/utils/accuracy.py | 14 +++++- cope2n-api/fwd_api/utils/file.py | 55 ++++++++++++------------ cope2n-api/report_detail.xlsx | Bin 6742 -> 6772 bytes 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/cope2n-api/fwd_api/models/ReportFile.py b/cope2n-api/fwd_api/models/ReportFile.py index 2ba5247..ba6e13c 100644 --- a/cope2n-api/fwd_api/models/ReportFile.py +++ b/cope2n-api/fwd_api/models/ReportFile.py @@ -8,6 +8,7 @@ class ReportFile(models.Model): # Metadata id = models.AutoField(primary_key=True) 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="") subsidiary = models.CharField(default="", null=True, max_length=200) created_at = models.DateTimeField(default=timezone.now, db_index=True) diff --git a/cope2n-api/fwd_api/utils/accuracy.py b/cope2n-api/fwd_api/utils/accuracy.py index ef5cc93..d334b2a 100755 --- a/cope2n-api/fwd_api/utils/accuracy.py +++ b/cope2n-api/fwd_api/utils/accuracy.py @@ -539,6 +539,7 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True) data.append({ "Subs": report_file.subsidiary, "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, "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, @@ -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_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_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 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, @@ -580,6 +581,16 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True) data[i][key] = data[i][key]*100 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"): base_query = Q(created_at__range=(start_date, end_date)) base_query &= Q(is_test_request=False) @@ -837,6 +848,7 @@ def calculate_a_request(report, request): new_report_file = ReportFile(report=report, subsidiary=_sub, correspond_request_id=request.request_id, + correspond_request_created_at=request.created_at, correspond_redemption_id=request.redemption_id, doc_type=image.doc_type, predict_result=image.predict_result, diff --git a/cope2n-api/fwd_api/utils/file.py b/cope2n-api/fwd_api/utils/file.py index c0903cf..f8d8d08 100755 --- a/cope2n-api/fwd_api/utils/file.py +++ b/cope2n-api/fwd_api/utils/file.py @@ -506,33 +506,34 @@ def dict2xlsx(input: json, _type='report'): mapping = { 'A': 'subs', 'B': 'request_id', - 'C': 'redemption_number', - 'D': 'image_type', - 'E': 'imei_user_submitted', - 'F': "imei_ocr_retrieved", - 'G': "imei_revised", - 'H': "imei1_accuracy", - 'I': "invoice_number_user", - 'J': "invoice_number_ocr", - 'K': "invoice_number_revised", - 'L': "invoice_number_accuracy", - 'M': "invoice_purchase_date_consumer", - 'N': "invoice_purchase_date_ocr", - 'O': "invoice_purchase_date_revised", - 'P': "invoice_purchase_date_accuracy", - 'Q': "invoice_retailer_consumer", - 'R': "invoice_retailer_ocr", - 'S': 'invoice_retailer_revised', - 'T': "invoice_retailer_accuracy", - 'U': "ocr_image_accuracy", - 'V': "ocr_image_speed_(seconds)", - 'W': "is_reviewed", - 'X': "bad_image_reasons", - 'Y': "countermeasures", - 'Z': "imei_revised_accuracy", - 'AA': "invoice_number_revised_accuracy", - 'AB': 'purchase_date_revised_accuracy', - 'AC': 'retailer_revised_accuracy', + 'C': "ocr_extraction_date", + 'D': 'redemption_number', + 'E': 'image_type', + 'F': 'imei_user_submitted', + 'G': "imei_ocr_retrieved", + 'H': "imei_revised", + 'I': "imei1_accuracy", + 'J': "invoice_number_user", + 'K': "invoice_number_ocr", + 'L': "invoice_number_revised", + 'M': "invoice_number_accuracy", + 'N': "invoice_purchase_date_consumer", + 'O': "invoice_purchase_date_ocr", + 'P': "invoice_purchase_date_revised", + 'Q': "invoice_purchase_date_accuracy", + 'R': "invoice_retailer_consumer", + 'S': "invoice_retailer_ocr", + 'T': 'invoice_retailer_revised', + 'U': "invoice_retailer_accuracy", + 'V': "ocr_image_accuracy", + 'W': "ocr_image_speed_(seconds)", + 'X': "is_reviewed", + 'Y': "bad_image_reasons", + 'Z': "countermeasures", + 'AA':"imei_revised_accuracy", + 'AB': "invoice_number_revised_accuracy", + 'AC': 'purchase_date_revised_accuracy', + 'AD':'retailer_revised_accuracy', } start_index = 4 diff --git a/cope2n-api/report_detail.xlsx b/cope2n-api/report_detail.xlsx index 480d827cd5fdc37cf12c12785fbedf5e76a44b71..5f574dac90c743a58add0e7130b8c5855d02652c 100644 GIT binary patch delta 2722 zcmZ8jc{J2*8=kR@k%%#vu|;E_)W}-MK4h|w#3}>>5;976jZxm-Z?cPjxuqHKI43(Nue@}T+_-J604ESu3p5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