Commit f716998b by lichenggang

有表头的预测

parent 273f2f67
...@@ -18,8 +18,9 @@ class Classify(classify_pb2_grpc.classifyServicer): ...@@ -18,8 +18,9 @@ class Classify(classify_pb2_grpc.classifyServicer):
def Classify(self, request, context): def Classify(self, request, context):
print('接收数据: ' + request.keyword) dic_data = json.loads(request.keyword)
res = self.predictorfac.predict(request.keyword) print(dic_data)
res = self.predictorfac.predict(dic_data)
return classify_pb2.ClassifyReply(message='result {msg}'.format(msg=res)) return classify_pb2.ClassifyReply(message='result {msg}'.format(msg=res))
def fac_test_predic(self, data): def fac_test_predic(self, data):
......
...@@ -4,7 +4,8 @@ from protobuf import classify_pb2_grpc ...@@ -4,7 +4,8 @@ from protobuf import classify_pb2_grpc
import pandas as pd import pandas as pd
import json import json
def get_test_data(): def get_test_data():
df=pd.read_excel(r'C:\Users\ICHUNT\Desktop\bomlist\DZ0901_V1.4_BOM.xlsx',header=None) df=pd.read_excel(r'C:\Users\ICHUNT\Desktop\bomlist\00 BSJ BMS合并-询价-珠海能源.xlsx', header=None)
print(df)
df.fillna(' ', inplace=True) df.fillna(' ', inplace=True)
dic_dft = df.to_dict(orient='list') dic_dft = df.to_dict(orient='list')
return json.dumps(dic_dft) return json.dumps(dic_dft)
......
...@@ -19,8 +19,7 @@ class PredictorFac(): ...@@ -19,8 +19,7 @@ class PredictorFac():
elif isinstance(data, dict): elif isinstance(data, dict):
return self.dict_predictor return self.dict_predictor
def predict(self, data): def predict(self, dic_data):
dic_data = json.loads(data)
predictor = self._get_predictor(dic_data) predictor = self._get_predictor(dic_data)
res = predictor.predict(dic_data) res = predictor.predict(dic_data)
return res return res
...@@ -40,5 +39,6 @@ if __name__ == "__main__": ...@@ -40,5 +39,6 @@ if __name__ == "__main__":
data = get_test_data() data = get_test_data()
p = PredictorFac(model_config) p = PredictorFac(model_config)
data = json.loads(data)
res = p.predict(data) res = p.predict(data)
print(res) print(res)
...@@ -4,17 +4,17 @@ from predict.base_handler import BasePredictor ...@@ -4,17 +4,17 @@ from predict.base_handler import BasePredictor
# 可能的头部字段 # 可能的头部字段
prob_fields = ["序号", "名称", "规格", "MPN", "用量(pcs)", "用量", "pcs", "位号", "描述", "值", "数量", "封装", "类别", "a面位置", "b面位置", "备注", prob_fields = ["序号", "名称", "规格", "MPN", "用量(pcs)", "用量", "pcs", "位号", "描述", "值", "数量", "封装", "类别", "a面位置", "b面位置", "备注",
"需求数量", "需求数量", "售价",
"参考品牌", "品牌", "item", "厂商编码", "品牌/厂商", "参考料号", "参考供应商", "top面", "bottom面"] "参考品牌", "品牌", "item", "厂商编码", "品牌/厂商", "参考料号", "参考供应商", "top面", "bottom面"]
# 标准名和代名词的映射 # 标准名和代名词的映射
fields_map = {"序号": ["序号"], fields_map = {"序号": ["序号"],
"类别": ["类别", "分类", "名称", "类别名称"], "类别": ["类别", "分类", "名称", "类别名称"],
"参数": ["参数", "规格", "描述"], "参数": ["参数", "规格", "描述"],
"型号": ["型号", "参考料号", "料号", "MPN"], "型号": ["型号", "参考料号", "料号", "MPN", "厂商编码"],
"数量": ["数量", "用量(pcs)", "PCS", "用量", "用量(PCS)", "pcs"], "数量": ["数量", "用量(pcs)", "PCS", "用量", "用量(PCS)", "pcs"],
"封装": ["封装", "封装规格"], "封装": ["封装", "封装规格"],
"品牌": ["品牌", "品牌/厂商", "参考品牌", "厂商编码", "参考供应商", "厂商", "参考供应商", "参考厂商"]} "品牌": ["品牌", "品牌/厂商", "参考品牌", "参考供应商", "厂商", "参考供应商", "参考厂商"]}
# #
order_list = ['序号'] order_list = ['序号']
...@@ -28,14 +28,17 @@ def fun(seri): ...@@ -28,14 +28,17 @@ def fun(seri):
# 取前多少行 # 取前多少行
HEAD_ROW = 5 HEAD_ROW = 7
# 空置率阈值
NAN_RATE = 0.8
class DicPredict(BasePredictor): class DicPredict(BasePredictor):
def id_by_field(self, df_head): def id_by_field(self, df_head):
""" """
:param df_head: 传入接收数据的头部Dataframe(默认5行) :param df_head: 传入接收数据的头部Dataframe(默认7行)
:return li_res: 返回结果列表 :return li_res: 返回结果列表
""" """
series = df_head.apply(fun) series = df_head.apply(fun)
...@@ -66,7 +69,7 @@ class DicPredict(BasePredictor): ...@@ -66,7 +69,7 @@ class DicPredict(BasePredictor):
for item in v: for item in v:
if not str(item).strip(): if not str(item).strip():
counter += 1 counter += 1
if counter / len(v) >= 0.8: if counter / len(v) >= NAN_RATE:
continue continue
columns.append(k) columns.append(k)
li_data.append(v) li_data.append(v)
......
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