|  | @@ -158,13 +158,13 @@ def predict_18_19(app_type):
 | 
	
		
			
				|  |  |      if app_type == config_.APP_TYPE['LAO_HAO_KAN_VIDEO']:
 | 
	
		
			
				|  |  |          sql = f"SELECT video_id FROM videoods.movie_store_video_allow_list " \
 | 
	
		
			
				|  |  |                f"WHERE allow_list_type=1 AND create_time>='{create_time}'"
 | 
	
		
			
				|  |  | -    elif app_type == config_.APP_TYPE['ZUI_JING_QI']:
 | 
	
		
			
				|  |  | -        sql = f"SELECT video_id FROM videoods.movie_store_video_allow_list " \
 | 
	
		
			
				|  |  | -              f"WHERE allow_list_type=0 AND " \
 | 
	
		
			
				|  |  | -              f"video_id NOT IN (" \
 | 
	
		
			
				|  |  | -              f"SELECT video_id FROM videoods.movie_store_video_allow_list WHERE allow_list_type=1" \
 | 
	
		
			
				|  |  | -              f") AND " \
 | 
	
		
			
				|  |  | -              f"create_time>='{create_time}'"
 | 
	
		
			
				|  |  | +    # elif app_type == config_.APP_TYPE['ZUI_JING_QI']:
 | 
	
		
			
				|  |  | +    #     sql = f"SELECT video_id FROM videoods.movie_store_video_allow_list " \
 | 
	
		
			
				|  |  | +    #           f"WHERE allow_list_type=0 AND " \
 | 
	
		
			
				|  |  | +    #           f"video_id NOT IN (" \
 | 
	
		
			
				|  |  | +    #           f"SELECT video_id FROM videoods.movie_store_video_allow_list WHERE allow_list_type=1" \
 | 
	
		
			
				|  |  | +    #           f") AND " \
 | 
	
		
			
				|  |  | +    #           f"create_time>='{create_time}'"
 | 
	
		
			
				|  |  |      else:
 | 
	
		
			
				|  |  |          sql = ""
 | 
	
		
			
				|  |  |      data_df = get_data_from_odps(project='videoods', sql=sql)
 | 
	
	
		
			
				|  | @@ -196,6 +196,58 @@ def predict_18_19(app_type):
 | 
	
		
			
				|  |  |          log_.info('data to redis finished!')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +def get_score_19(video_ids):
 | 
	
		
			
				|  |  | +    data = {}
 | 
	
		
			
				|  |  | +    step = round(100.0 / len(video_ids), 3)
 | 
	
		
			
				|  |  | +    for i, video_id in enumerate(video_ids):
 | 
	
		
			
				|  |  | +        score = 100 - i * step
 | 
	
		
			
				|  |  | +        data[video_id] = score
 | 
	
		
			
				|  |  | +    return data
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def predict_19(app_type):
 | 
	
		
			
				|  |  | +    log_.info(f'app_type = {app_type}')
 | 
	
		
			
				|  |  | +    now = datetime.datetime.now()
 | 
	
		
			
				|  |  | +    log_.info(f"now = {datetime.datetime.strftime(now, '%Y-%m-%d %H:%M:%S')}")
 | 
	
		
			
				|  |  | +    sql_create_time = datetime.datetime.strftime(now - datetime.timedelta(days=30), '%Y-%m-%d %H:%M:%S')
 | 
	
		
			
				|  |  | +    if sql_create_time < '2022-04-22 16:40:00':
 | 
	
		
			
				|  |  | +        sql_create_time = '2022-04-22 16:40:00'
 | 
	
		
			
				|  |  | +    sql = f"SELECT video_id, create_time FROM videoods.movie_store_video_allow_list " \
 | 
	
		
			
				|  |  | +          f"WHERE allow_list_type=0 AND " \
 | 
	
		
			
				|  |  | +          f"video_id NOT IN (" \
 | 
	
		
			
				|  |  | +          f"SELECT video_id FROM videoods.movie_store_video_allow_list WHERE allow_list_type=1" \
 | 
	
		
			
				|  |  | +          f") AND " \
 | 
	
		
			
				|  |  | +          f"create_time>='{sql_create_time}'" \
 | 
	
		
			
				|  |  | +          f"ORDER BY create_time DESC;"
 | 
	
		
			
				|  |  | +    data_df = get_data_from_odps(project='videoods', sql=sql)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if data_df is not None:
 | 
	
		
			
				|  |  | +        video_ids = [int(video_id) for video_id in data_df['video_id'].to_list()]
 | 
	
		
			
				|  |  | +        log_.info(f'video_ids count = {len(video_ids)}')
 | 
	
		
			
				|  |  | +        # 预测
 | 
	
		
			
				|  |  | +        video_score = get_score_19(video_ids=video_ids)
 | 
	
		
			
				|  |  | +        # 对视频状态进行过滤
 | 
	
		
			
				|  |  | +        filtered_videos = filter_video_status(list(video_ids))
 | 
	
		
			
				|  |  | +        log_.info('filter videos status finished, filtered_videos nums={}'.format(len(filtered_videos)))
 | 
	
		
			
				|  |  | +        if not filtered_videos:
 | 
	
		
			
				|  |  | +            log_.info('流量池中视频状态不符合分发')
 | 
	
		
			
				|  |  | +            return None
 | 
	
		
			
				|  |  | +        # 上传数据到redis
 | 
	
		
			
				|  |  | +        data = {}
 | 
	
		
			
				|  |  | +        for video_id in filtered_videos:
 | 
	
		
			
				|  |  | +            score = video_score[video_id]
 | 
	
		
			
				|  |  | +            data[video_id] = score
 | 
	
		
			
				|  |  | +        log_.info('predict finished!')
 | 
	
		
			
				|  |  | +        key_name = config_.FLOWPOOL_KEY_NAME_PREFIX + str(app_type)
 | 
	
		
			
				|  |  | +        redis_helper = RedisHelper()
 | 
	
		
			
				|  |  | +        # 如果key已存在,删除key
 | 
	
		
			
				|  |  | +        if redis_helper.key_exists(key_name):
 | 
	
		
			
				|  |  | +            redis_helper.del_keys(key_name)
 | 
	
		
			
				|  |  | +        # 写入redis
 | 
	
		
			
				|  |  | +        redis_helper.add_data_with_zset(key_name=key_name, data=data, expire_time=24 * 3600)
 | 
	
		
			
				|  |  | +        log_.info('data to redis finished!')
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  if __name__ == '__main__':
 | 
	
		
			
				|  |  |      # res = get_videos_from_pool(app_type=0)
 | 
	
		
			
				|  |  |      # res = get_videos_remain_view_count(app_type=0, videos_info=[('12345', '#2#1#111')])
 | 
	
	
		
			
				|  | @@ -205,8 +257,10 @@ if __name__ == '__main__':
 | 
	
		
			
				|  |  |      log_.info('flow pool predict start...')
 | 
	
		
			
				|  |  |      for app_name, app_type in config_.APP_TYPE.items():
 | 
	
		
			
				|  |  |          log_.info('{} predict start...'.format(app_name))
 | 
	
		
			
				|  |  | -        if app_type in app_type_list:
 | 
	
		
			
				|  |  | +        if app_type == config_.APP_TYPE['LAO_HAO_KAN_VIDEO']:
 | 
	
		
			
				|  |  |              predict_18_19(app_type=app_type)
 | 
	
		
			
				|  |  | +        elif app_type == config_.APP_TYPE['ZUI_JING_QI']:
 | 
	
		
			
				|  |  | +            predict_19(app_type=app_type)
 | 
	
		
			
				|  |  |          else:
 | 
	
		
			
				|  |  |              predict(app_type=app_type)
 | 
	
		
			
				|  |  |          log_.info('{} predict end...'.format(app_name))
 | 
	
	
		
			
				|  | @@ -214,10 +268,6 @@ if __name__ == '__main__':
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      # 将日志上传到oss
 | 
	
		
			
				|  |  |      # log_cmd = "ossutil cp -r -f {} oss://{}/{}".format(log_.logname, config_.BUCKET_NAME,
 | 
	
		
			
				|  |  |      #                                                    config_.OSS_FOLDER_LOGS + 'flow_pool/')
 |