fix compare
Showing
1 changed file
with
61 additions
and
25 deletions
... | @@ -24,44 +24,64 @@ def get_order_dict(src_dict, order_tuple): | ... | @@ -24,44 +24,64 @@ def get_order_dict(src_dict, order_tuple): |
24 | return order_dict | 24 | return order_dict |
25 | 25 | ||
26 | 26 | ||
27 | def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set, diff_idx=None): | 27 | def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): |
28 | is_find = False | 28 | is_find = False |
29 | find_dict = {} | ||
30 | ocr_res_str = ocr_res_dict.get(ocr_field) | 29 | ocr_res_str = ocr_res_dict.get(ocr_field) |
31 | if ocr_res_str is not None: | 30 | if ocr_res_str is not None: |
32 | ocr_res_list = json.loads(ocr_res_str) | 31 | ocr_res_list = json.loads(ocr_res_str) |
33 | res_len = len(ocr_res_list) | 32 | # res_len = len(ocr_res_list) |
34 | for ocr_res in ocr_res_list: | 33 | for ocr_res in ocr_res_list: |
35 | if is_find: | 34 | if is_find: |
36 | break | 35 | break |
37 | for idx, compare_tuple in enumerate(compare_list): | 36 | for idx, compare_tuple in enumerate(compare_list): |
37 | input_str = info_dict.get(compare_tuple[0]) | ||
38 | ocr_str = ocr_res.get(compare_tuple[1], '') | ||
38 | compare_res = getattr(cp, compare_tuple[2])( | 39 | compare_res = getattr(cp, compare_tuple[2])( |
39 | info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), **compare_tuple[3]) | 40 | info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), **compare_tuple[3]) |
40 | if idx == 0 and compare_res == consts.RESULT_N and res_len != 1: | 41 | if idx == 0 and compare_res == consts.RESULT_N: |
41 | break | 42 | break |
42 | is_find = True | 43 | is_find = True |
43 | find_dict = ocr_res | ||
44 | info_dict[compare_tuple[0] + 'Result'] = compare_res | 44 | info_dict[compare_tuple[0] + 'Result'] = compare_res |
45 | if input_str is not None: | ||
46 | info_dict[compare_tuple[0]] = ocr_str | ||
45 | res_set.add(compare_res) | 47 | res_set.add(compare_res) |
46 | if not is_find: | 48 | if not is_find: |
47 | res_set.add(consts.RESULT_N) | 49 | res_set.add(consts.RESULT_N) |
48 | for compare_tuple in compare_list: | 50 | for compare_tuple in compare_list: |
49 | info_dict[compare_tuple[0] + 'Result'] = consts.RESULT_N | 51 | info_dict[compare_tuple[0] + 'Result'] = consts.RESULT_NA |
50 | if diff_idx is not None: | 52 | if compare_tuple[0] in info_dict: |
51 | diff_field = compare_list[diff_idx][0] + 'Result' | 53 | info_dict[compare_tuple[0]] = '' |
52 | if info_dict.get(diff_field) == consts.RESULT_N: | 54 | |
55 | |||
56 | def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): | ||
57 | no_match_vino = [] | ||
58 | is_find = False | ||
59 | ocr_res_str = ocr_res_dict.get(ocr_field) | ||
60 | if ocr_res_str is not None: | ||
61 | ocr_res_list = json.loads(ocr_res_str) | ||
62 | for ocr_res in ocr_res_list: | ||
53 | if is_find: | 63 | if is_find: |
54 | diff_value = find_dict.get(compare_list[diff_idx][1], consts.RESULT_N) | 64 | break |
55 | elif ocr_res_str is not None: | 65 | for idx, compare_tuple in enumerate(compare_list): |
56 | for ocr_res in ocr_res_list: | 66 | input_str = info_dict.get(compare_tuple[0]) |
57 | if ocr_res.get(compare_list[diff_idx][1]): | 67 | ocr_str = ocr_res.get(compare_tuple[1], '') |
58 | diff_value = ocr_res.get(compare_list[diff_idx][1]) | 68 | compare_res = getattr(cp, compare_tuple[2])( |
59 | break | 69 | info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), **compare_tuple[3]) |
60 | else: | 70 | if idx == 0 and compare_res == consts.RESULT_N: |
61 | diff_value = consts.RESULT_N | 71 | no_match_vino.append(ocr_str) |
62 | else: | 72 | break |
63 | diff_value = consts.RESULT_N | 73 | is_find = True |
64 | info_dict[diff_field] = diff_value | 74 | info_dict[compare_tuple[0] + 'Result'] = compare_res |
75 | if input_str is not None: | ||
76 | info_dict[compare_tuple[0]] = ocr_str | ||
77 | res_set.add(compare_res) | ||
78 | if not is_find: | ||
79 | res_set.add(consts.RESULT_N) | ||
80 | for compare_tuple in compare_list: | ||
81 | info_dict[compare_tuple[0] + 'Result'] = consts.RESULT_N | ||
82 | if compare_tuple[0] in info_dict: | ||
83 | info_dict[compare_tuple[0]] = '' | ||
84 | return is_find, no_match_vino | ||
65 | 85 | ||
66 | 86 | ||
67 | @app.task | 87 | @app.task |
... | @@ -117,7 +137,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -117,7 +137,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
117 | order_individual_cus_info = get_order_dict(individual_cus_info, consts.IN_ORDER) | 137 | order_individual_cus_info = get_order_dict(individual_cus_info, consts.IN_ORDER) |
118 | # sep营业执照 | 138 | # sep营业执照 |
119 | if is_sep and order_individual_cus_info.get('companyName') is not None: | 139 | if is_sep and order_individual_cus_info.get('companyName') is not None: |
120 | field_compare(order_individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set, 2) | 140 | field_compare(order_individual_cus_info, ocr_res_dict, consts.BL_OCR_FIELD, consts.TCSEP, res_set) |
121 | 141 | ||
122 | # 个人信息证件 | 142 | # 个人信息证件 |
123 | id_type = order_individual_cus_info.get('idType') | 143 | id_type = order_individual_cus_info.get('idType') |
... | @@ -134,10 +154,26 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -134,10 +154,26 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
134 | usedcar_info = json.loads(last_obj.usedcar_info) | 154 | usedcar_info = json.loads(last_obj.usedcar_info) |
135 | order_usedcar_info = get_order_dict(usedcar_info, consts.UC_ORDER) | 155 | order_usedcar_info = get_order_dict(usedcar_info, consts.UC_ORDER) |
136 | 156 | ||
137 | field_compare(order_usedcar_info, ocr_res_dict, consts.MVC_OCR_FIELD, consts.PCUSD_MVC, res_set, 0) | 157 | mvc_find, mvc_vinos = usedcar_info_compare(order_usedcar_info, ocr_res_dict, consts.MVC_OCR_FIELD, consts.PCUSD_MVC, res_set) |
138 | 158 | ||
139 | if order_usedcar_info[consts.PCUSD_MVC[0][0] + 'Result'] == consts.RESULT_Y: | 159 | # if order_usedcar_info[consts.PCUSD_MVC[0][0] + 'Result'] == consts.RESULT_Y: |
140 | field_compare(order_usedcar_info, ocr_res_dict, consts.DL_OCR_FIELD, consts.PCUSD_DL, res_set, 0) | 160 | dl_find, dl_vinos = usedcar_info_compare(order_usedcar_info, ocr_res_dict, consts.DL_OCR_FIELD, consts.PCUSD_DL, res_set) |
161 | |||
162 | if mvc_find is True and dl_find is False: | ||
163 | vino = dl_vinos[0] if len(dl_vinos) > 0 else '' | ||
164 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | ||
165 | elif mvc_find is False and dl_find is True: | ||
166 | vino = mvc_vinos[0] if len(mvc_vinos) > 0 else '' | ||
167 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | ||
168 | order_usedcar_info[consts.PCUSD_MVC[0][0] + 'Result'] = consts.RESULT_N | ||
169 | elif mvc_find is False and dl_find is False: | ||
170 | vino_list = [] | ||
171 | if len(mvc_vinos) > 0: | ||
172 | vino_list.append(mvc_vinos[0]) | ||
173 | if len(dl_vinos) > 0: | ||
174 | vino_list.append(dl_vinos[0]) | ||
175 | vino = '、'.join(vino_list) | ||
176 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | ||
141 | 177 | ||
142 | comparison_res['OCR_Input']['usedCarInfo'] = order_usedcar_info | 178 | comparison_res['OCR_Input']['usedCarInfo'] = order_usedcar_info |
143 | 179 | ... | ... |
-
Please register or sign in to post a comment