Fix: Mix accuracy by images

This commit is contained in:
TannedCung 2024-06-18 15:52:40 +07:00
parent 3596f38cbc
commit c5f2f634d3

View File

@ -12,6 +12,7 @@ from ..utils.redis import RedisUtils
from ..utils.cache import set_cache, get_cache from ..utils.cache import set_cache, get_cache
from django.utils import timezone from django.utils import timezone
from django.db.models import Q from django.db.models import Q
from itertools import chain
import json import json
import copy import copy
import os import os
@ -123,20 +124,17 @@ def create_accuracy_report(report_id, **kwargs):
"retailername": mean_list(request_att["acc"]["reviewed"].get("retailername", [None])), "retailername": mean_list(request_att["acc"]["reviewed"].get("retailername", [None])),
"sold_to_party": mean_list(request_att["acc"]["reviewed"].get("sold_to_party", [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]))} "invoice_no": mean_list(request_att["acc"]["reviewed"].get("invoice_no", [None]))}
rq_accuracy = {"feedback": [], rq_accuracy = []
"reviewed": []}
for rpf in _report_files: for rpf in _report_files:
for cl in rpf.feedback_accuracy.keys(): if sum(len(value_list) for value_list in rpf.reviewed_accuracy.values()):
rq_accuracy["feedback"] += rpf.feedback_accuracy[cl] rq_accuracy += list(chain(*rpf.reviewed_accuracy.values()))
for cl in rpf.reviewed_accuracy.keys(): elif sum(len(value_list) for value_list in rpf.feedback_accuracy.values()):
rq_accuracy["reviewed"] += rpf.reviewed_accuracy[cl] rq_accuracy += list(chain(*rpf.feedback_accuracy.values()))
request.is_required = False request.is_required = False
if len(rq_accuracy["reviewed"]) > 0: if len(rq_accuracy) > 0:
request.raw_accuracy = mean_list(rq_accuracy["reviewed"]) request.raw_accuracy = mean_list(rq_accuracy)
elif len(rq_accuracy["feedback"]) > 0:
request.raw_accuracy = mean_list(rq_accuracy["feedback"])
request.is_required = request.raw_accuracy < settings.NEED_REVIEW if isinstance(request.raw_accuracy, float) else False # No need to review by default 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() request.save()