ソースを参照

update rov recall by h

liqian 3 年 前
コミット
4abe44e0e4
3 ファイル変更47 行追加13 行削除
  1. 13 6
      config.py
  2. 27 2
      recommend.py
  3. 7 5
      video_recall.py

+ 13 - 6
config.py

@@ -55,6 +55,9 @@ class BaseConfig(object):
     # ROV召回池redis key前缀,完整格式:com.weiqu.video.recall.hot.item.score.{date}
     RECALL_KEY_NAME_PREFIX = 'com.weiqu.video.recall.hot.item.score.'
 
+    # 小程序小时级更新结果存放 redis key前缀,完整格式:com.weiqu.video.recall.hot.item.score.h.{date}.{h}
+    RECALL_KEY_NAME_PREFIX_BY_H = 'com.weiqu.video.recall.hot.item.score.h.'
+
     # app应用 小程序离线ROV模型结果存放 redis key前缀,完整格式:com.weiqu.video.recall.hot.item.score.app.{date}
     RECALL_KEY_NAME_PREFIX_APP = 'com.weiqu.video.recall.hot.item.score.app.'
 
@@ -100,8 +103,8 @@ class BaseConfig(object):
     ROV_UPDATE_H = 6
     ROV_UPDATE_MINUTE = 30
 
-    # 短视频召回池更新时间 每个小时的15分更新成功
-    ROV_UPDATE_MINUTE_6 = 15
+    # 小时级召回池更新时间 每个小时的15分更新成功
+    ROV_H_UPDATE_MINUTE = 15
 
     # 置顶视频区域 为 全部 的code
     ALL_AREA_CODE = '000000'
@@ -167,7 +170,8 @@ class DevelopmentConfig(BaseConfig):
     # AB实验配置
     AB_EXP_CODE = {
         'rec_size_home': '003',
-        'rec_size_relevant': '004'
+        'rec_size_relevant': '004',
+        'rule_rank1': '011'
     }
 
 
@@ -222,7 +226,8 @@ class TestConfig(BaseConfig):
     # AB实验配置
     AB_EXP_CODE = {
         'rec_size_home': '003',
-        'rec_size_relevant': '004'
+        'rec_size_relevant': '004',
+        'rule_rank1': '011'
     }
 
 
@@ -277,7 +282,8 @@ class PreProductionConfig(BaseConfig):
     # AB实验配置
     AB_EXP_CODE = {
         'rec_size_home': '003',
-        'rec_size_relevant': '004'
+        'rec_size_relevant': '004',
+        'rule_rank1': ''
     }
 
 
@@ -332,7 +338,8 @@ class ProductionConfig(BaseConfig):
     # AB实验配置
     AB_EXP_CODE = {
         'rec_size_home': '003',
-        'rec_size_relevant': '004'
+        'rec_size_relevant': '004',
+        'rule_rank1': ''
     }
 
 

+ 27 - 2
recommend.py

@@ -371,6 +371,8 @@ def video_homepage_recommend(mid, uid, size, app_type, algo_type, client_info, a
             size = size
             top_K = config_.K
             flow_pool_P = config_.P
+            ab_code = config_.AB_CODE['initial']
+            expire_time = 24 * 3600
         else:
             ab_exp_code_list = []
             config_value_dict = {}
@@ -383,6 +385,7 @@ def video_homepage_recommend(mid, uid, size, app_type, algo_type, client_info, a
                         continue
                     ab_exp_code_list.append(str(ab_exp_code))
                     config_value_dict[str(ab_exp_code)] = ab_item.get('configValue', None)
+            # 推荐条数 10->4 实验
             if config_.AB_EXP_CODE['rec_size_home'] in ab_exp_code_list:
                 config_value = config_value_dict.get(config_.AB_EXP_CODE['rec_size_home'], None)
                 if config_value:
@@ -398,10 +401,19 @@ def video_homepage_recommend(mid, uid, size, app_type, algo_type, client_info, a
                 top_K = config_.K
                 flow_pool_P = config_.P
 
+            # 小时级更新-规则1 实验
+            if config_.AB_EXP_CODE['rule_rank1'] in ab_exp_code_list:
+                ab_code = config_.AB_CODE['rank_by_h']
+                expire_time = 3600
+            else:
+                ab_code = config_.AB_CODE['initial']
+                expire_time = 24 * 3600
+
         # 简单召回 - 排序 - 兜底
         rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, app_type=app_type,
                                                            size=size, top_K=top_K, flow_pool_P=flow_pool_P,
-                                                           algo_type=algo_type, client_info=client_info)
+                                                           algo_type=algo_type, client_info=client_info,
+                                                           ab_code=ab_code, expire_time=expire_time)
         # ab-test
         # result = ab_test_op(rank_result=rank_result,
         #                     ab_code_list=[config_.AB_CODE['position_insert']],
@@ -429,6 +441,8 @@ def video_relevant_recommend(video_id, mid, uid, size, app_type, ab_exp_info):
         size = size
         top_K = config_.K
         flow_pool_P = config_.P
+        ab_code = config_.AB_CODE['initial']
+        expire_time = 24 * 3600
     else:
         ab_exp_code_list = []
         config_value_dict = {}
@@ -441,6 +455,8 @@ def video_relevant_recommend(video_id, mid, uid, size, app_type, ab_exp_info):
                     continue
                 ab_exp_code_list.append(str(ab_exp_code))
                 config_value_dict[str(ab_exp_code)] = ab_item.get('configValue', None)
+
+        # 推荐条数 10->4 实验
         if config_.AB_EXP_CODE['rec_size_relevant'] in ab_exp_code_list:
             config_value = config_value_dict.get(config_.AB_EXP_CODE['rec_size_relevant'], None)
             if config_value:
@@ -456,10 +472,19 @@ def video_relevant_recommend(video_id, mid, uid, size, app_type, ab_exp_info):
             top_K = config_.K
             flow_pool_P = config_.P
 
+        # 小时级更新-规则1 实验
+        if config_.AB_EXP_CODE['rule_rank1'] in ab_exp_code_list:
+            ab_code = config_.AB_CODE['rank_by_h']
+            expire_time = 3600
+        else:
+            ab_code = config_.AB_CODE['initial']
+            expire_time = 24 * 3600
+
     # 简单召回 - 排序 - 兜底
     rank_result, last_rov_recall_key = video_recommend(mid=mid, uid=uid, app_type=app_type,
                                                        size=size, top_K=top_K, flow_pool_P=flow_pool_P,
-                                                       algo_type='', client_info=None)
+                                                       algo_type='', client_info=None,
+                                                       ab_code=ab_code, expire_time=expire_time)
     # ab-test
     # result = ab_test_op(rank_result=rank_result,
     #                     ab_code_list=[config_.AB_CODE['position_insert'], config_.AB_CODE['relevant_video_op']],

+ 7 - 5
video_recall.py

@@ -454,13 +454,13 @@ class PoolRecall(object):
         :return: key_name
         """
         if pool_type == 'rov':
+            now_date = date.today().strftime('%Y%m%d')
             # 获取当前所在小时
             h = datetime.now().hour
 
             # appType = 13, 票圈视频APP
             # 数据更新周期:每天07:00-21:00, 2h/次
             if self.app_type == config_.APP_TYPE['APP']:
-                now_date = date.today().strftime('%Y%m%d')
                 if h < 7:
                     key_h = 21
                     key_date = (date.today() - timedelta(days=1)).strftime('%Y%m%d')
@@ -491,20 +491,22 @@ class PoolRecall(object):
 
             else:
                 # 判断热度列表是否更新,未更新则使用前一小时的热度列表
-                key_name = '{}{}'.format(config_.RECALL_KEY_NAME_PREFIX_APP_TYPE, h)
+                key_name = f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{now_date}.{h}"
                 if self.redis_helper.key_exists(key_name):
                     return key_name, h
                 else:
-                    if 0 <= h <= 8:
+                    if h == 0:
                         redis_h = 23
+                        redis_date = (date.today() - timedelta(days=1)).strftime('%Y%m%d')
                     else:
                         redis_h = h - 1
-                    key_name = '{}{}'.format(config_.RECALL_KEY_NAME_PREFIX_APP_TYPE, redis_h)
+                        redis_date = now_date
+                    key_name = f"{config_.RECALL_KEY_NAME_PREFIX_BY_H}{redis_date}.{redis_h}"
                     # 判断当前时间是否晚于数据正常更新时间,发送消息到飞书
                     now_m = datetime.now().minute
                     feishu_text = '{} —— appType = {}, h = {} 数据未按时更新,请及时查看解决。'.format(
                         config_.ENV_TEXT, self.app_type, h)
-                    if now_m > config_.ROV_UPDATE_MINUTE_6 and h >= 8:
+                    if now_m > config_.ROV_H_UPDATE_MINUTE:
                         # 0<=h<8时,数据不做更新,不做报警
                         send_msg_to_feishu(feishu_text)
                     return key_name, redis_h