|
|
|
@ -115,84 +115,86 @@ class ReportAccumulateByRequest:
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def update_total(total, report_file):
|
|
|
|
|
total["total_images"] += 1
|
|
|
|
|
total["images_quality"]["successful"] += 1 if not report_file.is_bad_image else 0
|
|
|
|
|
total["images_quality"]["bad"] += 1 if report_file.is_bad_image else 0
|
|
|
|
|
doc_type = "imei"
|
|
|
|
|
if report_file.doc_type in ["imei", "invoice", "all"]:
|
|
|
|
|
doc_type = report_file.doc_type
|
|
|
|
|
else:
|
|
|
|
|
print(f"[WARM]: Weird doc type {report_file.doc_type} if request id: {report_file.correspond_request_id}")
|
|
|
|
|
total["num_imei"] += 1 if doc_type == "imei" else 0
|
|
|
|
|
total["num_invoice"] += 1 if doc_type == "invoice" else 0
|
|
|
|
|
if report_file.bad_image_reason not in settings.ACC_EXCLUDE_RESEASONS:
|
|
|
|
|
total["images_quality"]["successful"] += 1 if not report_file.is_bad_image else 0
|
|
|
|
|
total["images_quality"]["bad"] += 1 if report_file.is_bad_image else 0
|
|
|
|
|
total["total_images"] += 1
|
|
|
|
|
doc_type = "imei"
|
|
|
|
|
if report_file.doc_type in ["imei", "invoice", "all"]:
|
|
|
|
|
doc_type = report_file.doc_type
|
|
|
|
|
else:
|
|
|
|
|
print(f"[WARM]: Weird doc type {report_file.doc_type} if request id: {report_file.correspond_request_id}")
|
|
|
|
|
total["num_imei"] += 1 if doc_type == "imei" else 0
|
|
|
|
|
total["num_invoice"] += 1 if doc_type == "invoice" else 0
|
|
|
|
|
|
|
|
|
|
if sum([len(report_file.reviewed_accuracy[x]) for x in report_file.reviewed_accuracy.keys() if "_count" not in x]) > 0 :
|
|
|
|
|
total["average_accuracy_rate"]["imei"].add(report_file.reviewed_accuracy.get("imei_number", []))
|
|
|
|
|
total["average_accuracy_rate"]["purchase_date"].add(report_file.reviewed_accuracy.get("purchase_date", []))
|
|
|
|
|
total["average_accuracy_rate"]["retailer_name"].add(report_file.reviewed_accuracy.get("retailername", []))
|
|
|
|
|
total["average_accuracy_rate"]["sold_to_party"].add(report_file.reviewed_accuracy.get("sold_to_party", []))
|
|
|
|
|
elif sum([len(report_file.feedback_accuracy[x]) for x in report_file.feedback_accuracy.keys() if "_count" not in x]) > 0:
|
|
|
|
|
total["average_accuracy_rate"]["imei"].add(report_file.feedback_accuracy.get("imei_number", []))
|
|
|
|
|
total["average_accuracy_rate"]["purchase_date"].add(report_file.feedback_accuracy.get("purchase_date", []))
|
|
|
|
|
total["average_accuracy_rate"]["retailer_name"].add(report_file.feedback_accuracy.get("retailername", []))
|
|
|
|
|
total["average_accuracy_rate"]["sold_to_party"].add(report_file.feedback_accuracy.get("sold_to_party", []))
|
|
|
|
|
if sum([len(report_file.reviewed_accuracy[x]) for x in report_file.reviewed_accuracy.keys() if "_count" not in x]) > 0 :
|
|
|
|
|
total["average_accuracy_rate"]["imei"].add(report_file.reviewed_accuracy.get("imei_number", []))
|
|
|
|
|
total["average_accuracy_rate"]["purchase_date"].add(report_file.reviewed_accuracy.get("purchase_date", []))
|
|
|
|
|
total["average_accuracy_rate"]["retailer_name"].add(report_file.reviewed_accuracy.get("retailername", []))
|
|
|
|
|
total["average_accuracy_rate"]["sold_to_party"].add(report_file.reviewed_accuracy.get("sold_to_party", []))
|
|
|
|
|
elif sum([len(report_file.feedback_accuracy[x]) for x in report_file.feedback_accuracy.keys() if "_count" not in x]) > 0:
|
|
|
|
|
total["average_accuracy_rate"]["imei"].add(report_file.feedback_accuracy.get("imei_number", []))
|
|
|
|
|
total["average_accuracy_rate"]["purchase_date"].add(report_file.feedback_accuracy.get("purchase_date", []))
|
|
|
|
|
total["average_accuracy_rate"]["retailer_name"].add(report_file.feedback_accuracy.get("retailername", []))
|
|
|
|
|
total["average_accuracy_rate"]["sold_to_party"].add(report_file.feedback_accuracy.get("sold_to_party", []))
|
|
|
|
|
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
total["feedback_accuracy"][key].add(report_file.feedback_accuracy.get(key, []))
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
total["reviewed_accuracy"][key].add(report_file.reviewed_accuracy.get(key, []))
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
total["feedback_accuracy"][key].add(report_file.feedback_accuracy.get(key, []))
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
total["reviewed_accuracy"][key].add(report_file.reviewed_accuracy.get(key, []))
|
|
|
|
|
|
|
|
|
|
if not total["average_processing_time"].get(report_file.doc_type, None):
|
|
|
|
|
print(f"[WARM]: Weird doctype: {report_file.doc_type}")
|
|
|
|
|
total["average_processing_time"][report_file.doc_type] = IterAvg()
|
|
|
|
|
total["average_processing_time"][report_file.doc_type].add_avg(report_file.time_cost, 1) if report_file.time_cost else 0
|
|
|
|
|
if not total["average_processing_time"].get(report_file.doc_type, None):
|
|
|
|
|
print(f"[WARM]: Weird doctype: {report_file.doc_type}")
|
|
|
|
|
total["average_processing_time"][report_file.doc_type] = IterAvg()
|
|
|
|
|
total["average_processing_time"][report_file.doc_type].add_avg(report_file.time_cost, 1) if report_file.time_cost else 0
|
|
|
|
|
|
|
|
|
|
doc_type = "imei"
|
|
|
|
|
if report_file.doc_type in ["imei", "invoice", "all"]:
|
|
|
|
|
doc_type = report_file.doc_type
|
|
|
|
|
else:
|
|
|
|
|
print(f"[WARM]: Weird doc type {report_file.doc_type} if request id: {report_file.correspond_request_id}")
|
|
|
|
|
total["usage"]["imei"] += 1 if doc_type == "imei" else 0
|
|
|
|
|
total["usage"]["invoice"] += 1 if doc_type == "invoice" else 0
|
|
|
|
|
total["usage"]["total_images"] += 1
|
|
|
|
|
total["review_progress"].append(report_file.review_status)
|
|
|
|
|
doc_type = "imei"
|
|
|
|
|
if report_file.doc_type in ["imei", "invoice", "all"]:
|
|
|
|
|
doc_type = report_file.doc_type
|
|
|
|
|
else:
|
|
|
|
|
print(f"[WARM]: Weird doc type {report_file.doc_type} if request id: {report_file.correspond_request_id}")
|
|
|
|
|
total["usage"]["imei"] += 1 if doc_type == "imei" else 0
|
|
|
|
|
total["usage"]["invoice"] += 1 if doc_type == "invoice" else 0
|
|
|
|
|
total["usage"]["total_images"] += 1
|
|
|
|
|
total["review_progress"].append(report_file.review_status)
|
|
|
|
|
return total
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def update_day(day_data, report_file):
|
|
|
|
|
day_data["total_images"] += 1
|
|
|
|
|
day_data["images_quality"]["successful"] += 1 if not report_file.is_bad_image else 0
|
|
|
|
|
day_data["images_quality"]["bad"] += 1 if report_file.is_bad_image else 0
|
|
|
|
|
doc_type = "imei"
|
|
|
|
|
if report_file.doc_type in ["imei", "invoice", "all"]:
|
|
|
|
|
doc_type = report_file.doc_type
|
|
|
|
|
else:
|
|
|
|
|
print(f"[WARM]: Weird doc type {report_file.doc_type} if request id: {report_file.correspond_request_id}")
|
|
|
|
|
day_data["num_imei"] += 1 if doc_type == "imei" else 0
|
|
|
|
|
day_data["num_invoice"] += 1 if doc_type == "invoice" else 0
|
|
|
|
|
day_data["report_files"].append(report_file)
|
|
|
|
|
|
|
|
|
|
if sum([len(report_file.reviewed_accuracy[x]) for x in report_file.reviewed_accuracy.keys() if "_count" not in x]) > 0:
|
|
|
|
|
day_data["average_accuracy_rate"]["imei"].add(report_file.reviewed_accuracy.get("imei_number", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["purchase_date"].add(report_file.reviewed_accuracy.get("purchase_date", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["retailer_name"].add(report_file.reviewed_accuracy.get("retailername", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["sold_to_party"].add(report_file.reviewed_accuracy.get("sold_to_party", []))
|
|
|
|
|
elif sum([len(report_file.feedback_accuracy[x]) for x in report_file.feedback_accuracy.keys() if "_count" not in x]) > 0:
|
|
|
|
|
day_data["average_accuracy_rate"]["imei"].add(report_file.feedback_accuracy.get("imei_number", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["purchase_date"].add(report_file.feedback_accuracy.get("purchase_date", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["retailer_name"].add(report_file.feedback_accuracy.get("retailername", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["sold_to_party"].add(report_file.feedback_accuracy.get("sold_to_party", []))
|
|
|
|
|
if report_file.bad_image_reason not in settings.ACC_EXCLUDE_RESEASONS:
|
|
|
|
|
day_data["images_quality"]["successful"] += 1 if not report_file.is_bad_image else 0
|
|
|
|
|
day_data["images_quality"]["bad"] += 1 if report_file.is_bad_image else 0
|
|
|
|
|
day_data["total_images"] += 1
|
|
|
|
|
doc_type = "imei"
|
|
|
|
|
if report_file.doc_type in ["imei", "invoice", "all"]:
|
|
|
|
|
doc_type = report_file.doc_type
|
|
|
|
|
else:
|
|
|
|
|
print(f"[WARM]: Weird doc type {report_file.doc_type} if request id: {report_file.correspond_request_id}")
|
|
|
|
|
day_data["num_imei"] += 1 if doc_type == "imei" else 0
|
|
|
|
|
day_data["num_invoice"] += 1 if doc_type == "invoice" else 0
|
|
|
|
|
day_data["report_files"].append(report_file)
|
|
|
|
|
|
|
|
|
|
if sum([len(report_file.reviewed_accuracy[x]) for x in report_file.reviewed_accuracy.keys() if "_count" not in x]) > 0:
|
|
|
|
|
day_data["average_accuracy_rate"]["imei"].add(report_file.reviewed_accuracy.get("imei_number", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["purchase_date"].add(report_file.reviewed_accuracy.get("purchase_date", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["retailer_name"].add(report_file.reviewed_accuracy.get("retailername", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["sold_to_party"].add(report_file.reviewed_accuracy.get("sold_to_party", []))
|
|
|
|
|
elif sum([len(report_file.feedback_accuracy[x]) for x in report_file.feedback_accuracy.keys() if "_count" not in x]) > 0:
|
|
|
|
|
day_data["average_accuracy_rate"]["imei"].add(report_file.feedback_accuracy.get("imei_number", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["purchase_date"].add(report_file.feedback_accuracy.get("purchase_date", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["retailer_name"].add(report_file.feedback_accuracy.get("retailername", []))
|
|
|
|
|
day_data["average_accuracy_rate"]["sold_to_party"].add(report_file.feedback_accuracy.get("sold_to_party", []))
|
|
|
|
|
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
day_data["feedback_accuracy"][key].add(report_file.feedback_accuracy.get(key, []))
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
day_data["reviewed_accuracy"][key].add(report_file.reviewed_accuracy.get(key, []))
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
day_data["feedback_accuracy"][key].add(report_file.feedback_accuracy.get(key, []))
|
|
|
|
|
for key in ["imei_number", "purchase_date", "retailername", "sold_to_party"]:
|
|
|
|
|
day_data["reviewed_accuracy"][key].add(report_file.reviewed_accuracy.get(key, []))
|
|
|
|
|
|
|
|
|
|
if not day_data["average_processing_time"].get(report_file.doc_type, None):
|
|
|
|
|
print(f"[WARM]: Weird doctype: {report_file.doc_type}")
|
|
|
|
|
day_data["average_processing_time"][report_file.doc_type] = IterAvg()
|
|
|
|
|
day_data["average_processing_time"][report_file.doc_type].add_avg(report_file.time_cost, 1) if report_file.time_cost else 0
|
|
|
|
|
day_data["review_progress"].append(report_file.review_status)
|
|
|
|
|
if not day_data["average_processing_time"].get(report_file.doc_type, None):
|
|
|
|
|
print(f"[WARM]: Weird doctype: {report_file.doc_type}")
|
|
|
|
|
day_data["average_processing_time"][report_file.doc_type] = IterAvg()
|
|
|
|
|
day_data["average_processing_time"][report_file.doc_type].add_avg(report_file.time_cost, 1) if report_file.time_cost else 0
|
|
|
|
|
day_data["review_progress"].append(report_file.review_status)
|
|
|
|
|
return day_data
|
|
|
|
|
|
|
|
|
|
def add(self, request, report_files):
|
|
|
|
@ -255,6 +257,8 @@ class ReportAccumulateByRequest:
|
|
|
|
|
_average_OCR_time = {"invoice": self.data[month][1][day]["average_processing_time"]["invoice"](), "imei": self.data[month][1][day]["average_processing_time"]["imei"](),
|
|
|
|
|
"invoice_count": self.data[month][1][day]["average_processing_time"]["invoice"].count, "imei_count": self.data[month][1][day]["average_processing_time"]["imei"].count}
|
|
|
|
|
|
|
|
|
|
_average_OCR_time["invoice"] = 0 if _average_OCR_time["invoice"] is None else _average_OCR_time["invoice"]
|
|
|
|
|
_average_OCR_time["imei"] = 0 if _average_OCR_time["imei"] is None else _average_OCR_time["imei"]
|
|
|
|
|
_average_OCR_time["avg"] = (_average_OCR_time["invoice"]*_average_OCR_time["invoice_count"] + _average_OCR_time["imei"]*_average_OCR_time["imei_count"])/(_average_OCR_time["imei_count"] + _average_OCR_time["invoice_count"]) if (_average_OCR_time["imei_count"] + _average_OCR_time["invoice_count"]) > 0 else None
|
|
|
|
|
acumulated_acc = {"feedback_accuracy": {},
|
|
|
|
|
"reviewed_accuracy": {}}
|
|
|
|
@ -527,6 +531,8 @@ class IterAvg:
|
|
|
|
|
self.avg = (self.avg*(self.count-count) + avg*count)/(self.count)
|
|
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
if self.count == 0:
|
|
|
|
|
return None
|
|
|
|
|
return self.avg
|
|
|
|
|
|
|
|
|
|
def validate_feedback_file(feedback, predict):
|
|
|
|
|