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
f4a2c3cb
authored
2022-10-10 19:56:58 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add pre id
1 parent
90b2c2a2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
16 deletions
src/common/tools/comparison.py
src/prese/compare.py
src/prese/consts.py
src/common/tools/comparison.py
View file @
f4a2c3c
...
...
@@ -29,6 +29,8 @@ class Comparison:
self
.
RESULT_Y
=
'Y'
self
.
RESULT_N
=
'N'
self
.
RESULT_N1
=
'N1'
self
.
RESULT_N2
=
'N2'
self
.
RESULT_NA
=
'NA'
self
.
TRANS_MAP
=
{
...
...
@@ -331,6 +333,26 @@ class Comparison:
else
:
return
True
def
is_after_today_pre
(
self
,
ocr_str
):
dt_array
,
_
=
tslib
.
array_to_datetime
(
np
.
array
([
ocr_str
,
],
copy
=
False
,
dtype
=
np
.
object_
),
errors
=
"coerce"
,
utc
=
False
,
dayfirst
=
False
,
yearfirst
=
False
,
require_iso8601
=
True
,
)
dti
=
DatetimeIndex
(
dt_array
,
tz
=
None
,
name
=
None
)
ts
=
dti
[
0
]
if
isinstance
(
ts
,
NaTType
):
return
self
.
RESULT_N1
elif
ts
.
date
()
<
datetime
.
today
()
.
date
():
return
self
.
RESULT_N1
elif
ts
.
date
()
>
(
datetime
.
today
()
+
relativedelta
(
days
=
8
))
.
date
():
return
self
.
RESULT_Y
else
:
return
self
.
RESULT_N2
@staticmethod
def
is_predate_two_year
(
ocr_str
):
dt_array
,
_
=
tslib
.
array_to_datetime
(
...
...
@@ -350,7 +372,8 @@ class Comparison:
def
se_date_compare
(
self
,
input_str
,
ocr_str
,
**
kwargs
):
if
kwargs
.
get
(
'long'
,
False
):
if
'长期'
in
ocr_str
or
'永久'
in
ocr_str
or
'***'
in
ocr_str
or
'至今'
in
ocr_str
or
'年—月—日'
in
ocr_str
or
'年 月 日'
in
ocr_str
or
'年月日'
in
ocr_str
:
if
'长期'
in
ocr_str
or
'永久'
in
ocr_str
or
'***'
in
ocr_str
or
'至今'
in
ocr_str
or
'年—月—日'
in
ocr_str
\
or
'年 月 日'
in
ocr_str
or
'年月日'
in
ocr_str
:
if
kwargs
.
get
(
'today'
,
False
)
or
input_str
in
[
'2099-12-31'
,
'2099-01-01'
,
'2999-12-31'
,
'2999-01-01'
]:
return
self
.
RESULT_Y
else
:
...
...
@@ -622,6 +645,21 @@ class Comparison:
# return self.RESULT_N
# return self.RESULT_N
# 'long': True, 'ocr_split': True, 'input_replace': '', 'today': True
def
se_date_compare_pre
(
self
,
input_str
,
ocr_str
,
**
kwargs
):
if
'长期'
in
ocr_str
or
'永久'
in
ocr_str
or
'***'
in
ocr_str
or
'至今'
in
ocr_str
or
'年—月—日'
in
ocr_str
\
or
'年 月 日'
in
ocr_str
or
'年月日'
in
ocr_str
:
return
self
.
RESULT_Y
if
'至'
in
ocr_str
:
ocr_str
=
ocr_str
.
split
(
'至'
)[
-
1
]
elif
'-'
in
ocr_str
:
ocr_str
=
ocr_str
.
split
(
'-'
)[
-
1
]
# input_str = input_str.replace('-', '')
return
self
.
is_after_today_pre
(
ocr_str
)
cp
=
Comparison
()
...
...
src/prese/compare.py
View file @
f4a2c3c
...
...
@@ -23,8 +23,9 @@ def get_pos_compare_info(pos_info):
for
individual_cus_info
in
individual_cus_info_list
:
customer_name
=
individual_cus_info
.
get
(
'customerName'
,
''
)
.
strip
()
id_num
=
individual_cus_info
.
get
(
'idNum'
,
''
)
applicant_type
=
individual_cus_info
.
get
(
'applicantType'
,
''
)
if
individual_cus_info
.
get
(
'applicantType'
,
''
)
==
'CUSTR'
:
if
applicant_type
==
'CUSTR'
:
custr_name
=
customer_name
custr_id
=
id_num
...
...
@@ -32,7 +33,9 @@ def get_pos_compare_info(pos_info):
field_input
=
[(
consts
.
ID_FIELDS
[
0
],
customer_name
),
(
consts
.
ID_FIELDS
[
1
],
id_num
),
(
consts
.
ID_FIELDS
[
2
],
individual_cus_info
.
get
(
'idExpiryDate'
,
''
))]
compare_info
.
setdefault
(
consts
.
ID_EN
,
[])
.
append
(
field_input
)
compare_info
.
setdefault
(
consts
.
ID_EN
,
[])
.
append
(
(
consts
.
APPLICANT_TYPE_MAP
.
get
(
applicant_type
,
''
),
field_input
)
)
# 新车发票
vehicle_info
=
pos_info
.
get
(
'vehicleInfo'
,
{})
...
...
@@ -179,8 +182,8 @@ def pre_compare_process(compare_info, ocr_res_dict, id_res_list):
compare_result
=
{}
for
license_en
,
items_list
in
compare_info
.
items
():
if
license_en
==
consts
.
ID_EN
:
for
field_list
in
items_list
:
result_list
=
pre_compare_license_id
(
license_en
,
id_res_list
,
field_list
)
for
applicant_type
,
field_list
in
items_list
:
result_list
=
pre_compare_license_id
(
license_en
,
id_res_list
,
field_list
,
applicant_type
)
compare_result
.
setdefault
(
license_en
,
[])
.
append
(
result_list
)
elif
license_en
in
[
consts
.
HIL_CONTRACT_1_EN
,
consts
.
HIL_CONTRACT_2_EN
,
consts
.
AFC_CONTRACT_EN
]:
for
field_list
in
items_list
:
...
...
@@ -232,7 +235,7 @@ def pre_compare_license(license_en, ocr_res_dict, field_list):
return
result_field_list
def
pre_compare_license_id
(
license_en
,
id_res_list
,
field_list
):
def
pre_compare_license_id
(
license_en
,
id_res_list
,
field_list
,
applicant_type
):
ocr_field
,
compare_logic
,
no_find_comment
=
consts
.
PRE_COMPARE_LOGIC_MAP
[
license_en
]
is_find
=
False
...
...
@@ -274,23 +277,34 @@ def pre_compare_license_id(license_en, id_res_list, field_list):
break
# 过期期限特殊处理
if
name
==
'idExpiryDate'
and
result
==
consts
.
RESULT_N
:
# N, N1, N2, Y
if
name
==
'idExpiryDate'
and
result
==
consts
.
RESULT_N
:
# 遍历所有背面过期时间
if
len
(
expiry_dates
)
==
0
:
result
=
consts
.
RESULT_N1
ocr_str
=
empty_str
result
=
consts
.
RESULT_N
else
:
tmp_res_set
=
set
()
for
expiry_date
in
expiry_dates
:
expiry_date_res
=
getattr
(
cp
,
compare_logic
[
name
][
1
])(
value
,
expiry_date
,
**
compare_logic
[
name
][
2
])
if
expiry_date_res
==
consts
.
RESULT_N
:
tmp_res_set
.
add
(
expiry_date_res
)
if
expiry_date_res
==
consts
.
RESULT_N1
:
result
=
expiry_date_res
ocr_str
=
expiry_date
break
else
:
ocr_str
=
empty_str
result
=
consts
.
RESULT_Y
if
ca_or_se_idx
==
0
and
result
==
consts
.
RESULT_N
:
break
if
consts
.
RESULT_N2
in
tmp_res_set
:
result
=
consts
.
RESULT_N2
else
:
result
=
consts
.
RESULT_Y
if
ca_or_se_idx
==
0
:
if
name
==
'idExpiryDate'
:
if
result
==
consts
.
RESULT_N
or
result
==
consts
.
RESULT_N1
:
break
elif
result
==
consts
.
RESULT_N
:
break
if
ca_or_se_idx
==
1
:
is_find
=
True
...
...
@@ -299,10 +313,12 @@ def pre_compare_license_id(license_en, id_res_list, field_list):
if
isinstance
(
value
,
list
):
value
=
json
.
dumps
(
value
,
ensure_ascii
=
False
)
result_field_list
.
append
((
value
,
ocr_str
,
result
,
compare_logic
[
name
][
3
]))
comments
=
consts
.
ID_DATE_MAP
[
result
]
if
name
==
'idExpiryDate'
else
compare_logic
[
name
][
3
]
result_field_list
.
append
((
value
,
ocr_str
,
result
,
'{0}{1}'
.
format
(
applicant_type
,
comments
)))
if
not
is_find
:
result_field_list
=
[(
empty_str
,
empty_str
,
consts
.
RESULT_N
,
no_find_comment
)]
result_field_list
=
[(
empty_str
,
empty_str
,
consts
.
RESULT_N
,
'{0}{1}'
.
format
(
applicant_type
,
no_find_comment
)
)]
return
result_field_list
...
...
@@ -377,7 +393,7 @@ def rebuild_result(compare_result):
for
result_field_list
in
items_list
:
field_list
=
[]
for
input_str
,
ocr_str
,
result
,
comments
in
result_field_list
:
if
result
==
consts
.
RESULT_N
:
if
result
!=
consts
.
RESULT_Y
:
is_pass
=
False
field_list
.
append
(
{
...
...
src/prese/consts.py
View file @
f4a2c3c
...
...
@@ -112,6 +112,13 @@ HT_COMPARE_LOGIC = {
AFC_CON_FIELDS
[
9
]:
(
'ASP项目详情'
,
'se_asp_compare'
,
{},
'合同ASP名称或者金额与系统不一致'
),
}
ID_COMPARE_LOGIC
=
{
'customerName'
:
(
'姓名'
,
'se_name_compare'
,
{},
'身份证姓名与系统不一致'
),
'idNum'
:
(
'公民身份号码'
,
'se_common_compare'
,
{},
'身份证号码与系统不一致'
),
'idExpiryDate'
:
(
'有效期限'
,
'se_date_compare_pre'
,
{},
'身份证有效期疑似过期'
),
}
PRE_COMPARE_LOGIC_MAP
=
{
ID_EN
:
(
ID_OCR_FIELD
,
ID_COMPARE_LOGIC
,
'请确认是否提供身份证件'
),
MVI_EN
:
(
MVI_OCR_FIELD
,
MVI_COMPARE_LOGIC
,
'请确认是否提供发票'
),
...
...
@@ -125,4 +132,19 @@ PRE_COMPARE_LOGIC_MAP = {
RESULT_Y
=
'Y'
RESULT_N
=
'N'
RESULT_N1
=
'N1'
RESULT_N2
=
'N2'
ID_DATE_MAP
=
{
RESULT_N
:
'身份证有效期疑似过期'
,
RESULT_Y
:
'身份证有效期疑似过期'
,
RESULT_N1
:
'身份证有效期疑似过期'
,
RESULT_N2
:
'身份证即将过期,请尽快提交放款申请'
,
}
APPLICANT_TYPE_MAP
=
{
'CUSTR'
:
'Applicant'
,
'COAPP'
:
'Co Applicant'
,
'GAUTR1'
:
'guarantor1'
,
'GAUTR2'
:
'guarantor2'
,
}
...
...
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