From c5f2f634d35ed2b03e451756b2da454ac3558fba Mon Sep 17 00:00:00 2001 From: TannedCung Date: Tue, 18 Jun 2024 15:52:40 +0700 Subject: [PATCH] Fix: Mix accuracy by images --- .../celery_worker/process_report_tasks.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 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 1d3b27e..ea01557 100755 --- a/cope2n-api/fwd_api/celery_worker/process_report_tasks.py +++ b/cope2n-api/fwd_api/celery_worker/process_report_tasks.py @@ -12,6 +12,7 @@ from ..utils.redis import RedisUtils from ..utils.cache import set_cache, get_cache from django.utils import timezone from django.db.models import Q +from itertools import chain import json import copy import os @@ -123,20 +124,17 @@ def create_accuracy_report(report_id, **kwargs): "retailername": mean_list(request_att["acc"]["reviewed"].get("retailername", [None])), "sold_to_party": mean_list(request_att["acc"]["reviewed"].get("sold_to_party", [None])), "invoice_no": mean_list(request_att["acc"]["reviewed"].get("invoice_no", [None]))} - rq_accuracy = {"feedback": [], - "reviewed": []} + rq_accuracy = [] for rpf in _report_files: - for cl in rpf.feedback_accuracy.keys(): - rq_accuracy["feedback"] += rpf.feedback_accuracy[cl] - for cl in rpf.reviewed_accuracy.keys(): - rq_accuracy["reviewed"] += rpf.reviewed_accuracy[cl] + if sum(len(value_list) for value_list in rpf.reviewed_accuracy.values()): + rq_accuracy += list(chain(*rpf.reviewed_accuracy.values())) + elif sum(len(value_list) for value_list in rpf.feedback_accuracy.values()): + rq_accuracy += list(chain(*rpf.feedback_accuracy.values())) request.is_required = False - if len(rq_accuracy["reviewed"]) > 0: - request.raw_accuracy = mean_list(rq_accuracy["reviewed"]) - elif len(rq_accuracy["feedback"]) > 0: - request.raw_accuracy = mean_list(rq_accuracy["feedback"]) + if len(rq_accuracy) > 0: + request.raw_accuracy = mean_list(rq_accuracy) request.is_required = request.raw_accuracy < settings.NEED_REVIEW if isinstance(request.raw_accuracy, float) else False # No need to review by default request.save()