Commit 6c386050 by lzzzzl

识别数量列

parent 40f5d8ab
No preview for this file type
...@@ -43,6 +43,5 @@ def serve(): ...@@ -43,6 +43,5 @@ def serve():
if __name__ == '__main__': if __name__ == '__main__':
# serve() # serve()
data = read_from_excel('DZ0901_V1.4_BOM.xlsx', 'DZ0901_V1.3BOM清单') data = read_from_excel('DZ0901_V1.4_BOM.xlsx', 'DZ0901_V1.3BOM清单')
print(data)
print(Classify().fac_test_predic(data)) print(Classify().fac_test_predic(data))
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import re
from predict.base_handler import BasePredictor from predict.base_handler import BasePredictor
from utils.excel_manager import read_from_excel
order_list = ['序号'] RIGHT_LEVEL = 0.7
class LiPredict(BasePredictor): class LiPredict(BasePredictor):
def predict(self, key): def predict(self, key):
if len(key) > 0: # if len(key) > 0:
self.order_predict(key[0]) # self.order_predict(key[1])
for ix in key:
self.num_predict(key[ix])
pass pass
"""
序列预测
"""
def order_predict(self, data): def order_predict(self, data):
collect_num = [int(kw) for kw in data if isinstance(kw, float) or isinstance(kw, int)] collect_order = [int(kw) for kw in data if isinstance(kw, float) or isinstance(kw, int)]
judge = self.IsIncrease(collect_num, len(collect_num)) judge = self.isIncrease(collect_order, len(collect_order)) if len(collect_order) > 0 else False
print('judge: ' + str(judge)) print('judge: ' + str(judge))
return 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 IsIncrease(self, arr, size): def isIncrease(self, arr, size):
if size == 1: if size == 1:
return True 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
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import xlwt import pandas as pd
import xlrd
# 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): def read_from_excel(file_name, sheet_name):
wb = xlrd.open_workbook(file_name) data = pd.read_excel(file_name, sheet_name=sheet_name, keep_default_na=False, header=-1)
sheet = wb.sheet_by_name(sheet_name)
row = sheet.nrows
col = sheet.ncols
result_dict = {} result_dict = {}
for i in range(col): count = 0
col_list = [] for index in data.columns:
for j in range(row): col_list.append(sheet.cell_value(j, i)) result_dict[count] = data[index].tolist()
result_dict[i] = col_list count += 1
print(result_dict)
return result_dict return result_dict
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment