Browse Source

feat:广告人群选择实验迭代

zhaohaipeng 3 months ago
parent
commit
11d68a69a0

+ 12 - 11
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/v2/PredictServiceV2.java

@@ -9,7 +9,6 @@ import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.text.DecimalFormat;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -27,15 +26,14 @@ public class PredictServiceV2 {
         Feature feature = featureService.getPredictFeature(context);
         Map<String, Map<String, String>> userFeature = feature.getUserFeature();
         Map<String, String> featureMap = userFeature.getOrDefault("alg_ad_crowd_choose_feature_v2", new HashMap<>());
-        double score = 0.8;
+        double minScore = exp713Config.getOrDefault("minScore", 0.1d);
+        double maxScore = exp713Config.getOrDefault("maxScore", 0.8d);
+        double score = maxScore;
 
         context.getLogParam().setBIsNewUser(true);
 
         if (MapUtils.isNotEmpty(featureMap)) {
 
-            double noAdShareMin = exp713Config.getOrDefault((Object) "noAdShareMin", 5d);
-            double noShareReturnMin = exp713Config.getOrDefault("noShareReturnMin", 25d);
-
             double adViewCnt = Double.parseDouble(featureMap.getOrDefault("ad_view_cnt", "0"));
             double adClick = Double.parseDouble(featureMap.getOrDefault("ad_click", "0"));
             double adConver = Double.parseDouble(featureMap.getOrDefault("ad_conver", "0"));
@@ -59,11 +57,11 @@ public class PredictServiceV2 {
             double noAdValue = noAdShareValue + noAdReturnValue;
 
             // 计算最终的收益
-            score = NumUtil.softmax(new double[]{hasAdValue, noAdValue})[0];
+            double hasRate = exp713Config.getOrDefault("hasRate", 1d);
+            double noRate = exp713Config.getOrDefault("noRate", 1d);
+            score = NumUtil.softmax(new double[]{hasAdValue * hasRate, noAdValue * noRate})[0];
 
 
-            context.getLogParam().setScore(score);
-            context.getLogParam().setExpId("713");
             context.getLogParam().getMetaFeature().putAll(feature.getUserFeature());
             for (Map.Entry<String, String> entry : featureMap.entrySet()) {
                 context.getLogParam().getAllFeature().put(entry.getKey(), Double.parseDouble(entry.getValue()));
@@ -76,14 +74,14 @@ public class PredictServiceV2 {
             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("score", NumUtil.round(score, 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);
         }
 
         // 分数截断,避免过长或过短
-        double minScore = exp713Config.getOrDefault("minScore", 0.1d);
-        double maxScore = exp713Config.getOrDefault("maxScore", 0.8d);
         if (score < minScore) {
             score = minScore;
         } else if (score > maxScore) {
@@ -92,6 +90,9 @@ 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);