7c50d819 by 周伟奇

fix bug

1 parent 779b9a10
...@@ -102,10 +102,10 @@ class Command(BaseCommand, LoggerMixin): ...@@ -102,10 +102,10 @@ class Command(BaseCommand, LoggerMixin):
102 raise EDMSException(edms_exc) 102 raise EDMSException(edms_exc)
103 self.cronjob_log.info('{0} [edms download success] [pdf_path={1}]'.format(self.log_base, pdf_path)) 103 self.cronjob_log.info('{0} [edms download success] [pdf_path={1}]'.format(self.log_base, pdf_path))
104 104
105 def bs_process(self, wb, ocr_data, bs_summary, unknown_summary, classify, res_list, pno, ino): 105 def bs_process(self, wb, ocr_data, bs_summary, unknown_summary, classify, res_list, pno, ino, part_idx):
106 sheets = ocr_data.get('data', []) 106 sheets = ocr_data.get('data', [])
107 if not sheets: 107 if not sheets:
108 res_list.append((pno, ino, consts.RES_SUCCESS_EMPTY)) 108 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
109 return 109 return
110 # confidence = ocr_data.get('confidence', 1) 110 # confidence = ocr_data.get('confidence', 1)
111 img_name = 'page_{0}_img_{1}'.format(pno, ino) 111 img_name = 'page_{0}_img_{1}'.format(pno, ino)
...@@ -171,22 +171,22 @@ class Command(BaseCommand, LoggerMixin): ...@@ -171,22 +171,22 @@ class Command(BaseCommand, LoggerMixin):
171 ed_list.append(summary[6]) 171 ed_list.append(summary[6])
172 172
173 if cells_exists: 173 if cells_exists:
174 res_list.append((pno, ino, consts.RES_SUCCESS)) 174 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
175 else: 175 else:
176 res_list.append((pno, ino, consts.RES_SUCCESS_EMPTY)) 176 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
177 177
178 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino): 178 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx):
179 # 类别:'0'身份证, '1'居住证 179 # 类别:'0'身份证, '1'居住证
180 license_data = ocr_data.get('data', []) 180 license_data = ocr_data.get('data', [])
181 if not license_data: 181 if not license_data:
182 res_list.append((pno, ino, consts.RES_SUCCESS_EMPTY)) 182 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
183 return 183 return
184 res_list.append((pno, ino, consts.RES_SUCCESS)) 184 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
185 license_summary.setdefault(classify, []).extend(license_data) 185 license_summary.setdefault(classify, []).extend(license_data)
186 186
187 def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino): 187 def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx):
188 if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET: 188 if ocr_res_2.get('ErrorCode') in consts.SUCCESS_CODE_SET:
189 res_list.append((pno, ino, consts.RES_SUCCESS)) 189 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
190 if pid == consts.BC_PID: 190 if pid == consts.BC_PID:
191 # 银行卡 191 # 银行卡
192 # res_dict = {} 192 # res_dict = {}
...@@ -201,7 +201,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -201,7 +201,7 @@ class Command(BaseCommand, LoggerMixin):
201 res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '') 201 res_dict[field_dict.get('chn_key', '')] = field_dict.get('value', '')
202 license_summary.setdefault(classify, []).append(res_dict) 202 license_summary.setdefault(classify, []).append(res_dict)
203 else: 203 else:
204 res_list.append((pno, ino, consts.RES_FAILED_2)) 204 res_list.append((pno, ino, part_idx, consts.RES_FAILED_2))
205 205
206 @staticmethod 206 @staticmethod
207 def parse_img_path(img_path): 207 def parse_img_path(img_path):
...@@ -493,26 +493,27 @@ class Command(BaseCommand, LoggerMixin): ...@@ -493,26 +493,27 @@ class Command(BaseCommand, LoggerMixin):
493 wb = BSWorkbook(interest_keyword, salary_keyword, loan_keyword) 493 wb = BSWorkbook(interest_keyword, salary_keyword, loan_keyword)
494 for img_path, res in ocr_1_res.items(): 494 for img_path, res in ocr_1_res.items():
495 pno, ino = self.parse_img_path(img_path) 495 pno, ino = self.parse_img_path(img_path)
496 part_idx = 1
496 if res.get('code') == 1: 497 if res.get('code') == 1:
497 ocr_data_list = res.get('data', []) 498 ocr_data_list = res.get('data', [])
498 if not isinstance(ocr_data_list, list): 499 if not isinstance(ocr_data_list, list):
499 res_list.append((pno, ino, consts.RES_FAILED_3)) 500 res_list.append((pno, ino, part_idx, consts.RES_FAILED_3))
500 self.cronjob_log.info('{0} [ocr_1 res error] [img={1}] [res={2}]'.format( 501 self.cronjob_log.info('{0} [ocr_1 res error] [img={1}] [res={2}]'.format(
501 self.log_base, img_path, res)) 502 self.log_base, img_path, res))
502 else: 503 else:
503 for part_idx, ocr_data in enumerate(ocr_data_list): 504 for part_idx, ocr_data in enumerate(ocr_data_list):
504 ino_part = '{0}-{1}'.format(ino, part_idx) 505 part_idx = part_idx + 1
505 classify = ocr_data.get('classify') 506 classify = ocr_data.get('classify')
506 if classify is None: 507 if classify is None:
507 res_list.append((pno, ino_part, consts.RES_FAILED_3)) 508 res_list.append((pno, ino, part_idx, consts.RES_FAILED_3))
508 self.cronjob_log.info('{0} [ocr_1 res error] [img={1}] [res={2}]'.format( 509 self.cronjob_log.info('{0} [ocr_1 res error] [img={1}] [res={2}]'.format(
509 self.log_base, img_path, res)) 510 self.log_base, img_path, res))
510 continue 511 continue
511 elif classify in consts.OTHER_CLASSIFY_SET: # 其他类 512 elif classify in consts.OTHER_CLASSIFY_SET: # 其他类
512 res_list.append((pno, ino_part, consts.RES_SUCCESS_OTHER)) 513 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER))
513 continue 514 continue
514 elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1 515 elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1
515 self.license1_process(ocr_data, license_summary, classify, res_list, pno, ino_part) 516 self.license1_process(ocr_data, license_summary, classify, res_list, pno, ino, part_idx)
516 elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2 517 elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2
517 pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify) 518 pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify)
518 file_data = ocr_data.get('section_img') 519 file_data = ocr_data.get('section_img')
...@@ -557,16 +558,16 @@ class Command(BaseCommand, LoggerMixin): ...@@ -557,16 +558,16 @@ class Command(BaseCommand, LoggerMixin):
557 card_name_res.get('data', {}).get('is_exists_name') == 0: 558 card_name_res.get('data', {}).get('is_exists_name') == 0:
558 name = '无' 559 name = '无'
559 ocr_2_res['Name'] = name 560 ocr_2_res['Name'] = name
560 self.license2_process(ocr_2_res, license_summary, pid, classify, res_list, pno, ino_part) 561 self.license2_process(ocr_2_res, license_summary, pid, classify, res_list, pno, ino, part_idx)
561 break 562 break
562 else: 563 else:
563 res_list.append((pno, ino_part, consts.RES_FAILED_2)) 564 res_list.append((pno, ino, part_idx, consts.RES_FAILED_2))
564 self.cronjob_log.warn( 565 self.cronjob_log.warn(
565 '{0} [ocr_2 failed] [img_path={1}]'.format(self.log_base, img_path)) 566 '{0} [ocr_2 failed] [img_path={1}]'.format(self.log_base, img_path))
566 else: # 流水处理 567 else: # 流水处理
567 self.bs_process(wb, ocr_data, bs_summary, unknown_summary, classify, res_list, pno, ino_part) 568 self.bs_process(wb, ocr_data, bs_summary, unknown_summary, classify, res_list, pno, ino, part_idx)
568 else: 569 else:
569 res_list.append((pno, ino, consts.RES_FAILED_1)) 570 res_list.append((pno, ino, part_idx, consts.RES_FAILED_1))
570 self.cronjob_log.info('{0} [ocr_1 res error] [img={1}] [res={2}]'.format( 571 self.cronjob_log.info('{0} [ocr_1 res error] [img={1}] [res={2}]'.format(
571 self.log_base, img_path, res)) 572 self.log_base, img_path, res))
572 573
......
...@@ -582,7 +582,7 @@ class BSWorkbook(Workbook): ...@@ -582,7 +582,7 @@ class BSWorkbook(Workbook):
582 582
583 def res_sheet(self, res_list): 583 def res_sheet(self, res_list):
584 if res_list: 584 if res_list:
585 res_list.sort(key=lambda x: (x[0], x[1])) 585 res_list.sort(key=lambda x: (x[0], x[1], x[2]))
586 ws = self.create_sheet(consts.RES_SHEET_NAME) 586 ws = self.create_sheet(consts.RES_SHEET_NAME)
587 ws.append(consts.RES_SHEET_HEADER) 587 ws.append(consts.RES_SHEET_HEADER)
588 for res_tuple in res_list: 588 for res_tuple in res_list:
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!