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
1bd26cf0
authored
2021-03-24 19:31:04 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add result to db
1 parent
0347cfa5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
7 deletions
src/apps/doc/consts.py
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/consts.py
View file @
1bd26cf
...
...
@@ -1018,3 +1018,16 @@ BASE_XML_TEXT = """<?xml version="1.0" encoding="utf-8"?>
CDATA_TEXT
=
"""<![CDATA[<Exec xmlns="http://tempuri.org/"><strXMLParm><Request><Framework><UserName>SFCHINA
\
qqcout0</UserName><GUID>70d0efcb-3bc2-4018-ac4e-681c8f3131b6</GUID><DetailedTracingEnabled>False</DetailedTracingEnabled><ServiceName>AMSWebService</ServiceName><SupportsRedirection>true</SupportsRedirection><ServiceType>Service</ServiceType></Framework><Parms><InputXML type="string">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;InputXML&gt; &lt;Result&gt; {0} &lt;/Result&gt;&lt;AuthorizationData&gt;&lt;ServiceComponent&gt;OCR&lt;/ServiceComponent&gt;&lt;RoleId/&gt;&lt;CompanyId/&gt;&lt;/AuthorizationData&gt;&lt;/InputXML&gt;</InputXML></Parms></Request></strXMLParm></Exec>]]>"""
RESULT_MAPPING
=
{
MVI_CLASSIFY
:
'mvi_ocr'
,
IC_CLASSIFY
:
'ic_ocr'
,
RP_CLASSIFY
:
'rp_ocr'
,
BC_CLASSIFY
:
'bc_ocr'
,
BL_CLASSIFY
:
'bl_ocr'
,
UCI_CLASSIFY
:
'uci_ocr'
,
EEP_CLASSIFY
:
'eep_ocr'
,
DL_CLASSIFY
:
'dl_ocr'
,
PP_CLASSIFY
:
'pp_ocr'
,
MVC_CLASSIFY
:
'mvc_ocr'
,
VAT_CLASSIFY
:
'vat_ocr'
,
}
...
...
src/apps/doc/management/commands/ocr_process.py
View file @
1bd26cf
...
...
@@ -23,7 +23,7 @@ from apps.doc.ocr.edms import EDMS, rh
from
apps.doc.named_enum
import
KeywordsType
from
apps.doc.exceptions
import
EDMSException
,
OCR1Exception
,
OCR2Exception
,
OCR4Exception
from
apps.doc.ocr.wb
import
BSWorkbook
from
apps.doc.models
import
DocStatus
,
HILDoc
,
AFCDoc
,
Keywords
from
apps.doc.models
import
DocStatus
,
HILDoc
,
AFCDoc
,
Keywords
,
HILOCRResult
,
AFCOCRResult
from
celery_compare.tasks
import
compare
...
...
@@ -300,6 +300,9 @@ class Command(BaseCommand, LoggerMixin):
@staticmethod
def
license_rebuild
(
license_summary
):
ic_merge
=
False
rp_merge
=
False
for
classify
in
(
consts
.
IC_CLASSIFY
,
consts
.
MVI_CLASSIFY
):
license_list
=
license_summary
.
get
(
classify
)
...
...
@@ -314,19 +317,29 @@ class Command(BaseCommand, LoggerMixin):
rp_side1_list
=
[]
rp_side2_list
=
[]
for
license_dict
in
license_list
:
is_rp
=
license_dict
.
pop
(
'类别'
,
'0'
)
if
key
in
license_dict
:
if
license_dict
.
get
(
'类别'
)
==
'1'
:
if
is_rp
==
'1'
:
rp_side2_list
.
append
(
license_dict
)
ic_side2_list
.
append
(
license_dict
)
elif
license_dict
.
get
(
'类别'
)
==
'1'
:
elif
is_rp
==
'1'
:
rp_side1_list
.
append
(
license_dict
)
else
:
ic_side1_list
.
append
(
license_dict
)
ic_merge
=
len
(
ic_side1_list
)
==
len
(
ic_side2_list
)
==
1
rp_merge
=
len
(
rp_side1_list
)
==
len
(
rp_side2_list
)
==
1
ic_side1_list
.
extend
(
ic_side2_list
)
rp_side1_list
.
extend
(
rp_side2_list
)
license_summary
[
consts
.
RP_CLASSIFY
]
=
rp_side1_list
license_list
=
ic_side1_list
if
ic_side1_list
:
license_list
=
ic_side1_list
else
:
license_summary
.
pop
(
classify
,
None
)
if
rp_side1_list
:
license_summary
[
consts
.
RP_CLASSIFY
]
=
rp_side1_list
ic_side1_list
=
ic_side2_list
=
rp_side1_list
=
rp_side2_list
=
None
...
...
@@ -345,6 +358,8 @@ class Command(BaseCommand, LoggerMixin):
price
=
round
(
price_total
*
100
/
(
rate
+
100
),
2
)
license_dict
[
'不含税价(逻辑计算)'
]
=
price
return
ic_merge
,
rp_merge
def
parse_img_path
(
self
,
img_path
):
img_name
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
img_path
))
...
...
@@ -794,7 +809,7 @@ class Command(BaseCommand, LoggerMixin):
merged_bs_summary
=
self
.
rebuild_bs_summary
(
bs_summary
,
unknown_summary
)
del
unknown_summary
self
.
license_rebuild
(
license_summary
)
ic_merge
,
rp_merge
=
self
.
license_rebuild
(
license_summary
)
# self.bs_log.info('[task={0}] [bs_summary={1}]'.format(task_str, merged_bs_summary))
...
...
@@ -872,9 +887,35 @@ class Command(BaseCommand, LoggerMixin):
self
.
online_log
.
info
(
'{0} [process complete] [task={1}]'
.
format
(
self
.
log_base
,
task_str
))
os
.
remove
(
excel_path
)
finally
:
pass
# TODO 识别结果存一张表,方便跑报表
# 更新OCR累计识别结果表
result_class
=
HILOCRResult
if
business_type
==
consts
.
HIL_PREFIX
else
AFCOCRResult
res_obj
=
result_class
.
objects
.
filter
(
application_id
=
doc
.
application_id
)
.
first
()
if
res_obj
is
None
:
res_obj
=
result_class
()
for
classify
,
field
in
consts
.
RESULT_MAPPING
.
items
():
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
if
classify
==
consts
.
IC_CLASSIFY
and
ic_merge
:
new_res_list
=
list
()
new_res_list
.
append
(
license_list
[
0
]
.
update
(
license_list
[
1
]))
license_list
=
new_res_list
new_res_list
=
None
elif
classify
==
consts
.
RP_CLASSIFY
and
rp_merge
:
new_res_list
=
list
()
new_res_list
.
append
(
license_list
[
0
]
.
update
(
license_list
[
1
]))
license_list
=
new_res_list
new_res_list
=
None
old_res_str
=
getattr
(
res_obj
,
field
)
if
old_res_str
is
None
:
last_res_str
=
json
.
dumps
(
license_list
)
else
old_res_list
=
json
.
loads
(
old_res_str
)
old_res_list
.
extend
(
license_list
)
last_res_str
=
json
.
dumps
(
old_res_list
)
setattr
(
res_obj
,
field
,
last_res_str
)
res_obj
.
save
()
# 触发比对
# compare.apply_async((doc.application_id, business_type, None, ocr_res_id), queue='queue_compare')
...
...
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