Merge pull request #96 from SDSRV-IDP/trungpt/fix_purchase_date_in_report
update report detail
This commit is contained in:
commit
5343623b59
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user