Merge pull request #121 from SDSRV-IDP/BE/remove_validation
Be/remove validation
This commit is contained in:
commit
d3b933aaac
@ -127,7 +127,7 @@ def process_csv_feedback(csv_file_path, feedback_id):
|
|||||||
print(f"[ERROR] image.doc_type: {image.doc_type} - image.index_in_request: {image.index_in_request} - time_cost: {time_cost} - {e}")
|
print(f"[ERROR] image.doc_type: {image.doc_type} - image.index_in_request: {image.index_in_request} - time_cost: {time_cost} - {e}")
|
||||||
if not validate_feedback_file(_feedback_result, _predict_result):
|
if not validate_feedback_file(_feedback_result, _predict_result):
|
||||||
status[request_id] = "Missalign imei number between feedback and predict"
|
status[request_id] = "Missalign imei number between feedback and predict"
|
||||||
continue
|
# continue
|
||||||
if image.doc_type == "invoice":
|
if image.doc_type == "invoice":
|
||||||
_predict_result["imei_number"] = []
|
_predict_result["imei_number"] = []
|
||||||
if _feedback_result:
|
if _feedback_result:
|
||||||
@ -136,7 +136,7 @@ def process_csv_feedback(csv_file_path, feedback_id):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
_predict_result = {"retailername": None, "sold_to_party": None, "invoice_no": None, "purchase_date": [], "imei_number": [_predict_result["imei_number"][image.index_in_request]]}
|
_predict_result = {"retailername": None, "sold_to_party": None, "invoice_no": None, "purchase_date": [], "imei_number": [_predict_result["imei_number"][image.index_in_request]]}
|
||||||
_feedback_result = {"retailername": None, "sold_to_party": None, "invoice_no": None, "purchase_date": None, "imei_number": [_feedback_result["imei_number"][image.index_in_request]]} if _feedback_result else None
|
_feedback_result = {"retailername": None, "sold_to_party": None, "invoice_no": None, "purchase_date": None, "imei_number": [_feedback_result["imei_number"][image.index_in_request]]} if _feedback_result and len(_feedback_result["imei_number"]) > image.index_in_request else None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print (f"[ERROR]: {request_id} - {e}")
|
print (f"[ERROR]: {request_id} - {e}")
|
||||||
image.predict_result = _predict_result
|
image.predict_result = _predict_result
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from tqdm import tqdm
|
||||||
|
from fwd_api.models import SubscriptionRequestFile, SubscriptionRequest
|
||||||
|
from fwd_api.exception.exceptions import InvalidException
|
||||||
|
from fwd_api.utils.accuracy import predict_result_to_ready
|
||||||
|
import traceback
|
||||||
|
import copy
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
KEY = "imei_number"
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Refactor database for image level'
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
# Add your command-line arguments here
|
||||||
|
parser.add_argument('start', type=str, help='start date, sample: 2023-01-02T00:00:00+0700')
|
||||||
|
parser.add_argument('end', type=str, help='end date, sample: 2023-01-03T00:00:00+0700')
|
||||||
|
|
||||||
|
def process_request(self, request):
|
||||||
|
if len(request.request_id.split(".")[0].split("_")) < 2:
|
||||||
|
return
|
||||||
|
images = SubscriptionRequestFile.objects.filter(request=request)
|
||||||
|
|
||||||
|
if not request.predict_result:
|
||||||
|
self.stdout.write(self.style.WARNING(f"Key predict_result not found in {request.request_id}"))
|
||||||
|
return
|
||||||
|
if request.predict_result.get("status", 200) != 200:
|
||||||
|
self.stdout.write(self.style.WARNING(f"Not a sucess request {request.request_id}"))
|
||||||
|
return
|
||||||
|
|
||||||
|
for i, image in enumerate(images):
|
||||||
|
try:
|
||||||
|
if isinstance(image.reviewed_result, dict):
|
||||||
|
# print(f"[INFO]: dict ... {request.predict_result}")
|
||||||
|
if isinstance(image.reviewed_result[KEY], str):
|
||||||
|
image.reviewed_result[KEY] = [image.reviewed_result[KEY]]
|
||||||
|
image.save()
|
||||||
|
except Exception as e:
|
||||||
|
self.stdout.write(self.style.ERROR(f"Request: {request.request_id} failed with {e}"))
|
||||||
|
print(traceback.format_exc())
|
||||||
|
continue
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
start = options['start']
|
||||||
|
end = options['end']
|
||||||
|
|
||||||
|
if start or end:
|
||||||
|
try:
|
||||||
|
start_date = timezone.datetime.strptime(start, '%Y-%m-%dT%H:%M:%S%z') # We care only about day precision only
|
||||||
|
end_date = timezone.datetime.strptime(end, '%Y-%m-%dT%H:%M:%S%z')
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[INFO]: start: {start}")
|
||||||
|
print(f"[INFO]: end: {end}")
|
||||||
|
raise InvalidException(excArgs="Date format")
|
||||||
|
subcription_iter = SubscriptionRequest.objects.filter(created_at__range=(start_date, end_date))
|
||||||
|
else:
|
||||||
|
subcription_iter = SubscriptionRequest.objects.all()
|
||||||
|
|
||||||
|
for request in tqdm(subcription_iter.iterator()):
|
||||||
|
self.process_request(request)
|
||||||
|
self.stdout.write(self.style.SUCCESS('Sample Django management command executed successfully!'))
|
@ -529,6 +529,7 @@ def validate_feedback_file(feedback, predict):
|
|||||||
num_imei_predict = len(predict.get("imei_number", []))
|
num_imei_predict = len(predict.get("imei_number", []))
|
||||||
if num_imei_feedback != num_imei_predict:
|
if num_imei_feedback != num_imei_predict:
|
||||||
return False
|
return False
|
||||||
|
feedback["imei_number"] = imei_feedback
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def first_of_list(the_list):
|
def first_of_list(the_list):
|
||||||
|
Loading…
Reference in New Issue
Block a user