From 580f099200414b4ab74419929bfb63843d72d6fa Mon Sep 17 00:00:00 2001 From: dx-tan Date: Fri, 29 Mar 2024 17:47:28 +0700 Subject: [PATCH] Fix: #103 --- .../celery_worker/process_report_tasks.py | 7 +++++-- .../fwd_api/management/commands/migrate-csv.py | 15 ++++++++++----- cope2n-api/fwd_api/utils/accuracy.py | 6 +++--- .../components/report-detail/report-table.tsx | 12 +++++++++++- docker-compose-dev.yml | 16 ++++++++-------- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/cope2n-api/fwd_api/celery_worker/process_report_tasks.py b/cope2n-api/fwd_api/celery_worker/process_report_tasks.py index 820be0d..506762d 100755 --- a/cope2n-api/fwd_api/celery_worker/process_report_tasks.py +++ b/cope2n-api/fwd_api/celery_worker/process_report_tasks.py @@ -260,10 +260,13 @@ def create_billing_report(report_id, **kwargs): report.average_OCR_time = {"invoice": None, "imei": None, "invoice_count": None, "imei_count": None, "avg": None} report.status = "Ready" + detail_file_name = "detail_" + report.report_id + ".xlsx" + dashboard_file_name = "overview_" + report.report_id + ".xlsx" + report.S3_file_name = os.path.join("report", report.report_id, detail_file_name) + report.S3_dashboard_file_name = os.path.join("report", report.report_id, dashboard_file_name) report.save() data_workbook = dict2xlsx(billing_data, _type='billing_report') - local_workbook = save_workbook_file( - report.report_id + ".xlsx", report, data_workbook) + local_workbook = save_workbook_file(detail_file_name, report, data_workbook) s3_key = save_report_to_S3(report.report_id, local_workbook) except IndexError as e: print(e) diff --git a/cope2n-api/fwd_api/management/commands/migrate-csv.py b/cope2n-api/fwd_api/management/commands/migrate-csv.py index b4ad435..440992e 100644 --- a/cope2n-api/fwd_api/management/commands/migrate-csv.py +++ b/cope2n-api/fwd_api/management/commands/migrate-csv.py @@ -34,7 +34,8 @@ class Command(BaseCommand): "imei_number": [], "retailername": "", "purchase_date": "", - "sold_to_party": "" + "sold_to_party": "", + "invoice_no": "" } images = SubscriptionRequestFile.objects.filter(request=request, file_category=FileCategory.Origin.value) @@ -46,7 +47,7 @@ class Command(BaseCommand): if request.predict_result.get("status", 200) != 200: raise AttributeError(f"Failed request: {request.request_id}") - for field in ['retailername', 'purchase_date', 'imei_number']: + for field in ['retailername', 'purchase_date', 'imei_number', 'invoice_no']: if image.feedback_result[field] is not None and ((field == 'imei_number' and len(image.feedback_result[field]) > 0 and image.feedback_result[field][0] == user_feedback) or image.feedback_result[field] == user_feedback): is_match = True @@ -65,10 +66,11 @@ class Command(BaseCommand): "imei_number": [], "retailername": "", "purchase_date": "", - "sold_to_party": "" + "sold_to_party": "", + "invoice_no": "" } - if image.doc_type == "invoice" and field in ['retailername', 'purchase_date']: + if image.doc_type == "invoice" and field in ['retailername', 'purchase_date', 'invoice_no']: if _reviewed_result: _reviewed_result[field] = reviewed_result _reviewed_result["imei_number"] = [] @@ -79,11 +81,14 @@ class Command(BaseCommand): "retailername": None, "sold_to_party": None, "purchase_date": None, - "imei_number": [reviewed_result] + "imei_number": [reviewed_result], + "invoice_no": None } if _reviewed_result else None image.reviewed_result = _reviewed_result if reason: image.reason = reason + else: + image.reason = "" if counter: image.counter_measures = counter image.save() diff --git a/cope2n-api/fwd_api/utils/accuracy.py b/cope2n-api/fwd_api/utils/accuracy.py index d334b2a..833a4fd 100755 --- a/cope2n-api/fwd_api/utils/accuracy.py +++ b/cope2n-api/fwd_api/utils/accuracy.py @@ -584,7 +584,7 @@ def extract_report_detail_list(report_detail_list, lower=False, in_percent=True) 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' + format_to_date = '%Y-%m-%d' ocr_extraction_date = ocr_extraction_date.strftime(format_to_date) return ocr_extraction_date @@ -755,8 +755,8 @@ def create_billing_data(subscription_requests): _sub = map_subsidiary_short_to_long(request.redemption_id[:2]) redemption_id = request.redemption_id - format_to_time = '%Y/%m/%d %H:%M' - format_to_date = '%Y/%m/%d' + format_to_time = '%Y-%m-%d %H:%M' + format_to_date = '%Y-%m-%d' format_to_month = '%B %Y' naive_created_time = timezone.make_naive(request.created_at) rq_created_at = timezone.make_aware(value=naive_created_time, timezone=timezone.get_current_timezone()) diff --git a/cope2n-fe/src/components/report-detail/report-table.tsx b/cope2n-fe/src/components/report-detail/report-table.tsx index ef4a5b0..17ac154 100644 --- a/cope2n-fe/src/components/report-detail/report-table.tsx +++ b/cope2n-fe/src/components/report-detail/report-table.tsx @@ -59,6 +59,16 @@ const ReportTable: React.FC = () => { }, width: 110, }, + { + title: 'Report Type', + dataIndex: 'Report Type', + key: 'Report Type', + render: (_, record) => { + const reportType = record["Report Type"]; + const uppercasedReportType = reportType.charAt(0).toUpperCase() + reportType.slice(1); + return <>{uppercasedReportType}; + }, + }, { title: 'Start Date', dataIndex: 'Start Date', @@ -172,7 +182,7 @@ const ReportTable: React.FC = () => { }, }, { - title: 'Average Processing Time (ms)', + title: 'Average Processing Time (seconds)', dataIndex: 'Avg. OCR Processing Time', key: 'Avg. OCR Processing Time', render: (_, record) => { diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 9b67208..3d31685 100755 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -89,12 +89,12 @@ services: depends_on: db-sbt: condition: service_started - # command: sh -c "chmod -R 777 /app; sleep 5; python manage.py collectstatic --no-input && - # python manage.py makemigrations && - # python manage.py migrate && - # python manage.py compilemessages && - # gunicorn fwd.asgi:application -k uvicorn.workers.UvicornWorker --timeout 300 -b 0.0.0.0:9000" # pre-makemigrations on prod - command: "sleep infinity" + command: sh -c "chmod -R 777 /app; sleep 5; python manage.py collectstatic --no-input && + python manage.py makemigrations && + python manage.py migrate && + python manage.py compilemessages && + gunicorn fwd.asgi:application -k uvicorn.workers.UvicornWorker --timeout 300 -b 0.0.0.0:9000" # pre-makemigrations on prod + # command: "sleep infinity" minio: image: minio/minio @@ -179,8 +179,8 @@ services: - ./cope2n-api:/app working_dir: /app - # command: sh -c "celery -A fwd_api.celery_worker.worker worker -l INFO -c 5" - command: bash -c "tail -f > /dev/null" + command: sh -c "celery -A fwd_api.celery_worker.worker worker -l INFO -c 5" + # command: bash -c "tail -f > /dev/null" # Back-end persistent db-sbt: