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
b300b5b7
authored
2020-10-30 15:55:04 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'feature/license' into feature/mssql
2 parents
14cd91c6
9f8a7658
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
16 deletions
src/apps/doc/management/commands/doc_ocr_process.py
src/apps/doc/models.py
src/apps/doc/ocr/wb.py
src/apps/doc/views.py
src/apps/doc/management/commands/doc_ocr_process.py
View file @
b300b5b
import
os
import
time
import
json
import
signal
import
asyncio
import
aiohttp
...
...
@@ -197,7 +198,7 @@ class Command(BaseCommand, LoggerMixin):
async
with
aiohttp
.
ClientSession
(
connector
=
aiohttp
.
TCPConnector
(
ssl
=
False
))
as
session
:
async
with
session
.
post
(
url
,
data
=
json_data
)
as
response
:
if
response
.
status
==
200
:
return
await
response
.
json
()
return
await
response
.
text
()
@staticmethod
async
def
fetch_bc_name_result
(
url
,
json_data
):
...
...
@@ -245,13 +246,15 @@ class Command(BaseCommand, LoggerMixin):
raise
Exception
(
'ocr 2 error, img_path={0}'
.
format
(
img_path
))
else
:
# 识别结果
ocr_res_2
=
json
.
loads
(
ocr_res_2
)
self
.
cronjob_log
.
info
(
'{0} [ocr_2 result] [img={1}] [res={2}]'
.
format
(
self
.
log_base
,
img_path
,
ocr_res_2
))
if
classify
==
consts
.
BC_CLASSIFY
:
name
=
'有'
json_data_1
[
'card_res'
]
=
ocr_res_2
card_name_res
=
await
self
.
fetch_bc_name_result
(
self
.
ocr_url_3
,
json_data_1
)
if
card_name_res
.
get
(
'code'
)
==
1
and
card_name_res
.
get
(
'data'
,
{})
.
get
(
'is_exists_name'
)
==
0
:
if
isinstance
(
card_name_res
,
dict
)
and
\
card_name_res
.
get
(
'data'
,
{})
.
get
(
'is_exists_name'
)
==
0
:
name
=
'无'
ocr_res_2
[
'Name'
]
=
name
self
.
license2_process
(
ocr_res_2
,
license_summary
,
pid
,
classify
,
skip_img
,
img_path
)
...
...
@@ -521,7 +524,6 @@ class Command(BaseCommand, LoggerMixin):
# EDMS异常:下载异常-->回队列-->邮件;上传异常-->重新上传队列-->邮件
# 算法异常:第一道异常-->识别失败-->邮件;第二道异常-->识别失败-->邮件
# TODO OCR接口调用重试
# TODO 数据库断联问题
def
handle
(
self
,
*
args
,
**
kwargs
):
sleep_second
=
int
(
conf
.
SLEEP_SECOND
)
max_sleep_second
=
int
(
conf
.
MAX_SLEEP_SECOND
)
...
...
src/apps/doc/models.py
View file @
b300b5b
...
...
@@ -24,6 +24,7 @@ class UploadDocRecords(models.Model):
class
Meta
:
managed
=
False
db_table
=
'upload_doc_records'
situ_db_label
=
'afc'
class
HILDoc
(
models
.
Model
):
...
...
src/apps/doc/ocr/wb.py
View file @
b300b5b
...
...
@@ -251,17 +251,9 @@ class BSWorkbook(Workbook):
)
return
metadata_rows
def
create_meta_sheet
(
self
,
card
):
if
self
.
worksheets
[
0
]
.
title
==
'Sheet'
:
ms
=
self
.
worksheets
[
0
]
ms
.
title
=
'{0}({1})'
.
format
(
self
.
meta_sheet_title
,
card
[
-
6
:])
else
:
ms
=
self
.
create_sheet
(
'{0}({1})'
.
format
(
self
.
meta_sheet_title
,
card
[
-
6
:]))
return
ms
def
build_meta_sheet
(
self
,
card
,
confidence
,
code
,
print_time
,
start_date
,
end_date
):
metadata_rows
=
self
.
build_metadata_rows
(
confidence
,
code
,
print_time
,
start_date
,
end_date
)
ms
=
self
.
create_
meta_sheet
(
card
)
ms
=
self
.
create_
sheet
(
'{0}({1})'
.
format
(
self
.
meta_sheet_title
,
card
[
-
6
:])
)
for
row
in
metadata_rows
:
ms
.
append
(
row
)
return
ms
...
...
@@ -517,7 +509,12 @@ class BSWorkbook(Workbook):
for
img_tuple
in
skip_img
:
ws
.
append
(
img_tuple
)
def
remove_base_sheet
(
self
):
if
len
(
self
.
sheetnames
)
>
1
:
self
.
remove
(
self
.
get_sheet_by_name
(
'Sheet'
))
def
rebuild
(
self
,
bs_summary
,
license_summary
,
skip_img
,
document_scheme
):
self
.
bs_rebuild
(
bs_summary
)
self
.
license_rebuild
(
license_summary
,
document_scheme
)
self
.
skip_img_sheet
(
skip_img
)
self
.
remove_base_sheet
()
...
...
src/apps/doc/views.py
View file @
b300b5b
...
...
@@ -88,10 +88,10 @@ priority_doc_args = {
class
UploadDocView
(
GenericView
,
DocHandler
):
permission_classes
=
[]
authentication_classes
=
[]
#
permission_classes = [IsAuthenticated]
#
authentication_classes = [OAuth2AuthenticationWithUser]
#
permission_classes = []
#
authentication_classes = []
permission_classes
=
[
IsAuthenticated
]
authentication_classes
=
[
OAuth2AuthenticationWithUser
]
# required_scopes = ['write']
# 上传(接收)文件接口
...
...
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