|
@@ -39,29 +39,45 @@ def get_videos_from_flow_pool(app_type, size=1000):
|
|
|
return videos
|
|
|
|
|
|
|
|
|
-def get_videos_remain_view_count(app_type, videos_info):
|
|
|
+def get_videos_remain_view_count(app_type, video_info_list):
|
|
|
"""
|
|
|
- 获取视频在流量池中的剩余可分发数
|
|
|
+ 获取视频在流量池中的剩余可分发数,并存入对应的redis中
|
|
|
:param app_type: 产品标识 type-int
|
|
|
- :param videos_info: 视频信息 (视频id, 流量池标记) type-list,[(video_id, flow_pool), ...]
|
|
|
+ :param video_info_list: 视频信息 (视频id, 流量池标记) type-list,[(video_id, flow_pool), ...]
|
|
|
:return: data type-list,[(video_id, flow_pool, view_count), ...]
|
|
|
"""
|
|
|
- if not videos_info:
|
|
|
- return []
|
|
|
-
|
|
|
- videos = [{'videoId': info[0], 'flowPool': info[1]} for info in videos_info]
|
|
|
- request_data = {'appType': app_type, 'videos': videos}
|
|
|
- result = request_post(request_url=config_.GET_REMAIN_VIEW_COUNT_URL, request_data=request_data)
|
|
|
-
|
|
|
- if result is None:
|
|
|
- return []
|
|
|
-
|
|
|
- if result['code'] != 0:
|
|
|
- log_.info('获取视频在流量池中的剩余可分发数失败')
|
|
|
- return []
|
|
|
-
|
|
|
- data = [(item['videoId'], item['flowPool'], item['viewCount']) for item in result['data']]
|
|
|
- return data
|
|
|
+ redis_helper = RedisHelper()
|
|
|
+ if not video_info_list:
|
|
|
+ return
|
|
|
+
|
|
|
+
|
|
|
+ for i in range(len(video_info_list)//10 + 1):
|
|
|
+ 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}
|
|
|
+ result = request_post(request_url=config_.GET_REMAIN_VIEW_COUNT_URL,
|
|
|
+ request_data=request_data, timeout=(0.1, 3))
|
|
|
+ if result is None:
|
|
|
+ continue
|
|
|
+ if result['code'] != 0:
|
|
|
+ log_.error('获取视频在流量池中的剩余可分发数失败')
|
|
|
+ continue
|
|
|
+ for item in result['data']:
|
|
|
+ if item['distributeCount'] is None:
|
|
|
+ continue
|
|
|
+ distribute_count = int(item['distributeCount'])
|
|
|
+ if distribute_count > 0:
|
|
|
+
|
|
|
+ key_name = f"{config_.LOCAL_DISTRIBUTE_COUNT_PREFIX}{item['videoId']}:{item['flowPool']}"
|
|
|
+ redis_helper.setnx_key(key_name=key_name, value=distribute_count, expire_time=10 * 60)
|
|
|
+ else:
|
|
|
+
|
|
|
+ value = '{}-{}'.format(item['videoId'], item['flowPool'])
|
|
|
+ for type_name in config_.APP_TYPE:
|
|
|
+ flow_pool_key = f"{config_.FLOWPOOL_KEY_NAME_PREFIX}{config_.APP_TYPE.get(type_name)}"
|
|
|
+ redis_helper.remove_value_from_zset(key_name=flow_pool_key, value=value)
|
|
|
+ quick_flow_pool_key = f"{config_.QUICK_FLOWPOOL_KEY_NAME_PREFIX}{config_.APP_TYPE.get(item)}" \
|
|
|
+ f":{config_.QUICK_FLOW_POOL_ID}"
|
|
|
+ redis_helper.remove_value_from_zset(key_name=quick_flow_pool_key, value=value)
|
|
|
|
|
|
|
|
|
def get_flow_pool_recommend_config(flow_pool_id):
|
|
@@ -125,6 +141,7 @@ def predict(app_type):
|
|
|
|
|
|
redis_data = {}
|
|
|
quick_flow_pool_redis_data = {}
|
|
|
+ video_info_list = []
|
|
|
for i in range(len(video_score)):
|
|
|
video_id = filtered_videos[i]
|
|
|
score = video_score[i]
|
|
@@ -136,6 +153,9 @@ def predict(app_type):
|
|
|
quick_flow_pool_redis_data[value] = score
|
|
|
else:
|
|
|
redis_data[value] = score
|
|
|
+ video_info = (video_id, flow_pool)
|
|
|
+ if video_info not in video_info_list:
|
|
|
+ video_info_list.append(video_info)
|
|
|
|
|
|
|
|
|
redis_helper = RedisHelper()
|
|
@@ -165,6 +185,12 @@ def predict(app_type):
|
|
|
redis_helper.add_data_with_zset(key_name=flow_pool_key_name, data=redis_data, expire_time=24 * 3600)
|
|
|
|
|
|
log_.info('data to redis finished!')
|
|
|
+
|
|
|
+
|
|
|
+ get_videos_remain_view_count(app_type, video_info_list)
|
|
|
+
|
|
|
+ return video_info_list
|
|
|
+
|
|
|
except Exception as e:
|
|
|
log_.error('流量池更新失败, appType: {} exception: {}, traceback: {}'.format(
|
|
|
app_type, e, traceback.format_exc()))
|
|
@@ -297,12 +323,15 @@ if __name__ == '__main__':
|
|
|
for app_name, app_type in config_.APP_TYPE.items():
|
|
|
log_.info('{} predict start...'.format(app_name))
|
|
|
if app_type == config_.APP_TYPE['LAO_HAO_KAN_VIDEO']:
|
|
|
- predict_18_19(app_type=app_type)
|
|
|
+
|
|
|
+ continue
|
|
|
elif app_type == config_.APP_TYPE['ZUI_JING_QI']:
|
|
|
- predict_19(app_type=app_type)
|
|
|
+
|
|
|
+ continue
|
|
|
else:
|
|
|
predict(app_type=app_type)
|
|
|
log_.info('{} predict end...'.format(app_name))
|
|
|
+
|
|
|
log_.info('flow pool predict end...')
|
|
|
|
|
|
|