Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
bom_identify
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6c386050
authored
May 28, 2020
by
lzzzzl
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
识别数量列
parent
40f5d8ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
19 deletions
DZ0901_V1.4_BOM.xlsx
classify_server.py
predict/list_predict.py
utils/excel_manager.py
DZ0901_V1.4_BOM.xlsx
deleted
100644 → 0
View file @
40f5d8ab
No preview for this file type
classify_server.py
View file @
6c386050
...
...
@@ -43,6 +43,5 @@ def serve():
if
__name__
==
'__main__'
:
# serve()
data
=
read_from_excel
(
'DZ0901_V1.4_BOM.xlsx'
,
'DZ0901_V1.3BOM清单'
)
print
(
data
)
print
(
Classify
()
.
fac_test_predic
(
data
))
predict/list_predict.py
View file @
6c386050
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
re
from
predict.base_handler
import
BasePredictor
from
utils.excel_manager
import
read_from_excel
order_list
=
[
'序号'
]
RIGHT_LEVEL
=
0.7
class
LiPredict
(
BasePredictor
):
def
predict
(
self
,
key
):
if
len
(
key
)
>
0
:
self
.
order_predict
(
key
[
0
])
# if len(key) > 0:
# self.order_predict(key[1])
for
ix
in
key
:
self
.
num_predict
(
key
[
ix
])
pass
"""
序列预测
"""
def
order_predict
(
self
,
data
):
collect_
num
=
[
int
(
kw
)
for
kw
in
data
if
isinstance
(
kw
,
float
)
or
isinstance
(
kw
,
int
)]
judge
=
self
.
IsIncrease
(
collect_num
,
len
(
collect_num
))
collect_
order
=
[
int
(
kw
)
for
kw
in
data
if
isinstance
(
kw
,
float
)
or
isinstance
(
kw
,
int
)]
judge
=
self
.
isIncrease
(
collect_order
,
len
(
collect_order
))
if
len
(
collect_order
)
>
0
else
False
print
(
'judge: '
+
str
(
judge
))
return
judge
"""
数量预测
"""
def
num_predict
(
self
,
data
):
collect_num
=
[
kw
for
kw
in
data
if
isinstance
(
kw
,
int
)
or
self
.
isNumberCol
(
kw
)]
rate
=
round
(
len
(
collect_num
)
/
len
(
data
),
3
)
return
True
if
rate
>=
RIGHT_LEVEL
else
False
"""
判断列表元素是否递增
"""
def
I
sIncrease
(
self
,
arr
,
size
):
def
i
sIncrease
(
self
,
arr
,
size
):
if
size
==
1
:
return
True
return
(
arr
[
size
-
1
]
>=
arr
[
size
-
2
])
and
self
.
IsIncrease
(
arr
,
size
-
1
)
return
(
arr
[
size
-
1
]
>=
arr
[
size
-
2
])
and
self
.
isIncrease
(
arr
,
size
-
1
)
"""
判断是否数量列
"""
def
isNumberCol
(
self
,
kw
):
if
isinstance
(
kw
,
str
):
return
re
.
match
(
r'(\d+)((K)|([\u4E00-\u9FA5]{1,3}))$'
,
kw
,
re
.
M
|
re
.
I
)
else
:
return
False
utils/excel_manager.py
View file @
6c386050
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
xlwt
import
xlrd
import
pandas
as
pd
# def read_from_excel(file_name, sheet_name):
# wb = xlrd.open_workbook(file_name)
# sheet = wb.sheet_by_name(sheet_name)
# row = sheet.nrows
# col = sheet.ncols
# result_dict = {}
# for i in range(col):
# col_list = []
# for j in range(row): col_list.append(sheet.cell_value(j, i))
# result_dict[i] = col_list
# return result_dict
def
read_from_excel
(
file_name
,
sheet_name
):
wb
=
xlrd
.
open_workbook
(
file_name
)
sheet
=
wb
.
sheet_by_name
(
sheet_name
)
row
=
sheet
.
nrows
col
=
sheet
.
ncols
data
=
pd
.
read_excel
(
file_name
,
sheet_name
=
sheet_name
,
keep_default_na
=
False
,
header
=-
1
)
result_dict
=
{}
for
i
in
range
(
col
):
col_list
=
[]
for
j
in
range
(
row
):
col_list
.
append
(
sheet
.
cell_value
(
j
,
i
))
result_dict
[
i
]
=
col_list
count
=
0
for
index
in
data
.
columns
:
result_dict
[
count
]
=
data
[
index
]
.
tolist
()
count
+=
1
print
(
result_dict
)
return
result_dict
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment