|
@@ -14,7 +14,7 @@ import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class PredictServiceV2 {
|
|
|
+public class PredictServiceV2 extends BasicPredict {
|
|
|
|
|
|
@Autowired
|
|
|
private FeatureService featureService;
|
|
@@ -22,15 +22,16 @@ public class PredictServiceV2 {
|
|
|
@ApolloJsonValue("${exp.713.config:{}}")
|
|
|
private Map<String, Double> exp713Config;
|
|
|
|
|
|
- public Map<String, Object> adPredict(PredictContext context) {
|
|
|
- Feature feature = featureService.getPredictFeature(context);
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> predict(PredictContext ctx) {
|
|
|
+ Feature feature = featureService.getPredictFeature(ctx);
|
|
|
Map<String, Map<String, String>> userFeature = feature.getUserFeature();
|
|
|
Map<String, String> featureMap = userFeature.getOrDefault("alg_ad_crowd_choose_feature_v2", new HashMap<>());
|
|
|
double minScore = exp713Config.getOrDefault("minScore", 0.1d);
|
|
|
double maxScore = exp713Config.getOrDefault("maxScore", 0.8d);
|
|
|
double score = maxScore;
|
|
|
|
|
|
- context.getLogParam().setBIsNewUser(true);
|
|
|
+ ctx.getLogParam().setBIsNewUser(true);
|
|
|
|
|
|
if (MapUtils.isNotEmpty(featureMap)) {
|
|
|
|
|
@@ -62,23 +63,23 @@ public class PredictServiceV2 {
|
|
|
score = NumUtil.softmax(new double[]{hasAdValue * hasRate, noAdValue * noRate})[0];
|
|
|
|
|
|
|
|
|
- context.getLogParam().getMetaFeature().putAll(feature.getUserFeature());
|
|
|
+ ctx.getLogParam().getMetaFeature().putAll(feature.getUserFeature());
|
|
|
for (Map.Entry<String, String> entry : featureMap.entrySet()) {
|
|
|
- context.getLogParam().getAllFeature().put(entry.getKey(), Double.parseDouble(entry.getValue()));
|
|
|
+ ctx.getLogParam().getAllFeature().put(entry.getKey(), Double.parseDouble(entry.getValue()));
|
|
|
}
|
|
|
- context.getLogParam().getScoreMap().put("adClickValue", NumUtil.round(adClickValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("adConverValue", NumUtil.round(adConverValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("hasAdShareValue", NumUtil.round(hasAdShareValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("hasAdReturnValue", NumUtil.round(hasAdReturnValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("hasAdValue", NumUtil.round(hasAdValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("noAdShareValue", NumUtil.round(noAdShareValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("noAdReturnValue", NumUtil.round(noAdReturnValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("noAdValue", NumUtil.round(noAdValue, 6));
|
|
|
- context.getLogParam().getScoreMap().put("originScore", NumUtil.round(score, 6));
|
|
|
- context.getLogParam().getScoreMap().put("hasRate", NumUtil.round(hasRate, 6));
|
|
|
- context.getLogParam().getScoreMap().put("noRate", NumUtil.round(noRate, 6));
|
|
|
-
|
|
|
- context.getLogParam().setBIsNewUser(false);
|
|
|
+ ctx.getLogParam().getScoreMap().put("adClickValue", NumUtil.round(adClickValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("adConverValue", NumUtil.round(adConverValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("hasAdShareValue", NumUtil.round(hasAdShareValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("hasAdReturnValue", NumUtil.round(hasAdReturnValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("hasAdValue", NumUtil.round(hasAdValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("noAdShareValue", NumUtil.round(noAdShareValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("noAdReturnValue", NumUtil.round(noAdReturnValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("noAdValue", NumUtil.round(noAdValue, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("originScore", NumUtil.round(score, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("hasRate", NumUtil.round(hasRate, 6));
|
|
|
+ ctx.getLogParam().getScoreMap().put("noRate", NumUtil.round(noRate, 6));
|
|
|
+
|
|
|
+ ctx.getLogParam().setBIsNewUser(false);
|
|
|
}
|
|
|
|
|
|
// 分数截断,避免过长或过短
|
|
@@ -90,33 +91,19 @@ public class PredictServiceV2 {
|
|
|
|
|
|
double random = Math.random();
|
|
|
boolean isShowAd = random < score;
|
|
|
- context.getLogParam().setExpId("713");
|
|
|
- context.getLogParam().setScore(score);
|
|
|
- context.getLogParam().getScoreMap().put("score", NumUtil.round(score, 6));
|
|
|
- context.getLogParam().setAIsShowAd(isShowAd);
|
|
|
- context.getLogParam().getScoreMap().put("minScore", minScore);
|
|
|
- context.getLogParam().getScoreMap().put("maxScore", maxScore);
|
|
|
- context.getLogParam().getScoreMap().put("random", random);
|
|
|
+ ctx.getLogParam().setExpId("713");
|
|
|
+ ctx.getLogParam().setScore(score);
|
|
|
+ ctx.getLogParam().getScoreMap().put("score", NumUtil.round(score, 6));
|
|
|
+ ctx.getLogParam().setAIsShowAd(isShowAd);
|
|
|
+ ctx.getLogParam().getScoreMap().put("minScore", minScore);
|
|
|
+ ctx.getLogParam().getScoreMap().put("maxScore", maxScore);
|
|
|
+ ctx.getLogParam().getScoreMap().put("random", random);
|
|
|
|
|
|
|
|
|
- return isShowAd ? rtnAdPredict(context) : rtnNoAdPredict(context);
|
|
|
+ return isShowAd ? rtnAdPredict(ctx) : rtnNoAdPredict(ctx);
|
|
|
}
|
|
|
|
|
|
|
|
|
- private Map<String, Object> rtnNoAdPredict(PredictContext context) {
|
|
|
- Map<String, Object> rtnMap = new HashMap<>();
|
|
|
- rtnMap.put("ad_predict", 1);
|
|
|
- rtnMap.put("no_ad_strategy", "713_exp");
|
|
|
- return rtnMap;
|
|
|
- }
|
|
|
-
|
|
|
- private Map<String, Object> rtnAdPredict(PredictContext context) {
|
|
|
- Map<String, Object> rtnMap = new HashMap<>();
|
|
|
- rtnMap.put("ad_predict", 2);
|
|
|
- rtnMap.putAll(context.getLogParam().getScoreMap());
|
|
|
- return rtnMap;
|
|
|
- }
|
|
|
-
|
|
|
// public Map<String, Object> adPredictV1(PredictContext context){
|
|
|
//
|
|
|
// Feature feature = featureService.getPredictFeature(context);
|