|
@@ -31,17 +31,15 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
@Override
|
|
|
public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
|
|
|
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 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();
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
String userScore = redisHelper.get(userKeyName);
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
String itemScore = redisHelper.get(itemKeyName);
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
|
|
|
//加载配置数据
|
|
|
String configKeyNamePrefix = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG
|
|
@@ -50,7 +48,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
+ modelParam.getAbtestParam().get("abtest_config_tag");
|
|
|
String configKey = configKeyNamePrefix + ":config";
|
|
|
String configStr = redisHelper.get(configKey);
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
Map<String, Object> configMap = new HashMap<>();
|
|
|
String hitStrategy="model";
|
|
|
if (configStr != null) {
|
|
@@ -71,7 +69,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
|
|
|
boolean useBackup = Boolean.valueOf((String)configMap.getOrDefault("use_backup_key","false"));
|
|
|
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
//有数据为空且开启兜底策略
|
|
|
if (
|
|
|
(StringUtils.isBlank(userScore) || StringUtils.isBlank(itemScore))
|
|
@@ -85,7 +83,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
result.put("hit_strategy",hitStrategy);
|
|
|
return result;
|
|
|
}
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
double offlineScore ;
|
|
|
//处理空值逻辑
|
|
|
double threshold=(double)configMap.getOrDefault("threshold",0);
|
|
@@ -103,7 +101,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
(double)configMap.getOrDefault("user_threshold", 0);
|
|
|
hitStrategy=isUserScoreBlank?"item":"user";
|
|
|
}
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
//获取计算参数
|
|
|
SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
|
|
|
SimpleDateFormat weekDayFormat = new SimpleDateFormat("u");
|
|
@@ -121,7 +119,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
rankScore = Double.parseDouble(rankScoreStr);
|
|
|
}
|
|
|
}
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore);
|
|
|
double onlineScore=getOlineScore(onlineFeatures);
|
|
|
double rankScoreBias = (double)configMap.getOrDefault("rank_score_bias", 0.0);
|
|
@@ -130,7 +128,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
double rankScoreW = (double)configMap.getOrDefault("rank_score_w", 1.0);
|
|
|
double finalScoreW = (double)configMap.getOrDefault("final_score_w", 1.0);
|
|
|
double mergeScore = finalScoreW * finalScore + rankScoreW * (rankScore + rankScoreBias);
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
int adPredict;
|
|
|
if (mergeScore < threshold) {
|
|
|
// If final score is below threshold, show the ad
|
|
@@ -139,7 +137,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
|
|
|
// Otherwise, do not show the ad
|
|
|
adPredict = 1;
|
|
|
}
|
|
|
- TimerWatchUtil.printCost(methodName,step++,startTime);
|
|
|
+
|
|
|
result=new HashMap<>();
|
|
|
result.put("user_score", userScore);
|
|
|
result.put("item_score", itemScore);
|