liqian 2 лет назад
Родитель
Сommit
5ff40eaa72
3 измененных файлов с 76 добавлено и 12 удалено
  1. 26 4
      config.py
  2. 10 4
      recommend.py
  3. 40 4
      utils.py

+ 26 - 4
config.py

@@ -127,6 +127,8 @@ class BaseConfig(object):
             'abtest_121': 60022,
             'abtest_122': 60023,
             'abtest_130': 60024,
+            'abtest_136': 60027,
+            'abtest_137': 60028,
         },  # 地域分组小时级规则实验
 
         'rank_by_24h': {
@@ -208,10 +210,18 @@ 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实验基础上去除大列表,进行兜底策略优化
+        '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不同实验标识
@@ -650,6 +660,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',
@@ -702,6 +715,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',
@@ -754,6 +770,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',
@@ -806,6 +825,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',

+ 10 - 4
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:
     """
@@ -544,6 +545,9 @@ def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, page_type=0)
     data_key = config_.AB_EXP_CODE['095'].get('data_key')
     no_op_flag = True
 
+    # 获取用户近30天是否有回流
+    user_30day_return_result = get_user_has30day_return(mid=mid)
+
     # 获取实验配置
     if ab_exp_info:
         ab_exp_code_list = []
@@ -559,7 +563,8 @@ def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, page_type=0)
                 config_value_dict[str(ab_exp_code)] = ab_item.get('configValue', None)
 
             if '136' in ab_exp_code_list:
-                if user_type == 'click':
+                # 无回流
+                if user_30day_return_result is False:
                     param = config_.AB_EXP_CODE.get('136')
                     ab_code = param.get('ab_code')
                     expire_time = 3600
@@ -567,7 +572,8 @@ def get_recommend_params(recommend_type, ab_exp_info, ab_info_data, page_type=0)
                     data_key = param.get('data_key')
                     no_op_flag = True
             elif '137' in ab_exp_code_list:
-                if user_type == 'share':
+                # 有回流
+                if user_30day_return_result is True:
                     param = config_.AB_EXP_CODE.get('137')
                     ab_code = param.get('ab_code')
                     expire_time = 3600

+ 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))