Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
e6c82ee3
authored
2020-10-12 16:31:13 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix amount
1 parent
26691edc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
13 deletions
src/apps/doc/consts.py
src/apps/doc/ocr/wb.py
src/apps/doc/consts.py
View file @
e6c82ee
...
...
@@ -37,7 +37,26 @@ DEALER_CODE = 'ocr_situ_group'
# ---------银行流水模板相关--------------------------------------------------------------------------------------------
TRANS
=
str
.
maketrans
(
'Cc((oODlLAsSbgE'
,
'000000011455699'
)
TRANS_MAP
=
{
'C'
:
"0"
,
'c'
:
"0"
,
'('
:
"0"
,
'('
:
"0"
,
'o'
:
"0"
,
'O'
:
"0"
,
'D'
:
"0"
,
'['
:
"1"
,
'l'
:
"1"
,
'L'
:
"1"
,
'A'
:
"4"
,
's'
:
"5"
,
'S'
:
"5"
,
'b'
:
"6"
,
'g'
:
"9"
,
'E'
:
"9"
,
'B'
:
"13"
,
}
TRANS
=
str
.
maketrans
(
TRANS_MAP
)
CARD_RATIO
=
0.9
UNKNOWN_CARD
=
'未知卡号'
...
...
src/apps/doc/ocr/wb.py
View file @
e6c82ee
...
...
@@ -203,6 +203,17 @@ class BSWorkbook(Workbook):
ms
.
append
(
row
)
return
ms
@staticmethod
def
amount_format
(
amount_str
):
if
not
isinstance
(
amount_str
,
str
)
or
amount_str
==
''
:
return
amount_str
# 替换
res_str
=
amount_str
.
translate
(
consts
.
TRANS
)
# 删除多余的-
res_str
=
res_str
[
0
]
+
res_str
[
1
:]
.
replace
(
'-'
,
''
)
# TODO 逗号与句号处理
return
res_str
def
build_month_sheet
(
self
,
card
,
month_mapping
,
ms
,
is_reverse
):
tmp_ws
=
self
.
create_sheet
(
'tmp_ws'
)
for
month
in
sorted
(
month_mapping
.
keys
()):
...
...
@@ -235,9 +246,7 @@ class BSWorkbook(Workbook):
# 3.3.余额转数值
over_cell
=
rows
[
consts
.
OVER_IDX
]
try
:
if
isinstance
(
over_cell
.
value
,
str
):
over_cell
.
value
=
over_cell
.
value
.
translate
(
consts
.
TRANS
)
over_cell
.
value
=
locale
.
atof
(
over_cell
.
value
)
over_cell
.
value
=
locale
.
atof
(
self
.
amount_format
(
over_cell
.
value
))
except
Exception
as
e
:
continue
else
:
...
...
@@ -246,22 +255,16 @@ class BSWorkbook(Workbook):
# 3.4.金额转数值
try
:
try
:
if
isinstance
(
amount_cell
.
value
,
str
):
# TODO 可在转化数字失败后,再替换
amount_cell
.
value
=
amount_cell
.
value
.
translate
(
consts
.
TRANS
)
amount_cell
.
value
=
locale
.
atof
(
amount_cell
.
value
)
amount_cell
.
value
=
locale
.
atof
(
self
.
amount_format
(
amount_cell
.
value
))
except
Exception
as
e
:
try
:
if
isinstance
(
rows
[
consts
.
INCOME_IDX
]
.
value
,
str
):
rows
[
consts
.
OUTLAY_IDX
]
.
value
=
rows
[
consts
.
INCOME_IDX
]
.
value
.
translate
(
consts
.
TRANS
)
amount_cell
.
value
=
locale
.
atof
(
rows
[
consts
.
OUTLAY_IDX
]
.
value
)
amount_cell
.
value
=
locale
.
atof
(
self
.
amount_format
(
rows
[
consts
.
INCOME_IDX
]
.
value
))
if
amount_cell
.
value
==
0
:
raise
elif
amount_cell
.
value
<
0
:
amount_cell
.
value
=
-
amount_cell
.
value
except
Exception
as
e
:
if
isinstance
(
rows
[
consts
.
OUTLAY_IDX
]
.
value
,
str
):
rows
[
consts
.
OUTLAY_IDX
]
.
value
=
rows
[
consts
.
OUTLAY_IDX
]
.
value
.
translate
(
consts
.
TRANS
)
amount_cell
.
value
=
locale
.
atof
(
rows
[
consts
.
OUTLAY_IDX
]
.
value
)
amount_cell
.
value
=
locale
.
atof
(
self
.
amount_format
(
rows
[
consts
.
OUTLAY_IDX
]
.
value
))
if
amount_cell
.
value
>
0
:
amount_cell
.
value
=
-
amount_cell
.
value
except
Exception
as
e
:
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment