59cbfab2 by 周伟奇

fix bug & add skip_img_sheet

1 parent 6a5899fa
...@@ -33,4 +33,5 @@ data/* ...@@ -33,4 +33,5 @@ data/*
33 # 脚本 33 # 脚本
34 src/*.sh 34 src/*.sh
35 35
36 test*
...\ No newline at end of file ...\ No newline at end of file
36 test*
37 ocr_test.py
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -60,6 +60,8 @@ TRANS_MAP = { ...@@ -60,6 +60,8 @@ TRANS_MAP = {
60 } 60 }
61 TRANS = str.maketrans(TRANS_MAP) 61 TRANS = str.maketrans(TRANS_MAP)
62 ERROR_CHARS = {'.', '·', '•'} 62 ERROR_CHARS = {'.', '·', '•'}
63 SKIP_IMG_SHEET_NAME = '未处理图片'
64 SKIP_IMG_SHEET_HEADER = ('页码', '序号')
63 65
64 CARD_RATIO = 0.9 66 CARD_RATIO = 0.9
65 UNKNOWN_CARD = '未知卡号' 67 UNKNOWN_CARD = '未知卡号'
......
...@@ -141,32 +141,22 @@ class BSWorkbook(Workbook): ...@@ -141,32 +141,22 @@ class BSWorkbook(Workbook):
141 # month_info process 141 # month_info process
142 month_info = month_mapping.setdefault('xxxx-xx', []) 142 month_info = month_mapping.setdefault('xxxx-xx', [])
143 month_info.append((ws.title, min_row, ws.max_row, 0)) 143 month_info.append((ws.title, min_row, ws.max_row, 0))
144 elif len(month_list) == 1:
145 # reverse_trend_list process
146 reverse_trend = self.get_reverse_trend(dti.day, idx_list)
147 reverse_trend_list.append(reverse_trend)
148 # month_info process
149 month_info = month_mapping.setdefault(month_list[0], [])
150 day_mean = np.mean(dti.day.dropna())
151 if len(month_info) == 0:
152 month_info.append((ws.title, min_row, ws.max_row, day_mean))
153 else:
154 for i, item in enumerate(month_info):
155 if day_mean <= item[-1]:
156 month_info.insert(i, (ws.title, min_row, ws.max_row, day_mean))
157 break
158 else:
159 month_info.append((ws.title, min_row, ws.max_row, day_mean))
160 else: 144 else:
161 # reverse_trend_list process 145 # reverse_trend_list process
162 reverse_trend = self.get_reverse_trend(dti.day, idx_list) 146 reverse_trend = self.get_reverse_trend(dti.day, idx_list)
163 reverse_trend_list.append(reverse_trend) 147 reverse_trend_list.append(reverse_trend)
164 # month_info process 148 # month_info process
165 for i, item in enumerate(month_list[:-1]): 149 day_idx = dti.day
166 month_mapping.setdefault(item, []).append( 150 idx_list_max_idx = len(idx_list) - 1
167 (ws.title, idx_list[i] + min_row, idx_list[i + 1] + min_row - 1, self.MAX_MEAN)) 151 for i, item in enumerate(month_list):
168 month_mapping.setdefault(month_list[-1], []).insert( 152 if i == idx_list_max_idx:
169 0, (ws.title, idx_list[-1] + min_row, ws.max_row, 0)) 153 day_mean = np.mean(day_idx[idx_list[i]:].dropna())
154 month_mapping.setdefault(item, []).append(
155 (ws.title, idx_list[i] + min_row, ws.max_row, day_mean))
156 else:
157 day_mean = np.mean(day_idx[idx_list[i]: idx_list[i + 1]].dropna())
158 month_mapping.setdefault(item, []).append(
159 (ws.title, idx_list[i] + min_row, idx_list[i + 1] + min_row - 1, day_mean))
170 160
171 def build_metadata_rows(self, confidence, code, print_time, start_date, end_date): 161 def build_metadata_rows(self, confidence, code, print_time, start_date, end_date):
172 if start_date is None or end_date is None: 162 if start_date is None or end_date is None:
...@@ -259,7 +249,7 @@ class BSWorkbook(Workbook): ...@@ -259,7 +249,7 @@ class BSWorkbook(Workbook):
259 except Exception as e: 249 except Exception as e:
260 continue 250 continue
261 else: 251 else:
262 over_cell.number_format = numbers.FORMAT_NUMBER_COMMA_SEPARATED1 252 over_cell.number_format = numbers.FORMAT_GENERAL
263 253
264 # 3.4.金额转数值 254 # 3.4.金额转数值
265 try: 255 try:
...@@ -281,7 +271,7 @@ class BSWorkbook(Workbook): ...@@ -281,7 +271,7 @@ class BSWorkbook(Workbook):
281 else: 271 else:
282 if rows[consts.BORROW_IDX].value in consts.BORROW_OUTLAY_SET: 272 if rows[consts.BORROW_IDX].value in consts.BORROW_OUTLAY_SET:
283 amount_cell.value = -amount_cell.value 273 amount_cell.value = -amount_cell.value
284 amount_cell.number_format = numbers.FORMAT_NUMBER_COMMA_SEPARATED1 274 amount_cell.number_format = numbers.FORMAT_GENERAL
285 same_amount_mapping = amount_mapping.get(date_cell.value, {}) 275 same_amount_mapping = amount_mapping.get(date_cell.value, {})
286 fill_rows = same_amount_mapping.get(-amount_cell.value) 276 fill_rows = same_amount_mapping.get(-amount_cell.value)
287 if fill_rows: 277 if fill_rows:
...@@ -357,11 +347,11 @@ class BSWorkbook(Workbook): ...@@ -357,11 +347,11 @@ class BSWorkbook(Workbook):
357 end_date) 347 end_date)
358 348
359 # 3.创建月份表、提取/高亮关键行 349 # 3.创建月份表、提取/高亮关键行
360 is_reverse = False 350 # 倒序处理
361 if sum(reverse_trend_list) > 0: # 倒序处理 351 is_reverse = True if sum(reverse_trend_list) > 0 else False
362 is_reverse = True 352 for month_list in month_mapping.values():
363 for month_list in month_mapping.values(): 353 month_list.sort(key=lambda x: x[-1], reverse=is_reverse)
364 month_list.sort(key=lambda x: x[-1], reverse=True) 354
365 self.build_month_sheet(card, month_mapping, ms, is_reverse) 355 self.build_month_sheet(card, month_mapping, ms, is_reverse)
366 356
367 # 4.删除原表 357 # 4.删除原表
...@@ -379,6 +369,14 @@ class BSWorkbook(Workbook): ...@@ -379,6 +369,14 @@ class BSWorkbook(Workbook):
379 ws.append(bl_field) 369 ws.append(bl_field)
380 ws.append((None, )) 370 ws.append((None, ))
381 371
382 def rebuild(self, bs_summary, license_summary): 372 def skip_img_sheet(self, skip_img):
373 if skip_img:
374 ws = self.create_sheet(consts.SKIP_IMG_SHEET_NAME)
375 ws.append(consts.SKIP_IMG_SHEET_HEADER)
376 for img_tuple in skip_img:
377 ws.append(img_tuple)
378
379 def rebuild(self, bs_summary, license_summary, skip_img):
383 self.bs_rebuild(bs_summary) 380 self.bs_rebuild(bs_summary)
384 self.license_rebuild(license_summary) 381 self.license_rebuild(license_summary)
382 self.skip_img_sheet(skip_img)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!