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
e1cd63be
authored
2021-05-10 17:16:36 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add report part 2
1 parent
828d28c7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
259 additions
and
12 deletions
src/apps/doc/consts.py
src/apps/doc/models.py
src/apps/doc/named_enum.py
src/celery_compare/tasks.py
src/common/mssql_script2.py
src/common/tools/mssql_script3.py
src/apps/doc/consts.py
View file @
e1cd63b
...
...
@@ -1084,6 +1084,7 @@ ID_TYPE_COMPARE = {
}
ID_RES
=
'idNumResult'
SECOND_ID_FIELD
=
'secondIdNum'
SECOND_ID_RES
=
'secondIdNumResult'
SECOND_ITPRC
=
[
...
...
src/apps/doc/models.py
View file @
e1cd63b
...
...
@@ -312,15 +312,15 @@ class HILCompareReport(models.Model):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
case_number
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
request_team
=
models
.
SmallIntegerField
(
default
=
RequestTeam
.
ACCEPTANCE
.
value
,
verbose_name
=
"来源"
)
request_trigger
=
models
.
SmallIntegerField
(
default
=
RequestTrigger
.
POS
.
value
,
verbose_name
=
"触发者"
)
request_trigger
=
models
.
SmallIntegerField
(
default
=
RequestTrigger
.
SUBMITING
.
value
,
verbose_name
=
"触发者"
)
input_file
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"文件名"
,
null
=
True
)
transaction_start
=
models
.
DateTimeField
(
verbose_name
=
'开始时间'
)
# 索引
transaction_end
=
models
.
DateTimeField
(
verbose_name
=
'结束时间'
)
successful_at_this_level
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否成功"
)
failure_reason
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"失败原因"
)
process_name
=
models
.
SmallIntegerField
(
default
=
ProcessName
.
ALL
.
value
,
verbose_name
=
"流程名称"
)
process_name
=
models
.
SmallIntegerField
(
default
=
ProcessName
.
CACOMPARE
.
value
,
verbose_name
=
"流程名称"
)
total_fields
=
models
.
IntegerField
(
null
=
True
,
verbose_name
=
'比对字段数目'
)
workflow_name
=
models
.
SmallIntegerField
(
null
=
True
,
verbose_name
=
"工作流程"
)
workflow_name
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"工作流程"
,
null
=
True
)
class
Meta
:
managed
=
False
...
...
@@ -331,15 +331,16 @@ class AFCCompareReport(models.Model):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
case_number
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"申请id"
)
request_team
=
models
.
SmallIntegerField
(
default
=
RequestTeam
.
ACCEPTANCE
.
value
,
verbose_name
=
"来源"
)
request_trigger
=
models
.
SmallIntegerField
(
default
=
RequestTrigger
.
POS
.
value
,
verbose_name
=
"触发者"
)
request_trigger
=
models
.
SmallIntegerField
(
default
=
RequestTrigger
.
SUBMITING
.
value
,
verbose_name
=
"触发者"
)
input_file
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"文件名"
,
null
=
True
)
transaction_start
=
models
.
DateTimeField
(
verbose_name
=
'开始时间'
)
# 索引
transaction_end
=
models
.
DateTimeField
(
verbose_name
=
'结束时间'
)
successful_at_this_level
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否成功"
)
failure_reason
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"失败原因"
)
process_name
=
models
.
SmallIntegerField
(
default
=
ProcessName
.
ALL
.
value
,
verbose_name
=
"流程名称"
)
process_name
=
models
.
SmallIntegerField
(
default
=
ProcessName
.
CACOMPARE
.
value
,
verbose_name
=
"流程名称"
)
total_fields
=
models
.
IntegerField
(
null
=
True
,
verbose_name
=
'比对字段数目'
)
workflow_name
=
models
.
SmallIntegerField
(
null
=
True
,
verbose_name
=
"工作流程"
)
workflow_name
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"工作流程"
,
null
=
True
)
class
Meta
:
managed
=
False
...
...
@@ -352,13 +353,13 @@ class HILCompareOfflineReport(models.Model):
case_number
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"申请id"
)
request_team
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"来源"
)
request_trigger
=
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
"触发者"
)
input_file
=
models
.
CharField
(
max_length
=
2048
,
verbose_name
=
"文件名"
,
null
=
True
)
input_file
=
models
.
CharField
(
max_length
=
2048
,
verbose_name
=
"文件名"
)
transaction_start
=
models
.
DateTimeField
(
verbose_name
=
'开始时间'
)
# 索引
transaction_end
=
models
.
DateTimeField
(
verbose_name
=
'结束时间'
)
successful_at_this_level
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否成功"
)
failure_reason
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"失败原因"
)
process_name
=
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
"流程名称"
)
total_fields
=
models
.
IntegerField
(
verbose_name
=
'比对字段数目'
)
total_fields
=
models
.
IntegerField
(
verbose_name
=
'比对字段数目'
,
null
=
True
)
workflow_name
=
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
"工作流程"
)
class
Meta
:
...
...
@@ -371,13 +372,13 @@ class AFCCompareOfflineReport(models.Model):
case_number
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"申请id"
)
request_team
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"来源"
)
request_trigger
=
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
"触发者"
)
input_file
=
models
.
CharField
(
max_length
=
2048
,
verbose_name
=
"文件名"
,
null
=
True
)
input_file
=
models
.
CharField
(
max_length
=
2048
,
verbose_name
=
"文件名"
)
transaction_start
=
models
.
DateTimeField
(
verbose_name
=
'开始时间'
)
# 索引
transaction_end
=
models
.
DateTimeField
(
verbose_name
=
'结束时间'
)
successful_at_this_level
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否成功"
)
failure_reason
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"失败原因"
)
process_name
=
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
"流程名称"
)
total_fields
=
models
.
IntegerField
(
verbose_name
=
'比对字段数目'
)
total_fields
=
models
.
IntegerField
(
verbose_name
=
'比对字段数目'
,
null
=
True
)
workflow_name
=
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
"工作流程"
)
class
Meta
:
...
...
src/apps/doc/named_enum.py
View file @
e1cd63b
...
...
@@ -33,6 +33,8 @@ class RequestTrigger(NamedEnum):
EAPP
=
(
1
,
'EAPP'
)
ECONTRACT
=
(
2
,
'ECONTRACT'
)
DOCUPLOAD
=
(
3
,
'Document Upload'
)
SUBMITING
=
(
4
,
'Submiting'
)
UPLOADING
=
(
5
,
'Uploading'
)
class
FailureReason
(
NamedEnum
):
...
...
@@ -46,6 +48,7 @@ class ProcessName(NamedEnum):
BS
=
(
1
,
'S1_CA_BankStatementCalculation'
)
IDCARD
=
(
2
,
'F2_IDReport'
)
DDA
=
(
3
,
'CL_S1_DDAConsolidation'
)
CACOMPARE
=
(
4
,
'S1_CA_DocumentVerify'
)
class
WorkflowName
(
NamedEnum
):
...
...
src/celery_compare/tasks.py
View file @
e1cd63b
...
...
@@ -5,10 +5,11 @@ import traceback
from
datetime
import
datetime
,
timedelta
from
collections
import
OrderedDict
from
.
import
app
from
apps.doc.models
import
AFCOCRResult
,
HILOCRResult
,
AFCComparisonInfo
,
HILComparisonInfo
,
Configs
from
apps.doc.models
import
AFCOCRResult
,
HILOCRResult
,
AFCComparisonInfo
,
HILComparisonInfo
,
Configs
,
HILCompareReport
,
AFCCompareReport
from
apps.doc
import
consts
from
apps.doc.ocr.gcap
import
gcap
from
apps.doc.exceptions
import
GCAPException
from
apps.doc.named_enum
import
RequestTeam
,
RequestTrigger
,
ProcessName
from
common.tools.comparison
import
cp
compare_log
=
logging
.
getLogger
(
'compare'
)
...
...
@@ -173,6 +174,9 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
))
return
start_time
=
datetime
.
now
()
compare_failed
=
False
# 比对信息
try
:
comparison_res
=
OrderedDict
({
...
...
@@ -182,7 +186,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
'applicationEntity'
:
application_entity
,
'applicationVersion'
:
last_obj
.
application_version
,
'vehicleStatus'
:
last_obj
.
vehicle_status
,
'wholeResult'
:
'
Y
'
,
'wholeResult'
:
'
N
'
,
'wholeResultMessage'
:
''
,
'applicationLink'
:
r'//china.bmw.corp/WINFS/SF-CN-data/SF3-CN-S/SF3-CN-S-1-New Business/CA/OCR II test'
,
}
...
...
@@ -278,6 +282,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
comparison_res
[
'OCR_Input'
][
'wholeResult'
]
=
consts
.
RESULT_N
if
consts
.
RESULT_N
in
res_set
or
consts
.
RESULT_NA
in
res_set
else
consts
.
RESULT_Y
except
Exception
as
e
:
compare_failed
=
True
compare_log
.
error
(
'{0} [compare error] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[error={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
traceback
.
format_exc
()))
...
...
@@ -327,3 +332,99 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id):
ocr_res_id
,
res_text
))
compare_log
.
info
(
'{0} [task success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
finally
:
try
:
end_time
=
datetime
.
now
()
if
compare_failed
:
successful_at_this_level
=
False
failure_reason
=
'Compare process error'
total_fields
=
0
else
:
successful_at_this_level
=
True
if
comparison_res
[
'OCR_Input'
][
'wholeResult'
]
==
consts
.
RESULT_Y
else
False
field_failed
=
{
'individualCusInfo'
:
[],
'corporateCusInfo'
:
[],
'usedCarInfo'
:
[]
}
individual_list
=
comparison_res
.
get
(
'OCR_Input'
,
{})
.
get
(
'individualCusInfo'
,
[])
total_fields
=
len
(
individual_list
)
*
4
for
individual
in
individual_list
:
field_list
=
[]
if
not
successful_at_this_level
:
for
field_name
,
_
,
_
,
_
,
result_field
in
consts
.
ITPRC
:
if
individual
.
get
(
result_field
)
!=
consts
.
RESULT_Y
:
field_list
.
append
(
field_name
)
if
individual
.
get
(
'secondIdType'
)
in
consts
.
SECOND_ID_TYPE_COMPARE
:
total_fields
+=
1
if
not
successful_at_this_level
:
if
individual
.
get
(
consts
.
SECOND_ID_RES
)
!=
consts
.
RESULT_Y
:
field_list
.
append
(
consts
.
SECOND_ID_FIELD
)
if
individual
.
get
(
'customerType'
)
==
consts
.
CUSTOMER_TYPE
[
5
]:
total_fields
+=
3
if
not
successful_at_this_level
:
for
field_name
,
_
,
_
,
_
,
result_field
in
consts
.
TCSEP
:
if
individual
.
get
(
result_field
)
!=
consts
.
RESULT_Y
:
field_list
.
append
(
field_name
)
if
len
(
field_list
)
>
0
:
field_failed
[
'individualCusInfo'
]
.
append
(
';'
.
join
(
field_list
))
corporate_res
=
comparison_res
.
get
(
'OCR_Input'
,
{})
.
get
(
'corporateCusInfo'
)
if
corporate_res
is
not
None
:
total_fields
+=
8
if
not
successful_at_this_level
:
corporate_field_list
=
[]
for
field_name
,
_
,
_
,
_
,
result_field
in
consts
.
TCCOR
:
if
corporate_res
.
get
(
result_field
)
!=
consts
.
RESULT_Y
:
corporate_field_list
.
append
(
field_name
)
if
len
(
corporate_field_list
)
>
0
:
field_failed
[
'corporateCusInfo'
]
.
append
(
';'
.
join
(
corporate_field_list
))
used_car_res
=
comparison_res
.
get
(
'OCR_Input'
,
{})
.
get
(
'usedCarInfo'
)
if
used_car_res
is
not
None
:
total_fields
+=
3
if
not
successful_at_this_level
:
used_car_field_list
=
[]
for
field_name
,
_
,
_
,
_
,
result_field
in
consts
.
PCUSD_MVC
:
if
used_car_res
.
get
(
result_field
)
!=
consts
.
RESULT_Y
:
used_car_field_list
.
append
(
field_name
)
if
len
(
used_car_field_list
)
>
0
:
field_failed
[
'usedCarInfo'
]
.
append
(
';'
.
join
(
used_car_field_list
))
if
successful_at_this_level
:
reason_list
=
[]
for
key
,
value
in
field_failed
.
items
():
if
len
(
value
)
>
0
:
value_str
=
json
.
dumps
(
value
)
reason_list
.
append
(
'{0}: {1}'
.
format
(
key
,
value_str
))
failure_reason
=
'、'
.
join
(
reason_list
)
else
:
failure_reason
=
''
request_trigger
=
RequestTrigger
.
SUBMITING
.
value
if
ocr_res_id
is
None
else
RequestTrigger
.
UPLOADING
.
value
report_class
=
HILCompareReport
if
application_entity
==
consts
.
HIL_PREFIX
else
AFCCompareReport
report_class
.
objects
.
create
(
case_number
=
application_id
,
request_team
=
RequestTeam
.
ACCEPTANCE
.
value
,
request_trigger
=
request_trigger
,
transaction_start
=
start_time
,
transaction_end
=
end_time
,
successful_at_this_level
=
successful_at_this_level
,
failure_reason
=
failure_reason
,
process_name
=
ProcessName
.
CACOMPARE
.
value
,
total_fields
=
total_fields
,
workflow_name
=
last_obj
.
customer_type
,
)
compare_log
.
info
(
'{0} [report save success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
))
except
Exception
as
e
:
compare_log
.
error
(
'{0} [report save success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] '
'[error={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
uniq_seq
,
ocr_res_id
,
traceback
.
format_exc
()))
...
...
src/common/mssql_script2.py
0 → 100644
View file @
e1cd63b
import
pyodbc
hil_sql
=
"""
"""
afc_sql
=
"""
"""
hil_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
hil_cursor
=
hil_cnxn
.
cursor
()
hil_cursor
.
execute
(
hil_sql
)
hil_cursor
.
close
()
hil_cnxn
.
close
()
afc_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
afc_cursor
=
afc_cnxn
.
cursor
()
afc_cursor
.
execute
(
afc_sql
)
afc_cursor
.
close
()
afc_cnxn
.
close
()
src/common/tools/mssql_script3.py
View file @
e1cd63b
import
pyodbc
hil_sql
=
"""
create table hil_ocr_report
(
id int identity
primary key,
case_number nvarchar(64) not null,
request_team tinyint default 0 not null,
request_trigger tinyint default 0 not null,
input_file nvarchar(255) not null,
transaction_start datetime not null,
transaction_end datetime not null,
successful_at_this_level bit default 0 not null,
failure_reason tinyint,
process_name tinyint default 0 not null,
total_fields smallint,
workflow_name tinyint
);
create index hil_ocr_report_transaction_start_index
on hil_ocr_report (transaction_start);
create table hil_compare_report
(
id int identity
primary key,
case_number nvarchar(64) not null,
request_team tinyint default 0 not null,
request_trigger tinyint default 4 not null,
input_file nvarchar(255),
transaction_start datetime not null,
transaction_end datetime not null,
successful_at_this_level bit default 0 not null,
failure_reason nvarchar(max),
process_name tinyint default 4 not null,
total_fields smallint,
workflow_name nvarchar(255)
);
create hil_compare_report_transaction_start_index
on hil_compare_report (transaction_start);
create table hil_compare_offline_report
(
id int identity
primary key,
case_number nvarchar(255) not null,
request_team nvarchar(255) not null,
request_trigger nvarchar(1024) not null,
input_file nvarchar(2048) not null,
transaction_start datetime not null,
transaction_end datetime not null,
successful_at_this_level bit default 0 not null,
failure_reason nvarchar(max),
process_name nvarchar(1024) not null,
total_fields smallint,
workflow_name nvarchar(1024) not null,
);
create index hil_compare_offline_report_transaction_start_index
on hil_compare_offline_report (transaction_start);
"""
afc_sql
=
"""
create table afc_ocr_report
(
id int identity
primary key,
case_number nvarchar(64) not null,
request_team tinyint default 0 not null,
request_trigger tinyint default 0 not null,
input_file nvarchar(255) not null,
transaction_start datetime not null,
transaction_end datetime not null,
successful_at_this_level bit default 0 not null,
failure_reason tinyint,
process_name tinyint default 0 not null,
total_fields smallint,
workflow_name tinyint
);
create index afc_ocr_report_transaction_start_index
on afc_ocr_report (transaction_start);
create table afc_compare_report
(
id int identity
primary key,
case_number nvarchar(64) not null,
request_team tinyint default 0 not null,
request_trigger tinyint default 4 not null,
input_file nvarchar(255),
transaction_start datetime not null,
transaction_end datetime not null,
successful_at_this_level bit default 0 not null,
failure_reason nvarchar(max),
process_name tinyint default 4 not null,
total_fields smallint,
workflow_name nvarchar(255)
);
create index afc_compare_report_transaction_start_index
on afc_compare_report (transaction_start);
create table afc_compare_offline_report
(
id int identity
primary key,
case_number nvarchar(255) not null,
request_team nvarchar(255) not null,
request_trigger nvarchar(1024) not null,
input_file nvarchar(2048) not null,
transaction_start datetime not null,
transaction_end datetime not null,
successful_at_this_level bit default 0 not null,
failure_reason nvarchar(max),
process_name nvarchar(1024) not null,
total_fields smallint,
workflow_name nvarchar(1024) not null,
);
create index afc_compare_offline_report_transaction_start_index
on afc_compare_offline_report (transaction_start);
"""
hil_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
...
...
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