se compare yh part 2
Showing
3 changed files
with
51 additions
and
27 deletions
| ... | @@ -1350,6 +1350,8 @@ DDA_EN = 'DDA' | ... | @@ -1350,6 +1350,8 @@ DDA_EN = 'DDA' |
| 1350 | HMH_EN = 'Mortgage Waiver Letter' | 1350 | HMH_EN = 'Mortgage Waiver Letter' |
| 1351 | JYPZ_EN = 'Used Car Document' | 1351 | JYPZ_EN = 'Used Car Document' |
| 1352 | 1352 | ||
| 1353 | SKIP_CARD = {ID_EN, RP_EN} | ||
| 1354 | |||
| 1353 | 1355 | ||
| 1354 | ID_COMPARE_LOGIC = { | 1356 | ID_COMPARE_LOGIC = { |
| 1355 | 'customerName': ('姓名', 'se_name_compare', {}), | 1357 | 'customerName': ('姓名', 'se_name_compare', {}), |
| ... | @@ -1453,7 +1455,7 @@ JYPZ_COMPARE_LOGIC = { | ... | @@ -1453,7 +1455,7 @@ JYPZ_COMPARE_LOGIC = { |
| 1453 | 'vehicleTransactionAmount': ('price', 'se_amount_compare', {}), | 1455 | 'vehicleTransactionAmount': ('price', 'se_amount_compare', {}), |
| 1454 | 'customerName': ('buyer_name', 'se_name_compare', {'is_passport': True}), | 1456 | 'customerName': ('buyer_name', 'se_name_compare', {'is_passport': True}), |
| 1455 | 'idNum': ('buyer_id', 'se_contain_compare_2', {}), | 1457 | 'idNum': ('buyer_id', 'se_contain_compare_2', {}), |
| 1456 | 'date': ('date', 'se_date_compare_2', {'three_month': True}), | 1458 | 'date': ('date', 'se_date_compare_2', {}), |
| 1457 | } | 1459 | } |
| 1458 | 1460 | ||
| 1459 | HMH_COMPARE_LOGIC = { | 1461 | HMH_COMPARE_LOGIC = { |
| ... | @@ -1464,6 +1466,8 @@ HMH_COMPARE_LOGIC = { | ... | @@ -1464,6 +1466,8 @@ HMH_COMPARE_LOGIC = { |
| 1464 | 1466 | ||
| 1465 | # MVC_OCR_FIELD = 'mvc_ocr' | 1467 | # MVC_OCR_FIELD = 'mvc_ocr' |
| 1466 | 1468 | ||
| 1469 | SE_DETECT_CARD = [UCI_EN, JYPZ_EN, HMH_EN] | ||
| 1470 | |||
| 1467 | SE_COMPARE_FIELD = { | 1471 | SE_COMPARE_FIELD = { |
| 1468 | ID_EN: (IC_OCR_FIELD, ID_COMPARE_LOGIC, True), | 1472 | ID_EN: (IC_OCR_FIELD, ID_COMPARE_LOGIC, True), |
| 1469 | PP_EN: (PP_OCR_FIELD, PP_COMPARE_LOGIC, False), | 1473 | PP_EN: (PP_OCR_FIELD, PP_COMPARE_LOGIC, False), | ... | ... |
| ... | @@ -706,7 +706,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -706,7 +706,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
| 706 | traceback.format_exc())) | 706 | traceback.format_exc())) |
| 707 | 707 | ||
| 708 | 708 | ||
| 709 | def get_se_compare_info(last_obj, application_entity): | 709 | def get_se_compare_info(last_obj, application_entity, detect_list): |
| 710 | compare_info = {} | 710 | compare_info = {} |
| 711 | individual_info_dict = {} | 711 | individual_info_dict = {} |
| 712 | main_role_info = {} | 712 | main_role_info = {} |
| ... | @@ -832,10 +832,14 @@ def get_se_compare_info(last_obj, application_entity): | ... | @@ -832,10 +832,14 @@ def get_se_compare_info(last_obj, application_entity): |
| 832 | for jypz_field in consts.SE_USED_FIELD: | 832 | for jypz_field in consts.SE_USED_FIELD: |
| 833 | jypz_field_input.append((jypz_field, vehicle_info_dict[jypz_field])) | 833 | jypz_field_input.append((jypz_field, vehicle_info_dict[jypz_field])) |
| 834 | jypz_field_input.append((consts.SE_GB_USED_FIELD[-1], last_obj.first_submmison_date)) | 834 | jypz_field_input.append((consts.SE_GB_USED_FIELD[-1], last_obj.first_submmison_date)) |
| 835 | vehicle_info[consts.UCI_EN] = vehicle_field_input | ||
| 836 | vehicle_info[consts.MVC_EN] = gb_field_input | 835 | vehicle_info[consts.MVC_EN] = gb_field_input |
| 837 | vehicle_info[consts.MVC34_EN] = gb34_field_input | 836 | vehicle_info[consts.MVC34_EN] = gb34_field_input |
| 838 | vehicle_info[consts.JYPZ_EN] = jypz_field_input | 837 | if not detect_list[0]: |
| 838 | vehicle_info[consts.UCI_EN] = vehicle_field_input | ||
| 839 | if not detect_list[1]: | ||
| 840 | vehicle_info[consts.JYPZ_EN] = jypz_field_input | ||
| 841 | if detect_list[0] and detect_list[1]: | ||
| 842 | vehicle_info[consts.UCI_EN] = vehicle_field_input | ||
| 839 | compare_info['vehicleInfo'] = vehicle_info | 843 | compare_info['vehicleInfo'] = vehicle_info |
| 840 | 844 | ||
| 841 | bank_info_dict = json.loads(last_obj.bank_info) | 845 | bank_info_dict = json.loads(last_obj.bank_info) |
| ... | @@ -861,13 +865,14 @@ def get_se_compare_info(last_obj, application_entity): | ... | @@ -861,13 +865,14 @@ def get_se_compare_info(last_obj, application_entity): |
| 861 | bank_info[consts.DDA_EN] = dda_field_input | 865 | bank_info[consts.DDA_EN] = dda_field_input |
| 862 | compare_info['bankInfo'] = bank_info | 866 | compare_info['bankInfo'] = bank_info |
| 863 | 867 | ||
| 864 | other_info = {} | 868 | if not detect_list[-1]: |
| 865 | hmh_field_input = [] | 869 | other_info = {} |
| 866 | hmh_field_input.append((consts.SE_HMH_FIELD[0], hmh_name)) | 870 | hmh_field_input = [] |
| 867 | hmh_field_input.append((consts.SE_HMH_FIELD[1], hmh_id)) | 871 | hmh_field_input.append((consts.SE_HMH_FIELD[0], hmh_name)) |
| 868 | hmh_field_input.append((consts.SE_HMH_FIELD[2], last_obj.application_id)) | 872 | hmh_field_input.append((consts.SE_HMH_FIELD[1], hmh_id)) |
| 869 | other_info[consts.HMH_EN] = hmh_field_input | 873 | hmh_field_input.append((consts.SE_HMH_FIELD[2], last_obj.application_id)) |
| 870 | compare_info['other'] = other_info | 874 | other_info[consts.HMH_EN] = hmh_field_input |
| 875 | compare_info['other'] = other_info | ||
| 871 | 876 | ||
| 872 | return compare_info | 877 | return compare_info |
| 873 | 878 | ||
| ... | @@ -876,6 +881,7 @@ def se_compare_license(license_en, ocr_res_dict, field_list): | ... | @@ -876,6 +881,7 @@ def se_compare_license(license_en, ocr_res_dict, field_list): |
| 876 | ocr_field, compare_logic, special_expiry_date = consts.SE_COMPARE_FIELD[license_en] | 881 | ocr_field, compare_logic, special_expiry_date = consts.SE_COMPARE_FIELD[license_en] |
| 877 | 882 | ||
| 878 | is_find = False | 883 | is_find = False |
| 884 | no_ocr_result = False | ||
| 879 | result_field_list = [] | 885 | result_field_list = [] |
| 880 | ocr_res_str = ocr_res_dict.get(ocr_field) | 886 | ocr_res_str = ocr_res_dict.get(ocr_field) |
| 881 | if ocr_res_str is not None: | 887 | if ocr_res_str is not None: |
| ... | @@ -921,12 +927,14 @@ def se_compare_license(license_en, ocr_res_dict, field_list): | ... | @@ -921,12 +927,14 @@ def se_compare_license(license_en, ocr_res_dict, field_list): |
| 921 | img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY, '') if result == consts.RESULT_N else empty_str | 927 | img_path = ocr_res_list[res_idx].get(consts.IMG_PATH_KEY, '') if result == consts.RESULT_N else empty_str |
| 922 | error_type = empty_error_type if result == consts.RESULT_Y else ErrorType.OCR.value | 928 | error_type = empty_error_type if result == consts.RESULT_Y else ErrorType.OCR.value |
| 923 | result_field_list.append((name, value, result, ocr_str, img_path, error_type)) | 929 | result_field_list.append((name, value, result, ocr_str, img_path, error_type)) |
| 930 | else: | ||
| 931 | no_ocr_result = True | ||
| 924 | 932 | ||
| 925 | if not is_find: | 933 | if not is_find: |
| 926 | for name, value in field_list: | 934 | for name, value in field_list: |
| 927 | result_field_list.append((name, value, consts.RESULT_N, empty_str, empty_str, ErrorType.NF.value)) | 935 | result_field_list.append((name, value, consts.RESULT_N, empty_str, empty_str, ErrorType.NF.value)) |
| 928 | 936 | ||
| 929 | return result_field_list | 937 | return result_field_list, no_ocr_result |
| 930 | 938 | ||
| 931 | 939 | ||
| 932 | def se_mvc34_compare(license_en, ocr_res_dict, field_list): | 940 | def se_mvc34_compare(license_en, ocr_res_dict, field_list): |
| ... | @@ -1012,13 +1020,14 @@ def se_compare_process(compare_info, ocr_res_dict): | ... | @@ -1012,13 +1020,14 @@ def se_compare_process(compare_info, ocr_res_dict): |
| 1012 | for license_dict in license_list: | 1020 | for license_dict in license_list: |
| 1013 | for license_en, field_list in license_dict.items(): | 1021 | for license_en, field_list in license_dict.items(): |
| 1014 | failure_field = [] | 1022 | failure_field = [] |
| 1015 | result_field_list = se_compare_license(license_en, ocr_res_dict, field_list) | 1023 | result_field_list, no_ocr_result = se_compare_license(license_en, ocr_res_dict, field_list) |
| 1016 | for name, value, result, ocr_str, img_path, error_type in result_field_list: | 1024 | for name, value, result, ocr_str, img_path, error_type in result_field_list: |
| 1017 | total_fields += 1 | 1025 | if license_en not in consts.SKIP_CARD or not no_ocr_result: |
| 1018 | if result == consts.RESULT_N: | 1026 | total_fields += 1 |
| 1019 | failed_count += 1 | 1027 | if result == consts.RESULT_N: |
| 1020 | successful_at_this_level = False | 1028 | failed_count += 1 |
| 1021 | failure_field.append(name) | 1029 | successful_at_this_level = False |
| 1030 | failure_field.append(name) | ||
| 1022 | compare_result.append( | 1031 | compare_result.append( |
| 1023 | { | 1032 | { |
| 1024 | consts.HEAD_LIST[0]: info_key, | 1033 | consts.HEAD_LIST[0]: info_key, |
| ... | @@ -1040,14 +1049,16 @@ def se_compare_process(compare_info, ocr_res_dict): | ... | @@ -1040,14 +1049,16 @@ def se_compare_process(compare_info, ocr_res_dict): |
| 1040 | failure_field = [] | 1049 | failure_field = [] |
| 1041 | if license_en == consts.MVC34_EN: | 1050 | if license_en == consts.MVC34_EN: |
| 1042 | result_field_list = se_mvc34_compare(license_en, ocr_res_dict, field_list) | 1051 | result_field_list = se_mvc34_compare(license_en, ocr_res_dict, field_list) |
| 1052 | no_ocr_result = False | ||
| 1043 | else: | 1053 | else: |
| 1044 | result_field_list = se_compare_license(license_en, ocr_res_dict, field_list) | 1054 | result_field_list, no_ocr_result = se_compare_license(license_en, ocr_res_dict, field_list) |
| 1045 | for name, value, result, ocr_str, img_path, error_type in result_field_list: | 1055 | for name, value, result, ocr_str, img_path, error_type in result_field_list: |
| 1046 | total_fields += 1 | 1056 | if license_en != consts.DDA_EN or not no_ocr_result: |
| 1047 | if result == consts.RESULT_N: | 1057 | total_fields += 1 |
| 1048 | failed_count += 1 | 1058 | if result == consts.RESULT_N: |
| 1049 | successful_at_this_level = False | 1059 | failed_count += 1 |
| 1050 | failure_field.append(name) | 1060 | successful_at_this_level = False |
| 1061 | failure_field.append(name) | ||
| 1051 | compare_result.append( | 1062 | compare_result.append( |
| 1052 | { | 1063 | { |
| 1053 | consts.HEAD_LIST[0]: info_key, | 1064 | consts.HEAD_LIST[0]: info_key, |
| ... | @@ -1071,11 +1082,20 @@ def se_compare_process(compare_info, ocr_res_dict): | ... | @@ -1071,11 +1082,20 @@ def se_compare_process(compare_info, ocr_res_dict): |
| 1071 | return compare_result, total_fields, failed_count, successful_at_this_level, failure_reason_str | 1082 | return compare_result, total_fields, failed_count, successful_at_this_level, failure_reason_str |
| 1072 | 1083 | ||
| 1073 | 1084 | ||
| 1085 | def se_result_detect(ocr_res_dict): | ||
| 1086 | detect_list = [] | ||
| 1087 | for license_en in consts.SE_DETECT_CARD: | ||
| 1088 | ocr_field, _, _ = consts.SE_COMPARE_FIELD[license_en] | ||
| 1089 | ocr_res_str = ocr_res_dict.get(ocr_field) | ||
| 1090 | detect_list.append(ocr_res_str is None) | ||
| 1091 | return detect_list | ||
| 1092 | |||
| 1074 | def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict): | 1093 | def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict): |
| 1075 | try: | 1094 | try: |
| 1076 | # 比对逻辑 | 1095 | # 比对逻辑 |
| 1077 | start_time = datetime.now() | 1096 | start_time = datetime.now() |
| 1078 | compare_info = get_se_compare_info(last_obj, application_entity) | 1097 | detect_list = se_result_detect(ocr_res_dict) |
| 1098 | compare_info = get_se_compare_info(last_obj, application_entity, detect_list) | ||
| 1079 | compare_result, total_fields, failed_count, successful_at_this_level, failure_reason_str = se_compare_process( | 1099 | compare_result, total_fields, failed_count, successful_at_this_level, failure_reason_str = se_compare_process( |
| 1080 | compare_info, ocr_res_dict) | 1100 | compare_info, ocr_res_dict) |
| 1081 | compare_log.info('{0} [SE] [compare success] [entity={1}] [id={2}] [ocr_res_id={3}] [result={4}]'.format( | 1101 | compare_log.info('{0} [SE] [compare success] [entity={1}] [id={2}] [ocr_res_id={3}] [result={4}]'.format( |
| ... | @@ -1094,7 +1114,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res | ... | @@ -1094,7 +1114,7 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res |
| 1094 | res_obj.application_id = application_id | 1114 | res_obj.application_id = application_id |
| 1095 | res_obj.compare_count = total_fields | 1115 | res_obj.compare_count = total_fields |
| 1096 | res_obj.failed_count = failed_count | 1116 | res_obj.failed_count = failed_count |
| 1097 | res_obj.is_finish = failed_count == 0 | 1117 | res_obj.is_finish = successful_at_this_level |
| 1098 | res_obj.version = '{0}{1}{2}'.format(consts.INFO_SOURCE[0], consts.SPLIT_STR, last_obj.application_version) | 1118 | res_obj.version = '{0}{1}{2}'.format(consts.INFO_SOURCE[0], consts.SPLIT_STR, last_obj.application_version) |
| 1099 | # res_obj.reason1_count = reason1_count | 1119 | # res_obj.reason1_count = reason1_count |
| 1100 | res_obj.result = json.dumps(compare_result) | 1120 | res_obj.result = json.dumps(compare_result) | ... | ... |
| ... | @@ -203,7 +203,7 @@ class Comparison: | ... | @@ -203,7 +203,7 @@ class Comparison: |
| 203 | 203 | ||
| 204 | def se_date_compare(self, input_str, ocr_str, **kwargs): | 204 | def se_date_compare(self, input_str, ocr_str, **kwargs): |
| 205 | if kwargs.get('long', False): | 205 | if kwargs.get('long', False): |
| 206 | if '长期' in ocr_str or '永久' in ocr_str or '***' in ocr_str or '至今' in ocr_str: | 206 | if '长期' in ocr_str or '永久' in ocr_str or '***' in ocr_str or '至今' in ocr_str or '年—月—日' in ocr_str or '年 月 日' in ocr_str: |
| 207 | if kwargs.get('today', False) or input_str in ['2099-12-31', '2099-01-01', '2999-12-31', '2999-01-01']: | 207 | if kwargs.get('today', False) or input_str in ['2099-12-31', '2099-01-01', '2999-12-31', '2999-01-01']: |
| 208 | return self.RESULT_Y | 208 | return self.RESULT_Y |
| 209 | else: | 209 | else: | ... | ... |
-
Please register or sign in to post a comment