Переглянути джерело

add ad abtest: 173-e, 173-f

liqian 2 роки тому
батько
коміт
09e4c49f0d
3 змінених файлів з 59 додано та 9 видалено
  1. 38 8
      ad_recommend.py
  2. 3 1
      app.py
  3. 18 0
      config.py

+ 38 - 8
ad_recommend.py

@@ -42,7 +42,35 @@ def get_params(ab_exp_info, ab_test_code):
     return abtest_id, abtest_config_tag
 
 
-def ad_recommend_predict(app_type, mid, video_id, ab_exp_info, ab_test_code):
+def get_threshold(abtest_id, abtest_config_tag, ab_test_code, mid_group, care_model_status, abtest_param):
+    """获取对应的阈值"""
+    # 判断是否是关怀模式实验
+    care_model_status_param = abtest_param.get('care_model_status_param', None)
+    care_model_ab_mid_group = abtest_param.get('care_model_ab_mid_group', None)
+    if care_model_status_param is None:
+        # 无关怀模式实验
+        threshold_key_name_prefix = config_.KEY_NAME_PREFIX_AD_THRESHOLD
+    else:
+        # 关怀模式实验
+        if care_model_status is None or care_model_ab_mid_group is None:
+            # 参数缺失,走默认
+            threshold_key_name_prefix = config_.KEY_NAME_PREFIX_AD_THRESHOLD
+        elif int(care_model_status) == int(care_model_status_param) and mid_group == care_model_ab_mid_group:
+            # 实验匹配,获取对应的阈值
+            threshold_key_name_prefix = config_.KEY_NAME_PREFIX_AD_THRESHOLD_CARE_MODEL
+        else:
+            threshold_key_name_prefix = config_.KEY_NAME_PREFIX_AD_THRESHOLD
+
+    threshold_key_name = f"{threshold_key_name_prefix}{abtest_id}:{abtest_config_tag}:{ab_test_code}:{mid_group}"
+    threshold = redis_helper.get_data_from_redis(key_name=threshold_key_name)
+    if threshold is None:
+        threshold = 0
+    else:
+        threshold = float(threshold)
+    return threshold
+
+
+def ad_recommend_predict(app_type, mid, video_id, ab_exp_info, ab_test_code, care_model_status):
     """
     广告推荐预测
     :param app_type: app_type
@@ -50,6 +78,7 @@ def ad_recommend_predict(app_type, mid, video_id, ab_exp_info, ab_test_code):
     :param video_id: video_id
     :param ab_exp_info: AB实验组参数
     :param ab_test_code: 用户对应的ab组
+    :param care_model_status: 用户关怀模式状态 1-未开启,2-开启
     :return: ad_predict, type-int, 1-不发放广告,2-发放广告
     """
     try:
@@ -105,13 +134,14 @@ def ad_recommend_predict(app_type, mid, video_id, ab_exp_info, ab_test_code):
             mid_video_share_rate = float(group_share_rate) * float(video_share_rate)
 
             # 获取对应的阈值
-            threshold_key_name = \
-                f"{config_.KEY_NAME_PREFIX_AD_THRESHOLD}{abtest_id}:{abtest_config_tag}:{ab_test_code}:{mid_group}"
-            threshold = redis_helper.get_data_from_redis(key_name=threshold_key_name)
-            if threshold is None:
-                threshold = 0
-            else:
-                threshold = float(threshold)
+            threshold = get_threshold(
+                abtest_id=abtest_id,
+                abtest_config_tag=abtest_config_tag,
+                ab_test_code=ab_test_code,
+                mid_group=mid_group,
+                care_model_status=care_model_status,
+                abtest_param=abtest_param
+            )
             # 阈值判断
             if mid_video_share_rate > threshold:
                 # 大于阈值,出广告

+ 3 - 1
app.py

@@ -301,11 +301,13 @@ def ad_predict():
         app_type = request_data.get('appType')
         ab_exp_info = request_data.get('abExpInfo')
         ab_test_code = request_data.get('abTestCode')
+        care_model_status = request_data.get('careModelStatus')  # 用户关怀模式状态 1: 未开启,2: 开启
         predict_result = ad_recommend_predict(app_type=app_type,
                                               mid=mid,
                                               video_id=video_id,
                                               ab_exp_info=ab_exp_info,
-                                              ab_test_code=ab_test_code)
+                                              ab_test_code=ab_test_code,
+                                              care_model_status=care_model_status)
         if predict_result is None:
             result = {'code': -1, 'message': 'fail'}
         else:

+ 18 - 0
config.py

@@ -694,6 +694,22 @@ class BaseConfig(object):
             'group_class_key': 'class1',
             'no_ad_mid_group_list': NO_AD_MID_GROUP_LIST['class1']
         },  # 视频使用7天内有曝光的
+        '173-e': {
+            'video': {'data': 'data1'},
+            'user': {'data': 'data1', 'rule': 'rule2'},
+            'group_class_key': 'class1',
+            'no_ad_mid_group_list': NO_AD_MID_GROUP_LIST['class1'],
+            'care_model_status_param': 2,
+            'care_model_ab_mid_group': 'mean_group',
+        },  # 开启关怀模式人群多出广告
+        '173-f': {
+            'video': {'data': 'data1'},
+            'user': {'data': 'data1', 'rule': 'rule2'},
+            'group_class_key': 'class1',
+            'no_ad_mid_group_list': NO_AD_MID_GROUP_LIST['class1'],
+            'care_model_status_param': 1,
+            'care_model_ab_mid_group': 'mean_group',
+        },  # 未开启关怀模式人群多出广告
 
         # 票圈视频+
         '190-a': {
@@ -830,6 +846,8 @@ class BaseConfig(object):
     KEY_NAME_PREFIX_MID_GROUP = 'mid:group:'
     # 广告推荐阈值结果存放 redis key 前缀,完整格式:ad:threshold:{abtestId}:{abtestConfigTag}:{abtestGroup}:{group}
     KEY_NAME_PREFIX_AD_THRESHOLD = 'ad:threshold:'
+    # 广告推荐关怀模式实验阈值结果存放 redis key 前缀,完整格式:ad:threshold:care:{abtestId}:{abtestConfigTag}:{abtestGroup}:{group}
+    KEY_NAME_PREFIX_AD_THRESHOLD_CARE_MODEL = 'ad:threshold:care:'
 
 
 class DevelopmentConfig(BaseConfig):