|
@@ -94,12 +94,13 @@ def cal_score(df):
|
|
|
return df
|
|
|
|
|
|
|
|
|
-def video_rank(df, now_date, now_h):
|
|
|
+def video_rank(df, now_date, now_h, return_count):
|
|
|
"""
|
|
|
获取符合进入召回源条件的视频,与每日更新的rov模型结果视频列表进行合并
|
|
|
:param df:
|
|
|
:param now_date:
|
|
|
:param now_h:
|
|
|
+ :param return_count: 小时级数据回流限制数
|
|
|
:return:
|
|
|
"""
|
|
|
# 获取rov模型结果
|
|
@@ -109,7 +110,7 @@ def video_rank(df, now_date, now_h):
|
|
|
log_.info(f'initial data count = {len(initial_data)}')
|
|
|
|
|
|
# 获取符合进入召回源条件的视频,进入条件:小时级回流>=20 && score>=0.005
|
|
|
- h_recall_df = df[(df['lastonehour_return'] >= 20) & (df['score'] >= 0.005)]
|
|
|
+ h_recall_df = df[(df['lastonehour_return'] >= return_count) & (df['score'] >= 0.005)]
|
|
|
h_recall_videos = h_recall_df['videoid'].to_list()
|
|
|
log_.info(f'h_recall videos count = {len(h_recall_videos)}')
|
|
|
# 写入对应的redis
|
|
@@ -119,10 +120,11 @@ def video_rank(df, now_date, now_h):
|
|
|
score = h_recall_df[h_recall_df['videoid'] == video_id]['score']
|
|
|
h_recall_result[int(video_id)] = float(score)
|
|
|
h_video_ids.append(int(video_id))
|
|
|
- h_recall_key_name = f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{datetime.datetime.strftime(now_date, '%Y%m%d')}.{now_h}"
|
|
|
+ h_recall_key_name = \
|
|
|
+ f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{return_count}.{datetime.datetime.strftime(now_date, '%Y%m%d')}.{now_h}"
|
|
|
redis_helper.add_data_with_zset(key_name=h_recall_key_name, data=h_recall_result, expire_time=24 * 3600)
|
|
|
# 清空线上过滤应用列表
|
|
|
- redis_helper.del_keys(key_name=config_.H_VIDEO_FILER)
|
|
|
+ redis_helper.del_keys(key_name=f"{config_.H_VIDEO_FILER}{return_count}")
|
|
|
|
|
|
# 去重更新rov模型结果,并另存为redis中
|
|
|
initial_data_dup = {}
|
|
@@ -130,7 +132,7 @@ def video_rank(df, now_date, now_h):
|
|
|
if int(video_id) not in h_video_ids:
|
|
|
initial_data_dup[int(video_id)] = score
|
|
|
log_.info(f"initial data dup count = {len(initial_data_dup)}")
|
|
|
- initial_key_name = f"{config_.RECALL_KEY_NAME_PREFIX_DUP_H}{datetime.datetime.strftime(now_date, '%Y%m%d')}.{now_h}"
|
|
|
+ initial_key_name = f"{config_.RECALL_KEY_NAME_PREFIX_DUP_H}{return_count}.{datetime.datetime.strftime(now_date, '%Y%m%d')}.{now_h}"
|
|
|
redis_helper.add_data_with_zset(key_name=initial_key_name, data=initial_data_dup, expire_time=24 * 3600)
|
|
|
|
|
|
|
|
@@ -151,20 +153,23 @@ def video_rank(df, now_date, now_h):
|
|
|
# redis_helper.add_data_with_zset(key_name=final_key_name, data=final_data, expire_time=24 * 3600)
|
|
|
|
|
|
|
|
|
-def rank_by_h(now_date, now_h):
|
|
|
+def rank_by_h(now_date, now_h, return_count_list):
|
|
|
# 获取特征数据
|
|
|
feature_df = get_feature_data(now_date=now_date)
|
|
|
# 计算score
|
|
|
score_df = cal_score(df=feature_df)
|
|
|
# rank
|
|
|
- video_rank(df=score_df, now_date=now_date, now_h=now_h)
|
|
|
+ for cnt in return_count_list:
|
|
|
+ log_.info(f"return_count = {cnt}")
|
|
|
+ video_rank(df=score_df, now_date=now_date, now_h=now_h, return_count=cnt)
|
|
|
# to-csv
|
|
|
score_filename = f"score_{datetime.datetime.strftime(now_date, '%Y%m%d%H')}.csv"
|
|
|
score_df.to_csv(f'./data/{score_filename}')
|
|
|
|
|
|
|
|
|
-def h_rank_bottom(now_date, now_h):
|
|
|
+def h_rank_bottom(now_date, now_h, return_count):
|
|
|
"""未按时更新数据,用上一小时结果作为当前小时的数据"""
|
|
|
+ log_.info(f"return_count = {return_count}")
|
|
|
# 获取rov模型结果
|
|
|
redis_helper = RedisHelper()
|
|
|
if now_h == 0:
|
|
@@ -173,35 +178,39 @@ def h_rank_bottom(now_date, now_h):
|
|
|
else:
|
|
|
redis_dt = datetime.datetime.strftime(now_date, '%Y%m%d')
|
|
|
redis_h = now_h - 1
|
|
|
- key_name = f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{redis_dt}.{redis_h}"
|
|
|
+ key_name = f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{return_count}.{redis_dt}.{redis_h}"
|
|
|
initial_data = redis_helper.get_data_zset_with_index(key_name=key_name, start=0, end=-1, with_scores=True)
|
|
|
final_data = dict()
|
|
|
for video_id, score in initial_data:
|
|
|
final_data[video_id] = score
|
|
|
# 存入对应的redis
|
|
|
- final_key_name = f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{datetime.datetime.strftime(now_date, '%Y%m%d')}.{now_h}"
|
|
|
+ final_key_name = \
|
|
|
+ f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{return_count}.{datetime.datetime.strftime(now_date, '%Y%m%d')}.{now_h}"
|
|
|
redis_helper.add_data_with_zset(key_name=final_key_name, data=final_data, expire_time=24 * 3600)
|
|
|
# 清空线上过滤应用列表
|
|
|
- redis_helper.del_keys(key_name=config_.H_VIDEO_FILER)
|
|
|
+ redis_helper.del_keys(key_name=f"{config_.H_VIDEO_FILER}{return_count}")
|
|
|
|
|
|
|
|
|
def h_timer_check():
|
|
|
+ return_count_list = [20, 50]
|
|
|
now_date = datetime.datetime.today()
|
|
|
log_.info(f"now_date: {datetime.datetime.strftime(now_date, '%Y%m%d%H')}")
|
|
|
now_h = datetime.datetime.now().hour
|
|
|
now_min = datetime.datetime.now().minute
|
|
|
if now_h == 0:
|
|
|
- h_rank_bottom(now_date=now_date, now_h=now_h)
|
|
|
+ for cnt in return_count_list:
|
|
|
+ h_rank_bottom(now_date=now_date, now_h=now_h, return_count=cnt)
|
|
|
return
|
|
|
# 查看当前小时更新的数据是否已准备好
|
|
|
h_data_count = h_data_check(project=project, table=table, now_date=now_date)
|
|
|
if h_data_count > 0:
|
|
|
log_.info(f'h_data_count = {h_data_count}')
|
|
|
# 数据准备好,进行更新
|
|
|
- rank_by_h(now_date=now_date, now_h=now_h)
|
|
|
+ rank_by_h(now_date=now_date, now_h=now_h, return_count_list=return_count_list)
|
|
|
elif now_min > 50:
|
|
|
log_.info('h_recall data is None, use bottom data!')
|
|
|
- h_rank_bottom(now_date=now_date, now_h=now_h)
|
|
|
+ for cnt in return_count_list:
|
|
|
+ h_rank_bottom(now_date=now_date, now_h=now_h, return_count=cnt)
|
|
|
else:
|
|
|
# 数据没准备好,1分钟后重新检查
|
|
|
Timer(60, h_timer_check).start()
|