|
@@ -16,6 +16,9 @@ class ParamProcess(object):
|
|
self.model_v1 = models.model_v1
|
|
self.model_v1 = models.model_v1
|
|
self.model_v2 = models.model_v2
|
|
self.model_v2 = models.model_v2
|
|
self.label_encoder = models.label_encoder
|
|
self.label_encoder = models.label_encoder
|
|
|
|
+ self.features_v1 = ["channel", "type", "title"]
|
|
|
|
+ self.features_v2 = ["channel", "out_user_id", "mode", "out_play_cnt", "out_like_cnt", "out_share_cnt", "title",
|
|
|
|
+ "lop", "duration"]
|
|
|
|
|
|
async def title_to_tags(self, features):
|
|
async def title_to_tags(self, features):
|
|
"""
|
|
"""
|
|
@@ -38,7 +41,6 @@ class ParamProcess(object):
|
|
features['tag2'] = None
|
|
features['tag2'] = None
|
|
features['tag3'] = None
|
|
features['tag3'] = None
|
|
df = pd.DataFrame([features])
|
|
df = pd.DataFrame([features])
|
|
- # print("data_frame", df.columns)
|
|
|
|
df = df.drop('title', axis=1)
|
|
df = df.drop('title', axis=1)
|
|
return df
|
|
return df
|
|
|
|
|
|
@@ -47,7 +49,7 @@ class ParamProcess(object):
|
|
预测
|
|
预测
|
|
:param version: 模型版本
|
|
:param version: 模型版本
|
|
:param features: 视频被 label_encoder 之后的features
|
|
:param features: 视频被 label_encoder 之后的features
|
|
- :return: score: 返回的分数
|
|
|
|
|
|
+ :return: data
|
|
"""
|
|
"""
|
|
match version:
|
|
match version:
|
|
case "v1":
|
|
case "v1":
|
|
@@ -67,7 +69,11 @@ class ParamProcess(object):
|
|
"benchmark": 0.06,
|
|
"benchmark": 0.06,
|
|
"is_good_video": 0
|
|
"is_good_video": 0
|
|
}
|
|
}
|
|
- return obj
|
|
|
|
|
|
+ return {
|
|
|
|
+ "code": 0,
|
|
|
|
+ "message": "success",
|
|
|
|
+ "data": obj
|
|
|
|
+ }
|
|
case "v2":
|
|
case "v2":
|
|
result = self.model_v2.predict(features)
|
|
result = self.model_v2.predict(features)
|
|
result = list(result)
|
|
result = list(result)
|
|
@@ -85,13 +91,17 @@ class ParamProcess(object):
|
|
"benchmark": 0.3,
|
|
"benchmark": 0.3,
|
|
"is_good_video": 0
|
|
"is_good_video": 0
|
|
}
|
|
}
|
|
- return obj
|
|
|
|
|
|
+ return {
|
|
|
|
+ "code": 0,
|
|
|
|
+ "message": "success",
|
|
|
|
+ "data": obj
|
|
|
|
+ }
|
|
|
|
|
|
async def process_label(self, params):
|
|
async def process_label(self, params):
|
|
"""
|
|
"""
|
|
处理类别 features 和 float features
|
|
处理类别 features 和 float features
|
|
:param params: 接收到的参数
|
|
:param params: 接收到的参数
|
|
- :return:
|
|
|
|
|
|
+ :return: 转化好的类别特征的 dataframe
|
|
"""
|
|
"""
|
|
version = params['version']
|
|
version = params['version']
|
|
features = params['features']
|
|
features = params['features']
|
|
@@ -124,6 +134,63 @@ class ParamProcess(object):
|
|
:param params:
|
|
:param params:
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
- version, features = await self.process_label(params)
|
|
|
|
- # print(version, features)
|
|
|
|
- return await self.predict_score(version, features)
|
|
|
|
|
|
+ # check params
|
|
|
|
+ v = params.get("version")
|
|
|
|
+ if v == "v1":
|
|
|
|
+ features = params.get("features")
|
|
|
|
+ if len(features) != 3:
|
|
|
|
+ return {
|
|
|
|
+ "code": 1,
|
|
|
|
+ "message": "参数错误,v1,features长度应该是 3,传参长度是{}".format(len(features)),
|
|
|
|
+ "data": None
|
|
|
|
+ }
|
|
|
|
+ for feature in self.features_v1:
|
|
|
|
+ if feature in features:
|
|
|
|
+ continue
|
|
|
|
+ else:
|
|
|
|
+ return {
|
|
|
|
+ "code": 1,
|
|
|
|
+ "message": "参数错误, 缺少参数{}".format(feature),
|
|
|
|
+ "data": None
|
|
|
|
+ }
|
|
|
|
+ if v == "v2":
|
|
|
|
+ features = params.get("features")
|
|
|
|
+ if len(features) != 9:
|
|
|
|
+ return {
|
|
|
|
+ "code": 1,
|
|
|
|
+ "message": "参数错误,v2,features长度应该是 9,传参长度是{}".format(len(features)),
|
|
|
|
+ "data": None
|
|
|
|
+ }
|
|
|
|
+ for feature in self.features_v2:
|
|
|
|
+ if feature in features:
|
|
|
|
+ continue
|
|
|
|
+ else:
|
|
|
|
+ return {
|
|
|
|
+ "code": 1,
|
|
|
|
+ "message": "参数错误, 缺少参数{}".format(feature),
|
|
|
|
+ "data": None
|
|
|
|
+ }
|
|
|
|
+ else:
|
|
|
|
+ return {
|
|
|
|
+ "code": 1,
|
|
|
|
+ "message": "参数错误,version 应该是 v1 or v2, 传参是{}".format(v),
|
|
|
|
+ "data": None
|
|
|
|
+ }
|
|
|
|
+ try:
|
|
|
|
+ version, features = await self.process_label(params)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return {
|
|
|
|
+ "code": 2,
|
|
|
|
+ "message": "系统错误,定位在 process_label, 报错内容是{}:".format(e),
|
|
|
|
+ "data": None
|
|
|
|
+ }
|
|
|
|
+ try:
|
|
|
|
+ res = await self.predict_score(version, features)
|
|
|
|
+ return res
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return {
|
|
|
|
+ "code": 2,
|
|
|
|
+ "message": "系统异常, 定位在 predict_score, 报错是{}:".format(e),
|
|
|
|
+ "data": None
|
|
|
|
+ }
|
|
|
|
+
|