f682cf20 by 周伟奇

fix amount

1 parent e6c82ee3
...@@ -41,13 +41,15 @@ TRANS_MAP = { ...@@ -41,13 +41,15 @@ TRANS_MAP = {
41 'C': "0", 41 'C': "0",
42 'c': "0", 42 'c': "0",
43 '(': "0", 43 '(': "0",
44 '(': "0",
45 'o': "0", 44 'o': "0",
46 'O': "0", 45 'O': "0",
47 'D': "0", 46 'D': "0",
47
48 '[': "1", 48 '[': "1",
49 ']': "1",
49 'l': "1", 50 'l': "1",
50 'L': "1", 51 'L': "1",
52
51 'A': "4", 53 'A': "4",
52 's': "5", 54 's': "5",
53 'S': "5", 55 'S': "5",
...@@ -57,6 +59,7 @@ TRANS_MAP = { ...@@ -57,6 +59,7 @@ TRANS_MAP = {
57 'B': "13", 59 'B': "13",
58 } 60 }
59 TRANS = str.maketrans(TRANS_MAP) 61 TRANS = str.maketrans(TRANS_MAP)
62 ERROR_CHARS = {'.', '·', '•'}
60 63
61 CARD_RATIO = 0.9 64 CARD_RATIO = 0.9
62 UNKNOWN_CARD = '未知卡号' 65 UNKNOWN_CARD = '未知卡号'
......
...@@ -458,7 +458,6 @@ class Command(BaseCommand, LoggerMixin): ...@@ -458,7 +458,6 @@ class Command(BaseCommand, LoggerMixin):
458 pdf_handler.extract_image() 458 pdf_handler.extract_image()
459 self.cronjob_log.info('{0} [pdf to img end] [business_type={1}] [doc_id={2}]'.format( 459 self.cronjob_log.info('{0} [pdf to img end] [business_type={1}] [doc_id={2}]'.format(
460 self.log_base, business_type, doc.id)) 460 self.log_base, business_type, doc.id))
461 write_zip_file(img_save_path, os.path.join(doc_data_path, '{0}_img.zip'.format(doc.id)))
462 461
463 # 4.获取OCR结果并且构建excel文件 462 # 4.获取OCR结果并且构建excel文件
464 bs_summary = {} 463 bs_summary = {}
...@@ -514,6 +513,8 @@ class Command(BaseCommand, LoggerMixin): ...@@ -514,6 +513,8 @@ class Command(BaseCommand, LoggerMixin):
514 speed_time = int(end_time - start_time) 513 speed_time = int(end_time - start_time)
515 self.cronjob_log.error('{0} [upload failed] [business_type={1}] [doc_id={2}] [speed_time={3}] ' 514 self.cronjob_log.error('{0} [upload failed] [business_type={1}] [doc_id={2}] [speed_time={3}] '
516 '[err={4}]'.format(self.log_base, business_type, doc.id, speed_time, e)) 515 '[err={4}]'.format(self.log_base, business_type, doc.id, speed_time, e))
516 write_zip_file(img_save_path, os.path.join(doc_data_path, '{0}_img.zip'.format(doc.id)))
517
517 else: 518 else:
518 doc.status = DocStatus.COMPLETE.value 519 doc.status = DocStatus.COMPLETE.value
519 doc.save() 520 doc.save()
...@@ -521,5 +522,6 @@ class Command(BaseCommand, LoggerMixin): ...@@ -521,5 +522,6 @@ class Command(BaseCommand, LoggerMixin):
521 speed_time = int(end_time - start_time) 522 speed_time = int(end_time - start_time)
522 self.cronjob_log.info('{0} [process complete] [business_type={1}] [doc_id={2}] ' 523 self.cronjob_log.info('{0} [process complete] [business_type={1}] [doc_id={2}] '
523 '[speed_time={3}]'.format(self.log_base, business_type, doc.id, speed_time)) 524 '[speed_time={3}]'.format(self.log_base, business_type, doc.id, speed_time))
525 write_zip_file(img_save_path, os.path.join(doc_data_path, '{0}_img.zip'.format(doc.id)))
524 526
525 self.cronjob_log.info('{0} [stop safely]'.format(self.log_base)) 527 self.cronjob_log.info('{0} [stop safely]'.format(self.log_base))
......
...@@ -207,11 +207,20 @@ class BSWorkbook(Workbook): ...@@ -207,11 +207,20 @@ class BSWorkbook(Workbook):
207 def amount_format(amount_str): 207 def amount_format(amount_str):
208 if not isinstance(amount_str, str) or amount_str == '': 208 if not isinstance(amount_str, str) or amount_str == '':
209 return amount_str 209 return amount_str
210 # 替换 210 # 1.替换
211 res_str = amount_str.translate(consts.TRANS) 211 res_str = amount_str.translate(consts.TRANS)
212 # 删除多余的- 212 # 2.删除多余的-
213 res_str = res_str[0] + res_str[1:].replace('-', '') 213 res_str = res_str[0] + res_str[1:].replace('-', '')
214 # TODO 逗号与句号处理 214 # 3.首字符处理
215 if res_str[0] in consts.ERROR_CHARS:
216 res_str = '-{0}'.format(res_str[1:])
217 # 4.逗号与句号处理
218 if len(res_str) >= 4:
219 period_idx = len(res_str) - 3
220 if res_str[period_idx] == '.' and res_str[period_idx - 1] == ',':
221 res_str = '{0}{1}'.format(res_str[:period_idx - 1], res_str[period_idx:])
222 elif res_str[period_idx] == ',':
223 res_str = '{0}.{1}'.format(res_str[:period_idx], res_str[period_idx + 1:])
215 return res_str 224 return res_str
216 225
217 def build_month_sheet(self, card, month_mapping, ms, is_reverse): 226 def build_month_sheet(self, card, month_mapping, ms, is_reverse):
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!