|
@@ -294,6 +294,41 @@ def predict_mid_video_res_with_add(now_date, mid, video_id, abtest_param, abtest
|
|
|
'ad_predict': ad_predict}
|
|
|
return result
|
|
|
|
|
|
+def predict_mid_video_res_with_model(now_date, mid, video_id, abtest_param, abtest_id, abtest_config_tag, ab_test_code, care_model_status):
|
|
|
+ # now_dt = datetime.datetime.strftime(now_date, '%Y%m%d')
|
|
|
+ now_dt = '20231129'
|
|
|
+ model_key = abtest_param.get('model_key', 'ad_out_v2_model_v1.day')
|
|
|
+ user_key_name = f"{config_.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_USER}{model_key}:{now_dt}"
|
|
|
+ item_key_name = f"{config_.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_ITEM}{model_key}:{now_dt}"
|
|
|
+
|
|
|
+ user_score = redis_helper.get_score_with_value(key_name=user_key_name, value=mid)
|
|
|
+ item_score = redis_helper.get_score_with_value(key_name=item_key_name, value=video_id)
|
|
|
+ if user_score is None:
|
|
|
+ user_score = 0.0
|
|
|
+ if item_score is None:
|
|
|
+ item_score = 0.0
|
|
|
+ mid_video_predict_res = user_score + item_score
|
|
|
+
|
|
|
+ # 获取对应的阈值
|
|
|
+ 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}:"
|
|
|
+ # threshold = redis_helper.get_data_from_redis(key_name=threshold_key_name)
|
|
|
+ threshold = 0.2
|
|
|
+
|
|
|
+ # 阈值判断
|
|
|
+ if mid_video_predict_res > threshold:
|
|
|
+ # 大于阈值,出广告
|
|
|
+ ad_predict = 2
|
|
|
+ else:
|
|
|
+ # 否则,不出广告
|
|
|
+ ad_predict = 1
|
|
|
+ result = {
|
|
|
+ 'user_score': user_score,
|
|
|
+ 'item_score': item_score,
|
|
|
+ 'threshold': threshold,
|
|
|
+ 'ad_predict': ad_predict
|
|
|
+ }
|
|
|
+ return result
|
|
|
|
|
|
def predict_mid_video_res_with_multiply(now_date, mid, video_id, abtest_param, abtest_id, abtest_config_tag, ab_test_code, care_model_status):
|
|
|
now_dt = datetime.datetime.strftime(now_date, '%Y%m%d')
|
|
@@ -449,6 +484,17 @@ def ad_recommend_predict(app_type, mid, video_id, ab_exp_info, ab_test_code, car
|
|
|
ab_test_code=ab_test_code,
|
|
|
care_model_status=care_model_status
|
|
|
)
|
|
|
+ elif threshold_mix_func == 'model':
|
|
|
+ result = predict_mid_video_res_with_model(
|
|
|
+ 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
|
|
|
+ )
|
|
|
else:
|
|
|
result = predict_mid_video_res(
|
|
|
now_date=now_date,
|