|
@@ -2,6 +2,7 @@ package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
|
|
import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
|
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
|
|
import com.tzld.piaoquan.ad.engine.service.predict.config.AdOutV1OnlineWeightConfig;
|
|
import com.tzld.piaoquan.ad.engine.service.predict.config.AdOutV1OnlineWeightConfig;
|
|
import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
|
|
import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
|
|
import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer;
|
|
import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer;
|
|
@@ -30,13 +31,17 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
|
|
public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
|
|
Map<String, Object> result;
|
|
Map<String, Object> result;
|
|
-
|
|
|
|
|
|
+ long startTime=System.currentTimeMillis();
|
|
|
|
+ String methodName=initName();
|
|
|
|
+ int step=1;
|
|
String modelKey = (String) modelParam.getAbtestParam().getOrDefault("model_key", "ad_out_v1");
|
|
String modelKey = (String) modelParam.getAbtestParam().getOrDefault("model_key", "ad_out_v1");
|
|
String userKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_USER + modelKey + ":" + modelParam.getMid();
|
|
String userKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_USER + modelKey + ":" + modelParam.getMid();
|
|
String itemKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_ITEM + modelKey + ":" + modelParam.getVideoId();
|
|
String itemKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_ITEM + modelKey + ":" + modelParam.getVideoId();
|
|
-
|
|
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
String userScore = redisHelper.get(userKeyName);
|
|
String userScore = redisHelper.get(userKeyName);
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
String itemScore = redisHelper.get(itemKeyName);
|
|
String itemScore = redisHelper.get(itemKeyName);
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
|
|
|
//加载配置数据
|
|
//加载配置数据
|
|
String configKeyNamePrefix = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG
|
|
String configKeyNamePrefix = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG
|
|
@@ -45,6 +50,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
+ modelParam.getAbtestParam().get("abtest_config_tag");
|
|
+ modelParam.getAbtestParam().get("abtest_config_tag");
|
|
String configKey = configKeyNamePrefix + ":config";
|
|
String configKey = configKeyNamePrefix + ":config";
|
|
String configStr = redisHelper.get(configKey);
|
|
String configStr = redisHelper.get(configKey);
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
Map<String, Object> configMap = new HashMap<>();
|
|
Map<String, Object> configMap = new HashMap<>();
|
|
String hitStrategy="model";
|
|
String hitStrategy="model";
|
|
if (configStr != null) {
|
|
if (configStr != null) {
|
|
@@ -65,7 +71,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
|
|
|
boolean useBackup = Boolean.valueOf((String)configMap.getOrDefault("use_backup_key","false"));
|
|
boolean useBackup = Boolean.valueOf((String)configMap.getOrDefault("use_backup_key","false"));
|
|
|
|
|
|
-
|
|
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
//有数据为空且开启兜底策略
|
|
//有数据为空且开启兜底策略
|
|
if (
|
|
if (
|
|
(StringUtils.isBlank(userScore) || StringUtils.isBlank(itemScore))
|
|
(StringUtils.isBlank(userScore) || StringUtils.isBlank(itemScore))
|
|
@@ -79,7 +85,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
result.put("hit_strategy",hitStrategy);
|
|
result.put("hit_strategy",hitStrategy);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
double offlineScore ;
|
|
double offlineScore ;
|
|
//处理空值逻辑
|
|
//处理空值逻辑
|
|
double threshold=(double)configMap.getOrDefault("threshold",0);
|
|
double threshold=(double)configMap.getOrDefault("threshold",0);
|
|
@@ -97,6 +103,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
(double)configMap.getOrDefault("user_threshold", 0);
|
|
(double)configMap.getOrDefault("user_threshold", 0);
|
|
hitStrategy=isUserScoreBlank?"item":"user";
|
|
hitStrategy=isUserScoreBlank?"item":"user";
|
|
}
|
|
}
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
//获取计算参数
|
|
//获取计算参数
|
|
SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
|
|
SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
|
|
SimpleDateFormat weekDayFormat = new SimpleDateFormat("u");
|
|
SimpleDateFormat weekDayFormat = new SimpleDateFormat("u");
|
|
@@ -114,6 +121,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
rankScore = Double.parseDouble(rankScoreStr);
|
|
rankScore = Double.parseDouble(rankScoreStr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore);
|
|
offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore);
|
|
double onlineScore=getOlineScore(onlineFeatures);
|
|
double onlineScore=getOlineScore(onlineFeatures);
|
|
double rankScoreBias = (double)configMap.getOrDefault("rank_score_bias", 0.0);
|
|
double rankScoreBias = (double)configMap.getOrDefault("rank_score_bias", 0.0);
|
|
@@ -122,7 +130,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
double rankScoreW = (double)configMap.getOrDefault("rank_score_w", 1.0);
|
|
double rankScoreW = (double)configMap.getOrDefault("rank_score_w", 1.0);
|
|
double finalScoreW = (double)configMap.getOrDefault("final_score_w", 1.0);
|
|
double finalScoreW = (double)configMap.getOrDefault("final_score_w", 1.0);
|
|
double mergeScore = finalScoreW * finalScore + rankScoreW * (rankScore + rankScoreBias);
|
|
double mergeScore = finalScoreW * finalScore + rankScoreW * (rankScore + rankScoreBias);
|
|
-
|
|
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
int adPredict;
|
|
int adPredict;
|
|
if (mergeScore < threshold) {
|
|
if (mergeScore < threshold) {
|
|
// If final score is below threshold, show the ad
|
|
// If final score is below threshold, show the ad
|
|
@@ -131,6 +139,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
// Otherwise, do not show the ad
|
|
// Otherwise, do not show the ad
|
|
adPredict = 1;
|
|
adPredict = 1;
|
|
}
|
|
}
|
|
|
|
+ TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
result=new HashMap<>();
|
|
result=new HashMap<>();
|
|
result.put("user_score", userScore);
|
|
result.put("user_score", userScore);
|
|
result.put("item_score", itemScore);
|
|
result.put("item_score", itemScore);
|