From d075efda672a6b4015d5b3fb833a426f241cc863 Mon Sep 17 00:00:00 2001 From: dx-tan Date: Thu, 1 Feb 2024 15:32:40 +0700 Subject: [PATCH] Enhancement: exclude bad images from accuracy calculation --- .../celery_worker/process_report_tasks.py | 2 +- .../migrations/0178_alter_reportfile_acc.py | 18 ++++++++++++++++++ cope2n-api/fwd_api/models/ReportFile.py | 2 +- cope2n-api/fwd_api/utils/accuracy.py | 8 +++++++- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 cope2n-api/fwd_api/migrations/0178_alter_reportfile_acc.py 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 9dd6915..5f72781 100644 --- a/cope2n-api/fwd_api/celery_worker/process_report_tasks.py +++ b/cope2n-api/fwd_api/celery_worker/process_report_tasks.py @@ -116,7 +116,7 @@ def make_a_report(report_id, query_set): report.average_OCR_time = {"invoice": time_cost["invoice"](), "imei": time_cost["imei"](), "invoice_count": time_cost["invoice"].count, "imei_count": time_cost["imei"].count} - report.average_OCR_time["avg"] = (report.average_OCR_time["invoice"]*report.average_OCR_time["invoice_count"] + report.average_OCR_time["imei"]*report.average_OCR_time["imei_count"])/(report.average_OCR_time["imei_count"] + report.average_OCR_time["invoice_count"]) + report.average_OCR_time["avg"] = (report.average_OCR_time["invoice"]*report.average_OCR_time["invoice_count"] + report.average_OCR_time["imei"]*report.average_OCR_time["imei_count"])/(report.average_OCR_time["imei_count"] + report.average_OCR_time["invoice_count"]) if (report.average_OCR_time["imei_count"] + report.average_OCR_time["invoice_count"]) > 0 else None report.number_imei_transaction = transaction_att.get("imei", 0) report.number_invoice_transaction = transaction_att.get("invoice", 0) diff --git a/cope2n-api/fwd_api/migrations/0178_alter_reportfile_acc.py b/cope2n-api/fwd_api/migrations/0178_alter_reportfile_acc.py new file mode 100644 index 0000000..c760de1 --- /dev/null +++ b/cope2n-api/fwd_api/migrations/0178_alter_reportfile_acc.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.3 on 2024-02-01 08:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fwd_api', '0177_alter_report_subsidiary'), + ] + + operations = [ + migrations.AlterField( + model_name='reportfile', + name='acc', + field=models.FloatField(default=0, null=True), + ), + ] diff --git a/cope2n-api/fwd_api/models/ReportFile.py b/cope2n-api/fwd_api/models/ReportFile.py index f5ccaab..86e9270 100644 --- a/cope2n-api/fwd_api/models/ReportFile.py +++ b/cope2n-api/fwd_api/models/ReportFile.py @@ -23,7 +23,7 @@ class ReportFile(models.Model): feedback_accuracy = models.JSONField(null=True) reviewed_accuracy = models.JSONField(null=True) - acc = models.FloatField(default=0) + acc = models.FloatField(default=0, null=True) time_cost = models.FloatField(default=0) is_reviewed = models.CharField(default="NA", max_length=5) # NA, No, Yes diff --git a/cope2n-api/fwd_api/utils/accuracy.py b/cope2n-api/fwd_api/utils/accuracy.py index 06b9187..3ba1efd 100644 --- a/cope2n-api/fwd_api/utils/accuracy.py +++ b/cope2n-api/fwd_api/utils/accuracy.py @@ -419,7 +419,13 @@ def calculate_subcription_file(subcription_request_file): avg_acc = max([x for x in [avg_feedback, avg_reviewed] if x is not None]) if avg_acc < BAD_THRESHOLD: att["is_bad_image"] = True - att["avg_acc"] = avg_acc + # exclude bad images + for key_name in valid_keys: + att["acc"]["feedback"][key_name] = [] + att["acc"]["reviewed"][key_name] = [] + att["avg_acc"] = None + else: + att["avg_acc"] = avg_acc return 200, att def calculate_attributions(request): # for one request, return in order