|
@@ -39,7 +39,7 @@ def get_videos_from_flow_pool(app_type, size=1000):
|
|
return videos
|
|
return videos
|
|
|
|
|
|
|
|
|
|
-def get_videos_remain_view_count(app_type, video_info_list):
|
|
|
|
|
|
+def get_videos_remain_view_count(video_info_list):
|
|
"""
|
|
"""
|
|
获取视频在流量池中的剩余可分发数,并存入对应的redis中
|
|
获取视频在流量池中的剩余可分发数,并存入对应的redis中
|
|
:param app_type: 产品标识 type-int
|
|
:param app_type: 产品标识 type-int
|
|
@@ -52,10 +52,12 @@ def get_videos_remain_view_count(app_type, video_info_list):
|
|
|
|
|
|
# 每次请求10个
|
|
# 每次请求10个
|
|
for i in range(len(video_info_list)//10 + 1):
|
|
for i in range(len(video_info_list)//10 + 1):
|
|
|
|
+ remain_st_time = time.time()
|
|
videos = [{'videoId': info[0], 'flowPool': info[1]} for info in video_info_list[i*10:(i+1)*10]]
|
|
videos = [{'videoId': info[0], 'flowPool': info[1]} for info in video_info_list[i*10:(i+1)*10]]
|
|
- request_data = {'appType': app_type, 'videos': videos}
|
|
|
|
|
|
+ request_data = {'videos': videos}
|
|
result = request_post(request_url=config_.GET_REMAIN_VIEW_COUNT_URL,
|
|
result = request_post(request_url=config_.GET_REMAIN_VIEW_COUNT_URL,
|
|
request_data=request_data, timeout=(0.1, 3))
|
|
request_data=request_data, timeout=(0.1, 3))
|
|
|
|
+ log_.info(f"i = {i}, expend time = {(time.time()-remain_st_time)*1000}")
|
|
if result is None:
|
|
if result is None:
|
|
continue
|
|
continue
|
|
if result['code'] != 0:
|
|
if result['code'] != 0:
|
|
@@ -102,7 +104,7 @@ def get_score(video_ids):
|
|
return [random.uniform(0, 100) for _ in range(len(video_ids))]
|
|
return [random.uniform(0, 100) for _ in range(len(video_ids))]
|
|
|
|
|
|
|
|
|
|
-def predict(app_type):
|
|
|
|
|
|
+def predict(app_type, video_info_list):
|
|
"""
|
|
"""
|
|
对流量池视频排序,并将结果上传Redis
|
|
对流量池视频排序,并将结果上传Redis
|
|
:param app_type: 产品标识 type-int
|
|
:param app_type: 产品标识 type-int
|
|
@@ -113,7 +115,7 @@ def predict(app_type):
|
|
videos = get_videos_from_flow_pool(app_type=app_type)
|
|
videos = get_videos_from_flow_pool(app_type=app_type)
|
|
if len(videos) <= 0:
|
|
if len(videos) <= 0:
|
|
log_.info('流量池中无需分发的视频')
|
|
log_.info('流量池中无需分发的视频')
|
|
- return None
|
|
|
|
|
|
+ return video_info_list
|
|
# video_id 与 flow_pool 进行mapping
|
|
# video_id 与 flow_pool 进行mapping
|
|
video_ids = set()
|
|
video_ids = set()
|
|
log_.info('流量池中视频数:{}'.format(len(videos)))
|
|
log_.info('流量池中视频数:{}'.format(len(videos)))
|
|
@@ -134,14 +136,13 @@ def predict(app_type):
|
|
log_.info('filter videos status finished, filtered_videos nums={}'.format(len(filtered_videos)))
|
|
log_.info('filter videos status finished, filtered_videos nums={}'.format(len(filtered_videos)))
|
|
if not filtered_videos:
|
|
if not filtered_videos:
|
|
log_.info('流量池中视频状态不符合分发')
|
|
log_.info('流量池中视频状态不符合分发')
|
|
- return None
|
|
|
|
|
|
+ return video_info_list
|
|
# 预测
|
|
# 预测
|
|
video_score = get_score(filtered_videos)
|
|
video_score = get_score(filtered_videos)
|
|
log_.info('predict finished!')
|
|
log_.info('predict finished!')
|
|
# 上传数据到redis
|
|
# 上传数据到redis
|
|
redis_data = {}
|
|
redis_data = {}
|
|
quick_flow_pool_redis_data = {}
|
|
quick_flow_pool_redis_data = {}
|
|
- video_info_list = []
|
|
|
|
for i in range(len(video_score)):
|
|
for i in range(len(video_score)):
|
|
video_id = filtered_videos[i]
|
|
video_id = filtered_videos[i]
|
|
score = video_score[i]
|
|
score = video_score[i]
|
|
@@ -186,9 +187,6 @@ def predict(app_type):
|
|
|
|
|
|
log_.info('data to redis finished!')
|
|
log_.info('data to redis finished!')
|
|
|
|
|
|
- # 更新剩余分发数
|
|
|
|
- get_videos_remain_view_count(app_type, video_info_list)
|
|
|
|
-
|
|
|
|
return video_info_list
|
|
return video_info_list
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -199,6 +197,8 @@ def predict(app_type):
|
|
key_word=config_.FEISHU_ROBOT['server_robot'].get('key_word'),
|
|
key_word=config_.FEISHU_ROBOT['server_robot'].get('key_word'),
|
|
msg_text='rov-offline{} - 流量池更新失败, appType: {}, exception: {}'.format(config_.ENV_TEXT, app_type, e)
|
|
msg_text='rov-offline{} - 流量池更新失败, appType: {}, exception: {}'.format(config_.ENV_TEXT, app_type, e)
|
|
)
|
|
)
|
|
|
|
+ return video_info_list
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
def get_data_from_odps(project, sql):
|
|
def get_data_from_odps(project, sql):
|
|
@@ -320,6 +320,7 @@ def predict_19(app_type):
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
app_type_list = [config_.APP_TYPE['LAO_HAO_KAN_VIDEO'], config_.APP_TYPE['ZUI_JING_QI']]
|
|
app_type_list = [config_.APP_TYPE['LAO_HAO_KAN_VIDEO'], config_.APP_TYPE['ZUI_JING_QI']]
|
|
log_.info('flow pool predict start...')
|
|
log_.info('flow pool predict start...')
|
|
|
|
+ video_info_list = []
|
|
for app_name, app_type in config_.APP_TYPE.items():
|
|
for app_name, app_type in config_.APP_TYPE.items():
|
|
log_.info('{} predict start...'.format(app_name))
|
|
log_.info('{} predict start...'.format(app_name))
|
|
if app_type == config_.APP_TYPE['LAO_HAO_KAN_VIDEO']:
|
|
if app_type == config_.APP_TYPE['LAO_HAO_KAN_VIDEO']:
|
|
@@ -329,9 +330,14 @@ if __name__ == '__main__':
|
|
# predict_19(app_type=app_type)
|
|
# predict_19(app_type=app_type)
|
|
continue
|
|
continue
|
|
else:
|
|
else:
|
|
- predict(app_type=app_type)
|
|
|
|
|
|
+ video_info_list = predict(app_type=app_type, video_info_list=video_info_list)
|
|
log_.info('{} predict end...'.format(app_name))
|
|
log_.info('{} predict end...'.format(app_name))
|
|
|
|
|
|
|
|
+ # 更新剩余分发数
|
|
|
|
+ log_.info(f"video_info_list count = {len(video_info_list)}")
|
|
|
|
+ st_time = time.time()
|
|
|
|
+ get_videos_remain_view_count(video_info_list)
|
|
|
|
+ log_.info(f"expend time = {(time.time() - st_time) * 1000}")
|
|
log_.info('flow pool predict end...')
|
|
log_.info('flow pool predict end...')
|
|
|
|
|
|
|
|
|