Forráskód Böngészése

merge abtest-136-137-2022090811

liqian 2 éve
szülő
commit
6921ea20ad
3 módosított fájl, 98 hozzáadás és 16 törlés
  1. 27 5
      config.py
  2. 31 7
      recommend.py
  3. 40 4
      utils.py

+ 27 - 5
config.py

@@ -128,6 +128,8 @@ class BaseConfig(object):
             'abtest_122': 60023,
             'abtest_130': 60024,
             'abtest_139': 60025,
+            'abtest_136': 60027,
+            'abtest_137': 60028,
         },  # 地域分组小时级规则实验
 
         'rank_by_24h': {
@@ -209,14 +211,22 @@ class BaseConfig(object):
             'data_key': 'data4', 'rule_key': 'rule7',
             'ab_code': AB_CODE['region_rank_by_h'].get('abtest_122')
         },  # 票圈短视频 分数据实验 data-[vlog: 0.5, 票圈短视频: 0.5], rule-rule7
-        '130': {
-            'data_key': 'data1', 'rule_key': 'rule4',
-            'ab_code': AB_CODE['region_rank_by_h'].get('abtest_130')
-        },  # 095实验基础上去除大列表,进行兜底策略优化
+        # '130': {
+        #     'data_key': 'data1', 'rule_key': 'rule4',
+        #     'ab_code': AB_CODE['region_rank_by_h'].get('abtest_130')
+        # },  # 095实验基础上去除大列表,进行兜底策略优化
         '139': {
             'data_key': 'data1', 'rule_key': 'rule9', '30day_rule_key': 'rule1',
             'ab_code': AB_CODE['region_rank_by_h'].get('abtest_139')
-        }
+        },
+        '136': {
+            'data_key': 'data1', 'rule_key': 'rule10',
+            'ab_code': AB_CODE['region_rank_by_h'].get('abtest_136')
+        },
+        '137': {
+            'data_key': 'data1', 'rule_key': 'rule11',
+            'ab_code': AB_CODE['region_rank_by_h'].get('abtest_137')
+        },
     }
 
     # 小程序小时级列表key不同实验标识
@@ -668,6 +678,9 @@ class DevelopmentConfig(BaseConfig):
     # 获取视频在流量池中的剩余可分发数接口地址
     GET_REMAIN_VIEW_COUNT_URL = 'http://testapi-internal.piaoquantv.com/flowpool/video/remainViewCount'
 
+    # 获取用户近30天是否有回流接口地址
+    GET_USER_30DayReturnCnt_URL = 'https://videotest.yishihui.com/longvideoapi/openapi/user/has30DayReturnCnt?mid='
+
     # 日志服务配置
     ALIYUN_LOG = {
         'ENDPOINT': 'cn-hangzhou-intranet.log.aliyuncs.com',
@@ -720,6 +733,9 @@ class TestConfig(BaseConfig):
     # 获取视频在流量池中的剩余可分发数接口地址
     GET_REMAIN_VIEW_COUNT_URL = 'http://testapi-internal.piaoquantv.com/flowpool/video/remainViewCount'
 
+    # 获取用户近30天是否有回流接口地址
+    GET_USER_30DayReturnCnt_URL = 'https://videotest.yishihui.com/longvideoapi/openapi/user/has30DayReturnCnt?mid='
+
     # 日志服务配置
     ALIYUN_LOG = {
         'ENDPOINT': 'cn-hangzhou-intranet.log.aliyuncs.com',
@@ -772,6 +788,9 @@ class PreProductionConfig(BaseConfig):
     # 获取视频在流量池中的剩余可分发数接口地址
     GET_REMAIN_VIEW_COUNT_URL = 'http://preapi-internal.piaoquantv.com/flowpool/video/remainViewCount'
 
+    # 获取用户近30天是否有回流接口地址
+    GET_USER_30DayReturnCnt_URL = 'https://videopre.piaoquantv.com/longvideoapi/openapi/user/has30DayReturnCnt?mid='
+
     # 日志服务配置
     ALIYUN_LOG = {
         'ENDPOINT': 'cn-hangzhou-intranet.log.aliyuncs.com',
@@ -824,6 +843,9 @@ class ProductionConfig(BaseConfig):
     # 获取视频在流量池中的剩余可分发数接口地址
     GET_REMAIN_VIEW_COUNT_URL = 'http://api-internal.piaoquantv.com/flowpool/video/remainViewCount'
 
+    # 获取用户近30天是否有回流接口地址
+    GET_USER_30DayReturnCnt_URL = 'https://longvideoapi.piaoquantv.com/longvideoapi/openapi/user/has30DayReturnCnt?mid='
+
     # 日志服务配置
     ALIYUN_LOG = {
         'ENDPOINT': 'cn-hangzhou-intranet.log.aliyuncs.com',

+ 31 - 7
recommend.py

@@ -13,7 +13,7 @@ from video_recall import PoolRecall
 from video_rank import video_rank, bottom_strategy, video_rank_by_w_h_rate, video_rank_with_old_video, bottom_strategy2
 from db_helper import RedisHelper
 import gevent
-from utils import FilterVideos
+from utils import FilterVideos, get_user_has30day_return
 import ast
 
 log_ = Log()
@@ -515,12 +515,13 @@ def update_local_distribute_count(videos):
         log_.error(traceback.format_exc())
 
 
-def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, page_type=0):
+def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, mid, page_type=0):
     """
     根据实验分组给定对应的推荐参数
     :param recommend_type: 首页推荐和相关推荐区分参数(0-首页推荐,1-相关推荐)
     :param ab_exp_info: AB实验组参数
     :param ab_info_data: app实验组参数
+    :param mid: mid
     :param page_type: 页面区分参数,默认:0(首页)
     :return:
     """
@@ -545,6 +546,9 @@ def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, page_type=0)
     rule_key_30day = None
     no_op_flag = True
 
+    # 获取用户近30天是否有回流
+    user_30day_return_result = get_user_has30day_return(mid=mid)
+
     # 获取实验配置
     if ab_exp_info:
         ab_exp_code_list = []
@@ -559,15 +563,34 @@ def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, page_type=0)
                 ab_exp_code_list.append(str(ab_exp_code))
                 config_value_dict[str(ab_exp_code)] = ab_item.get('configValue', None)
 
-            for code, param in config_.AB_EXP_CODE.items():
-                if code in ab_exp_code_list:
+            if '136' in ab_exp_code_list:
+                # 无回流
+                if user_30day_return_result is False:
+                    param = config_.AB_EXP_CODE.get('136')
+                    ab_code = param.get('ab_code')
+                    expire_time = 3600
+                    rule_key = param.get('rule_key')
+                    data_key = param.get('data_key')
+                    no_op_flag = True
+            elif '137' in ab_exp_code_list:
+                # 有回流
+                if user_30day_return_result is True:
+                    param = config_.AB_EXP_CODE.get('137')
                     ab_code = param.get('ab_code')
                     expire_time = 3600
                     rule_key = param.get('rule_key')
                     data_key = param.get('data_key')
                     rule_key_30day = param.get('30day_rule_key')
                     no_op_flag = True
-                    break
+            else:
+                for code, param in config_.AB_EXP_CODE.items():
+                    if code in ab_exp_code_list:
+                        ab_code = param.get('ab_code')
+                        expire_time = 3600
+                        rule_key = param.get('rule_key')
+                        data_key = param.get('data_key')
+                        no_op_flag = True
+                        break
 
             """
             # 推荐条数 10->4 实验
@@ -926,7 +949,7 @@ def video_homepage_recommend(request_id, mid, uid, size, app_type, algo_type,
 
     # 普通mid推荐处理
     top_K, flow_pool_P, ab_code, rule_key, data_key, expire_time, no_op_flag, old_video_index, rule_key_30day = \
-        get_recommend_params(recommend_type=0, ab_exp_info=ab_exp_info, ab_info_data=ab_info_data)
+        get_recommend_params(recommend_type=0, ab_exp_info=ab_exp_info, ab_info_data=ab_info_data, mid=mid)
     # log_.info({
     #     'logTimestamp': int(time.time() * 1000),
     #     'request_id': request_id,
@@ -1013,7 +1036,8 @@ def video_relevant_recommend(request_id, video_id, mid, uid, size, app_type, ab_
 
     # 普通mid推荐处理
     top_K, flow_pool_P, ab_code, rule_key, data_key, expire_time, no_op_flag, old_video_index, rule_key_30day = \
-        get_recommend_params(recommend_type=1, ab_exp_info=ab_exp_info, ab_info_data=ab_info_data, page_type=page_type)
+        get_recommend_params(recommend_type=1, ab_exp_info=ab_exp_info, ab_info_data=ab_info_data, page_type=page_type,
+                             mid=mid)
     # log_.info({
     #     'logTimestamp': int(time.time() * 1000),
     #     'request_id': request_id,

+ 40 - 4
utils.py

@@ -52,6 +52,41 @@ def request_post(request_url, request_data, timeout):
         return None
 
 
+def request_get(request_url, timeout):
+    """
+    get 请求 HTTP接口
+    :param request_url: 接口URL
+    :param timeout: 超时时间,单位为秒,type-float or tuple(connect_timeout, read_timeout)
+    :return: res_data json格式
+    """
+    try:
+        response = requests.get(url=request_url, timeout=timeout)
+        if response.status_code == 200:
+            res_data = json.loads(response.text)
+            return res_data
+        else:
+            return None
+    except Exception as e:
+        log_.error('url: {}, exception: {}, traceback: {}'.format(request_url, e, traceback.format_exc()))
+        return None
+
+
+def get_user_has30day_return(mid):
+    """
+    获取用户近30天是否有回流
+    :param mid: mid
+    :return: data, type
+    """
+    request_url = f"{config_.GET_USER_30DayReturnCnt_URL}{mid}"
+    result = request_get(request_url=request_url, timeout=0.1)
+    if result is None:
+        return None
+    if result['code'] != 0:
+        return None
+    data = result['data']
+    return data
+
+
 def get_videos_remain_view_count(app_type, videos):
     """
     获取视频在流量池中的剩余可分发数
@@ -433,8 +468,9 @@ if __name__ == '__main__':
 
     # update_video_w_h_rate(video_id=113, key_name='')
 
-    request_url = "http://videotest-internal.yishihui.com/longvideoapi/dev/test/testTimeout"
-    headers = {"Connection": "close"}
-    response = requests.post(url=request_url, json={}, timeout=(0.1, 1), headers=headers)
-    print(response.status_code, response.text)
+    mid = "weixin_openid_obHDW5c4g3aULfCWh-68LcUSxCB"
+    # request_url = f"{config_.GET_USER_30DayReturnCnt_URL}{mid}"
+    # res = request_get(request_url=request_url, timeout=100)
+    res = get_user_has30day_return(mid=mid)
+    print(res, type(res))