|
@@ -303,26 +303,50 @@ def predict_mid_video_res_with_model(now_date, mid, video_id, abtest_param, abte
|
|
|
item_key_name = f"{config_.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_ITEM}{model_key}:{video_id}"
|
|
|
config_key_prefix = f"{config_.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG}{model_key}:{abtest_id}:{abtest_config_tag}"
|
|
|
threshold_key = f"{config_key_prefix}:threshold"
|
|
|
+ use_backup_key = f"{config_key_prefix}:use_backup"
|
|
|
+ item_threshold_key = f"{config_key_prefix}:item_threshold"
|
|
|
+ user_threshold_key = f"{config_key_prefix}:user_threshold"
|
|
|
+ miss_threshold_key = f"{config_key_prefix}:miss_threshold"
|
|
|
|
|
|
user_score = redis_helper.get_data_from_redis(key_name=user_key_name)
|
|
|
item_score = redis_helper.get_data_from_redis(key_name=item_key_name)
|
|
|
-
|
|
|
+ hit_strategy = 'model'
|
|
|
# 如果离线分数为空,则走基线逻辑
|
|
|
- if user_score is None or item_score is None:
|
|
|
- result = predict_mid_video_res(
|
|
|
- now_date=now_date,
|
|
|
- mid=mid,
|
|
|
- video_id=video_id,
|
|
|
- abtest_param=abtest_param,
|
|
|
- abtest_id=abtest_id,
|
|
|
- abtest_config_tag=abtest_config_tag,
|
|
|
- ab_test_code=ab_test_code,
|
|
|
- care_model_status=care_model_status,
|
|
|
- app_type=app_type
|
|
|
- )
|
|
|
- return result
|
|
|
+ if user_score is not None and item_score is not None:
|
|
|
+ offline_score = float(user_score) + float(item_score)
|
|
|
+ else:
|
|
|
+ use_backup = redis_helper.get_data_from_redis(key_name=use_backup_key)
|
|
|
+ # 如果离线分数为空 & 兜底策略开启,走兜底策略
|
|
|
+ if use_backup == 'true':
|
|
|
+ result = predict_mid_video_res(
|
|
|
+ now_date=now_date,
|
|
|
+ mid=mid,
|
|
|
+ video_id=video_id,
|
|
|
+ abtest_param=abtest_param,
|
|
|
+ abtest_id=abtest_id,
|
|
|
+ abtest_config_tag=abtest_config_tag,
|
|
|
+ ab_test_code=ab_test_code,
|
|
|
+ care_model_status=care_model_status,
|
|
|
+ app_type=app_type
|
|
|
+ )
|
|
|
+ if result is not None:
|
|
|
+ hit_strategy = 'backup'
|
|
|
+ result['hit_strategy'] = hit_strategy
|
|
|
+ return result
|
|
|
+ else:
|
|
|
+ if item_score is not None:
|
|
|
+ offline_score = float(item_score)
|
|
|
+ threshold_key = item_threshold_key
|
|
|
+ hit_strategy = 'item'
|
|
|
+ elif user_score is not None:
|
|
|
+ offline_score = float(user_score)
|
|
|
+ threshold_key = user_threshold_key
|
|
|
+ hit_strategy = 'user'
|
|
|
+ else: # item_score and user_score all None
|
|
|
+ offline_score = 0.0
|
|
|
+ threshold_key = miss_threshold_key
|
|
|
+ hit_strategy = 'miss'
|
|
|
|
|
|
- offline_score = float(user_score) + float(item_score)
|
|
|
online_features = {
|
|
|
'ctx_apptype': str(app_type),
|
|
|
'ctx_week': time.strftime('%w', time.localtime()),
|
|
@@ -330,8 +354,12 @@ def predict_mid_video_res_with_model(now_date, mid, video_id, abtest_param, abte
|
|
|
}
|
|
|
|
|
|
final_score, online_score = get_final_score(online_features, offline_score)
|
|
|
- threshold = float(redis_helper.get_data_from_redis(key_name=threshold_key))
|
|
|
-
|
|
|
+ threshold = redis_helper.get_data_from_redis(key_name=threshold_key)
|
|
|
+ if threshold is None:
|
|
|
+ threshold = 0.0
|
|
|
+ hit_strategy = 'error_' + hit_strategy
|
|
|
+ else:
|
|
|
+ threshold = float(threshold)
|
|
|
# 跳出率阈值判断
|
|
|
if final_score < threshold:
|
|
|
# 小于阈值,出广告
|
|
@@ -347,6 +375,7 @@ def predict_mid_video_res_with_model(now_date, mid, video_id, abtest_param, abte
|
|
|
'threshold': threshold,
|
|
|
'ad_predict': ad_predict,
|
|
|
'online_features': online_features,
|
|
|
+ 'hit_strategy': hit_strategy
|
|
|
}
|
|
|
return result
|
|
|
|