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
c001972a
authored
2021-01-19 10:52:40 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix log
1 parent
306566d4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
3 deletions
src/apps/doc/management/commands/doc_ocr_process.py
src/apps/doc/management/commands/idcard_statistics.py
src/apps/doc/management/commands/ocr_process.py
src/apps/doc/management/commands/doc_ocr_process.py
deleted
100644 → 0
View file @
306566d
This diff is collapsed.
Click to expand it.
src/apps/doc/management/commands/idcard_statistics.py
0 → 100644
View file @
c001972
import
re
import
os
import
ast
import
datetime
from
openpyxl
import
Workbook
from
django.core.management
import
BaseCommand
from
settings
import
conf
from
common.mixins
import
LoggerMixin
from
apps.doc.models
import
HILDoc
,
AFCDoc
from
apps.doc
import
consts
class
Command
(
BaseCommand
,
LoggerMixin
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
sheet_names
=
(
'AFC'
,
'HIL'
)
self
.
header
=
(
'申请号'
,
'身份证号'
,
'民族'
,
'时间戳'
)
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--date'
,
default
=
datetime
.
date
.
today
()
-
datetime
.
timedelta
(
days
=
1
),
dest
=
'date'
,
help
=
'将要计算的日期,格式: 2018-01-01'
)
def
handle
(
self
,
*
args
,
**
kwargs
):
date
=
kwargs
.
get
(
'date'
)
if
isinstance
(
date
,
str
):
if
not
re
.
match
(
r'\d{4}-\d{2}-\d{2}'
,
date
):
print
(
'date format error'
)
return
date_str
=
date
else
:
date_str
=
date
.
strftime
(
'
%
Y-
%
m-
%
d'
)
excel_dir
=
os
.
path
.
join
(
conf
.
DATA_DIR
,
'AFC'
,
'Logs'
)
if
not
os
.
path
.
exists
(
excel_dir
):
print
(
'excel dir not exists'
)
return
excel_path
=
os
.
path
.
join
(
excel_dir
,
'idcard_{0}.xlsx'
.
format
(
date_str
))
log_path
=
os
.
path
.
join
(
conf
.
LOG_DIR
,
'idcard.log.{0}'
.
format
(
date_str
))
if
not
os
.
path
.
exists
(
log_path
):
print
(
'log_path not exists'
)
return
wb
=
Workbook
()
for
name
in
self
.
sheet_names
:
ws
=
wb
.
create_sheet
(
name
)
ws
.
append
(
self
.
header
)
wb
.
remove
(
wb
.
get_sheet_by_name
(
'Sheet'
))
with
open
(
log_path
,
'r'
,
encoding
=
'utf-8'
)
as
fp
:
for
line
in
fp
:
search_obj
=
re
.
search
(
r'[(.*)] [task=(.*)] [idcard=(.*)]'
,
line
)
task_str
=
search_obj
.
group
(
1
)
license_summary
=
ast
.
literal_eval
(
search_obj
.
group
(
2
))
business_type
,
doc_id_str
=
task_str
.
split
(
consts
.
SPLIT_STR
)
doc_id
=
int
(
doc_id_str
)
doc_class
=
HILDoc
if
business_type
==
consts
.
HIL_PREFIX
else
AFCDoc
application_id
=
doc_class
.
objects
.
filter
(
id
=
doc_id
)
.
values_list
(
'application_id'
,
flat
=
True
)
for
classify
,
(
_
,
name
,
field_order
,
side_diff
,
_
,
_
)
in
consts
.
LICENSE_ORDER
:
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
ws
=
wb
.
get_sheet_by_name
(
name
)
for
license_dict
in
license_list
:
if
classify
==
consts
.
IC_CLASSIFY
and
license_dict
.
get
(
'类别'
)
==
'1'
:
# 居住证处理
license_summary
.
setdefault
(
consts
.
RP_CLASSIFY
,
[])
.
append
(
license_dict
)
continue
if
side_diff
:
key
,
field_order_yes
,
field_order_no
=
consts
.
FIELD_ORDER_MAP
.
get
(
classify
)
field_order
=
field_order_yes
if
key
in
license_dict
else
field_order_no
all_value
=
[]
for
search_field
,
write_field
in
field_order
:
if
write_field
is
None
:
continue
field_value
=
license_dict
.
get
(
search_field
,
''
)
if
isinstance
(
field_value
,
list
):
all_value
.
append
(
'
\n
'
.
join
(
field_value
))
else
:
all_value
.
append
(
field_value
)
ws
.
append
((
application_id
[
0
],
*
all_value
))
wb
.
save
(
excel_path
)
src/apps/doc/management/commands/ocr_process.py
View file @
c001972
...
...
@@ -641,14 +641,14 @@ class Command(BaseCommand, LoggerMixin):
'[license_summary={4}]'
.
format
(
self
.
log_base
,
task_str
,
bs_summary
,
unknown_summary
,
license_summary
))
self
.
license_log
.
info
(
'[
license_summary={0}]'
.
format
(
license_summary
))
self
.
license_log
.
info
(
'[
task={0}] [license_summary={1}]'
.
format
(
task_str
,
license_summary
))
idcard_list
=
license_summary
.
get
(
consts
.
IC_CLASSIFY
)
if
idcard_list
:
self
.
idcard_log
.
info
(
'[
idcard={0}]'
.
format
(
idcard_list
))
self
.
idcard_log
.
info
(
'[
task={0}] [idcard={1}]'
.
format
(
task_str
,
idcard_list
))
merged_bs_summary
=
self
.
rebuild_bs_summary
(
bs_summary
,
unknown_summary
)
self
.
bs_log
.
info
(
'[
bs_summary={0}]'
.
format
(
merged_bs_summary
))
self
.
bs_log
.
info
(
'[
task={0}] [bs_summary={1}]'
.
format
(
task_str
,
merged_bs_summary
))
self
.
cronjob_log
.
info
(
'{0} [task={1}] [merged_bs_summary={2}] [unknown_summary={3}] '
'[res_list={4}]'
.
format
(
self
.
log_base
,
task_str
,
merged_bs_summary
,
...
...
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