Browse Source

Merge branch 'feature_20240705_zhaohaipeng_model_v2' into pre-master

zhaohaipeng 10 months ago
parent
commit
86b33b6166

+ 24 - 0
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/util/NumUtil.java

@@ -9,4 +9,28 @@ public class NumUtil {
         return d1 / d2;
     }
 
+
+    public static Double log(double a){
+        if (a <= 0){
+            return 0D;
+        }
+        return Math.log(a + 1.0);
+    }
+
+    @SafeVarargs
+    public static <T extends Comparable<T>> T min(T... values) {
+        if (values == null || values.length == 0) {
+            throw new IllegalArgumentException("Values cannot be null or empty");
+        }
+
+        T minValue = values[0];
+        for (T value : values) {
+            if (value.compareTo(minValue) < 0) {
+                minValue = value;
+            }
+        }
+
+        return minValue;
+    }
+
 }

File diff suppressed because it is too large
+ 1 - 0
ad-engine-server/src/main/resources/20240704_ad_bucket_351.txt


+ 1 - 1
ad-engine-server/src/main/resources/ad_score_config_20240626.conf

@@ -2,7 +2,7 @@ scorer-config = {
   lr-rov-score-config = {
     scorer-name = "com.tzld.piaoquan.ad.engine.service.score.VlogRovLRScorer"
     scorer-priority = 99
-    model-path = "zhangbo/model_bkb0.txt"
+    model-path = "zhangbo/model_bkb8_v3.txt"
   }
 
 }

+ 1 - 1
ad-engine-server/src/main/resources/application-dev.yml

@@ -4,7 +4,7 @@ server:
 eureka:
   client:
     serviceUrl:
-      defaultZone: http://deveureka-internal.piaoquantv.com/eureka/
+      defaultZone: http://preeureka-internal.piaoquantv.com/eureka/
 
 datalog: .
 

+ 16 - 9
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/feature/FeatureService.java

@@ -1,7 +1,5 @@
 package com.tzld.piaoquan.ad.engine.service.feature;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.TypeReference;
 import com.google.common.reflect.TypeToken;
 import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
 import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
@@ -9,6 +7,7 @@ import com.tzld.piaoquan.ad.engine.service.remote.FeatureV2RemoteService;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRequestContext;
 import com.tzld.piaoquan.recommend.feature.model.feature.FeatureKeyProto;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -50,13 +49,17 @@ public class FeatureService {
             protos.add(genWithCidAndHour("alg_cid_feature_hour_action", cidStr, context.getHour()));
 
             // cid + brand
-            protos.add(genWithCidAndBrand("alg_cid_feature_brand_action", cidStr, context.getMachineinfoBrand()));
+            if (StringUtils.isNotEmpty(context.getMachineinfoBrand())) {
+                protos.add(genWithCidAndBrand("alg_cid_feature_brand_action", cidStr, context.getMachineinfoBrand()));
+            }
 
             // cid + wechatversion
-            protos.add(genWithCidAndWechatVersion("alg_cid_feature_weChatVersion_action", cidStr, context.getMachineinfoWechatversion()));
+            // protos.add(genWithCidAndWechatVersion("alg_cid_feature_weChatVersion_action", cidStr, context.getMachineinfoWechatversion()));
 
             // cid + vid
-            protos.add(genWithCidAndVid("alg_cid_feature_vid_cf", cidStr, param.getVideoId().toString()));
+            if (Objects.nonNull(param.getVideoId())) {
+                protos.add(genWithCidAndVid("alg_cid_feature_vid_cf", cidStr, param.getVideoId().toString()));
+            }
         }
 
         for (String adVerId : adVerIdList) {
@@ -65,12 +68,16 @@ public class FeatureService {
         }
 
         // vid
-        protos.add(genWithVid("alg_cid_feature_vid_cf_rank", param.getVideoId().toString()));
+        if (Objects.nonNull(param.getVideoId())) {
+            protos.add(genWithVid("alg_cid_feature_vid_cf_rank", param.getVideoId().toString()));
+        }
 
         // mid
-        protos.add(genWithMid("alg_mid_feature_ad_action", param.getMid()));
-        protos.add(genWithMid("alg_mid_feature_return_tags", param.getMid()));
-        protos.add(genWithMid("alg_mid_feature_share_tags", param.getMid()));
+        if (StringUtils.isNotEmpty(param.getMid())) {
+            protos.add(genWithMid("alg_mid_feature_ad_action", param.getMid()));
+            protos.add(genWithMid("alg_mid_feature_return_tags", param.getMid()));
+            protos.add(genWithMid("alg_mid_feature_share_tags", param.getMid()));
+        }
 
         Map<String, String> featureMap = remoteService.getFeature(protos);
         featureMap = this.featureStrCover(featureMap);

+ 6 - 4
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/log/impl/LogHubServiceImpl.java

@@ -12,6 +12,7 @@ import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRequestContext;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -71,6 +72,7 @@ public class LogHubServiceImpl implements LogHubService {
                     JSONObject json = new JSONObject();
                     json.put("cid", rankItem.getAdId());
                     json.put("score", rankItem.getScore());
+                    json.put("scoremap", rankItem.getScoreMap());
                     JSONObject featureJson = new JSONObject();
                     for (Map.Entry<String, String> entry : rankItem.getFeatureMap().entrySet()) {
                         if (FEATURE_FIELD_SET.contains(entry.getKey())) {
@@ -82,7 +84,9 @@ public class LogHubServiceImpl implements LogHubService {
                             featureJson.put(entry.getKey(), entry.getValue());
                         }
                     }
-                    json.put("feature", featureJson);
+                    if (MapUtils.isNotEmpty(featureJson)) {
+                        json.put("feature", featureJson);
+                    }
                     scoreResult.add(json);
                 }
 
@@ -96,9 +100,7 @@ public class LogHubServiceImpl implements LogHubService {
                 logMap.put("adid", top1.getId());
                 logMap.put("campaignid", top1.getCampaignId());
                 logMap.put("score", top1.getScore());
-                Map<String, String> featureMap = top1.getFeatureMap();
-                featureMap.put("weight", String.valueOf(top1.getWeight()));
-                logMap.put("allfeature", JSON.toJSONString(featureMap));
+                logMap.put("allfeature", JSON.toJSONString(top1.getFeatureMap()));
                 logMap.put("metafeature", JSON.toJSONString(top1.getMetaFeatureMap()));
                 logMap.put("scoremap", JSON.toJSONString(top1.getScoreMap()));
 

+ 70 - 27
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/RankService680.java

@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.BufferedReader;
@@ -26,6 +27,9 @@ import java.util.stream.Collectors;
 @Service
 public class RankService680 {
 
+    @Value("${id.feature.default.value:0.01}")
+    private String idDefaultValue;
+
     @Autowired
     private FeatureService featureService;
 
@@ -116,19 +120,47 @@ public class RankService680 {
 
         for (AdRankItem item : result) {
             item.setScore(item.getLrScore() * item.getCpa());
+            item.getScoreMap().put("cpa", item.getCpa());
             item.getFeatureMap().putAll(userFeatureMap);
-            if (MapUtils.isNotEmpty(videoFeature)) {
-                item.getMetaFeatureMap().putAll(videoFeature);
+
+            for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
+                if (MapUtils.isNotEmpty(entry.getValue())) {
+                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+                }
             }
-            if (MapUtils.isNotEmpty(userFeature)) {
-                item.getMetaFeatureMap().putAll(userFeature);
+
+            for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
+                if (MapUtils.isNotEmpty(entry.getValue())) {
+                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+                }
             }
-            if (allAdVerFeature.containsKey(item.getAdVerId())) {
-                item.getMetaFeatureMap().putAll(allAdVerFeature.get(item.getAdVerId()));
+
+            Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(item.getAdVerId(), new HashMap<>());
+            for (Map.Entry<String, Map<String, String>> entry : adVerFeature.entrySet()) {
+                if (MapUtils.isNotEmpty(entry.getValue())) {
+                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+                }
             }
-            if (allCidFeature.containsKey(String.valueOf(item.getAdId()))) {
-                item.getMetaFeatureMap().putAll(allCidFeature.get(String.valueOf(item.getAdId())));
+
+            Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(String.valueOf(item.getAdId()), new HashMap<>());
+            for (Map.Entry<String, Map<String, String>> entry : cidFeature.entrySet()) {
+                if (MapUtils.isNotEmpty(entry.getValue())) {
+                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+                }
             }
+
+            // if (MapUtils.isNotEmpty(videoFeature)) {
+            //     item.getMetaFeatureMap().putAll(videoFeature);
+            // }
+            // if (MapUtils.isNotEmpty(userFeature)) {
+            //     item.getMetaFeatureMap().putAll(userFeature);
+            // }
+            // if (allAdVerFeature.containsKey(item.getAdVerId())) {
+            //     item.getMetaFeatureMap().putAll(allAdVerFeature.get(item.getAdVerId()));
+            // }
+            // if (allCidFeature.containsKey(String.valueOf(item.getAdId()))) {
+            //     item.getMetaFeatureMap().putAll(allCidFeature.get(String.valueOf(item.getAdId())));
+            // }
         }
 
         Collections.sort(result);
@@ -145,25 +177,26 @@ public class RankService680 {
 
         List<String> adVerIdList = adIdList.stream()
                 .map(AdPlatformCreativeDTO::getAdVerId)
+                .filter(StringUtils::isNotBlank)
                 .distinct()
                 .collect(Collectors.toList());
         return featureService.getFeature(cidList, adVerIdList, param);
     }
 
     private void handleB1Feature(Map<String, String> b1Feature, Map<String, String> cidFeatureMap, String cid) {
-        cidFeatureMap.put("cid_" + cid, "1");
-        if (StringUtils.isNotBlank(b1Feature.get("adid"))) {
-            String adId = b1Feature.get("adid");
-            cidFeatureMap.put("adid_" + adId, "1");
-        }
+        cidFeatureMap.put("cid_" + cid, "0.01");
+        // if (StringUtils.isNotBlank(b1Feature.get("adid"))) {
+        //     String adId = b1Feature.get("adid");
+        //     cidFeatureMap.put("adid_" + adId, idDefaultValue);
+        // }
         if (StringUtils.isNotBlank(b1Feature.get("adverid"))) {
             String adVerId = b1Feature.get("adverid");
-            cidFeatureMap.put("adverid_" + adVerId, "1");
-        }
-        if (StringUtils.isNotBlank(b1Feature.get("targeting_conversion"))) {
-            String targetingConversion = b1Feature.get("targeting_conversion");
-            cidFeatureMap.put("targeting_conversion_" + targetingConversion, "1");
+            cidFeatureMap.put("adverid_" + adVerId, "0.01");
         }
+        // if (StringUtils.isNotBlank(b1Feature.get("targeting_conversion"))) {
+        //     String targetingConversion = b1Feature.get("targeting_conversion");
+        //     cidFeatureMap.put("targeting_conversion_" + targetingConversion, idDefaultValue);
+        // }
         if (StringUtils.isNotBlank(b1Feature.get("cpa"))) {
             String cpa = b1Feature.get("cpa");
             cidFeatureMap.put("cpa", cpa);
@@ -193,11 +226,16 @@ public class RankService680 {
                 double click = Double.parseDouble(feature.getOrDefault("ad_click_" + time, "0"));
                 double conver = Double.parseDouble(feature.getOrDefault("ad_conversion_" + time, "0"));
                 double income = Double.parseDouble(feature.getOrDefault("ad_income_" + time, "0"));
+                double f2 = NumUtil.div(conver, view);
                 cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(NumUtil.div(click, view)));
-                cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(NumUtil.div(conver, view)));
+                cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(f2));
                 cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.div(conver, click)));
                 cidFeatureMap.put(prefix + "_" + time + "_conver", String.valueOf(conver));
                 cidFeatureMap.put(prefix + "_" + time + "_ecpm", String.valueOf(NumUtil.div(income * 1000, view)));
+
+                cidFeatureMap.put(prefix + "_" + time + "_click", String.valueOf(click));
+                cidFeatureMap.put(prefix + "_" + time + "_conver*log(view)", String.valueOf(conver * NumUtil.log(view)));
+                cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * f2));
             }
         }
 
@@ -220,11 +258,16 @@ public class RankService680 {
                 double click = Double.parseDouble(feature.getOrDefault("ad_click_" + time, "0"));
                 double conver = Double.parseDouble(feature.getOrDefault("ad_conversion_" + time, "0"));
                 double income = Double.parseDouble(feature.getOrDefault("ad_income_" + time, "0"));
+                double f2 = NumUtil.div(conver, view);
                 cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(NumUtil.div(click, view)));
-                cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(NumUtil.div(conver, view)));
+                cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(f2));
                 cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.div(conver, click)));
                 cidFeatureMap.put(prefix + "_" + time + "_conver", String.valueOf(conver));
                 cidFeatureMap.put(prefix + "_" + time + "_ecpm", String.valueOf(NumUtil.div(income * 1000, view)));
+
+                cidFeatureMap.put(prefix + "_" + time + "_click", String.valueOf(click));
+                cidFeatureMap.put(prefix + "_" + time + "_conver*log(view)", String.valueOf(conver * NumUtil.log(view)));
+                cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * f2));
             }
         }
 
@@ -292,9 +335,9 @@ public class RankService680 {
             );
             featureMap.put("actionstatic_ctr", String.valueOf(ctr));
         }
-        if (midActionStatic.containsKey("actionstatic_view_" + cid) && midActionStatic.containsKey("timediff_conver_" + cid)) {
+        if (midActionStatic.containsKey("actionstatic_view_" + cid) && midActionStatic.containsKey("actionstatic_conver_" + cid)) {
             double ctcvr = NumUtil.div(
-                    midActionStatic.getOrDefault("timediff_conver_" + cid, 0.0),
+                    midActionStatic.getOrDefault("actionstatic_conver_" + cid, 0.0),
                     midActionStatic.getOrDefault("actionstatic_view_" + cid, 0.0)
             );
             featureMap.put("actionstatic_ctcvr", String.valueOf(ctcvr));
@@ -302,7 +345,7 @@ public class RankService680 {
         if (midActionStatic.containsKey("actionstatic_conver_" + cid) && midActionStatic.containsKey("actionstatic_click_" + cid)) {
             double cvr = NumUtil.div(
                     midActionStatic.getOrDefault("actionstatic_click_" + cid, 0.0),
-                    midActionStatic.getOrDefault("timediff_conver_" + cid, 0.0)
+                    midActionStatic.getOrDefault("actionstatic_conver_" + cid, 0.0)
             );
             featureMap.put("actionstatic_cvr", String.valueOf(cvr));
         }
@@ -436,7 +479,7 @@ public class RankService680 {
             return;
         }
         synchronized (this) {
-            InputStream resourceStream = RankService680.class.getClassLoader().getResourceAsStream("20240622_ad_bucket_249.txt");
+            InputStream resourceStream = RankService680.class.getClassLoader().getResourceAsStream("20240704_ad_bucket_351.txt");
             if (resourceStream != null) {
                 try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceStream))) {
                     Map<String, double[]> bucketsMap = new HashMap<>();
@@ -461,7 +504,7 @@ public class RankService680 {
                     this.bucketsMap = bucketsMap;
                     this.bucketsLen = bucketsLen;
                 } catch (IOException e) {
-                    log.error("something is wrong in parse bucket file:" + e);
+                    log.error("something is wrong in parse bucket file:", e);
                 }
             } else {
                 log.error("no bucket file");
@@ -476,9 +519,9 @@ public class RankService680 {
             double score = Double.parseDouble(entry.getValue());
             // 注意:0值、不在分桶文件中的特征,会被过滤掉。
             if (score > 1E-8) {
-                if (this.bucketsMap.containsKey(name)) {
+                if (this.bucketsMap.containsKey(name) && this.bucketsLen.containsKey(name)) {
                     double[] buckets = this.bucketsMap.get(name);
-                    int bucketNum = buckets.length + 1;
+                    double bucketNum = this.bucketsLen.get(name);
                     Double scoreNew = 1.0 / bucketNum * (ExtractorUtils.findInsertPosition(buckets, score) + 1.0);
                     newFeatureMap.put(name, String.valueOf(scoreNew));
                 } else {

+ 22 - 25
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/VlogRovFMScorer.java

@@ -8,14 +8,12 @@ import com.tzld.piaoquan.ad.engine.commons.score.model.FMModel;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.UserAdFeature;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.*;
 
 
@@ -132,29 +130,28 @@ public class VlogRovFMScorer extends BaseFMModelScorer {
                             final Map<String, String> sceneFeatureMap) {
 
 
-        // Map<String, String> featureMap = new HashMap<>();
-        // if (MapUtils.isNotEmpty(item.getFeatureMap())) {
-        //     featureMap.putAll(item.getFeatureMap());
-        // }
-        // if (MapUtils.isNotEmpty(userFeatureMap)) {
-        //     featureMap.putAll(userFeatureMap);
-        // }
-        // if (MapUtils.isNotEmpty(sceneFeatureMap)) {
-        //     featureMap.putAll(sceneFeatureMap);
-        // }
+        Map<String, String> featureMap = new HashMap<>();
+        if (MapUtils.isNotEmpty(item.getFeatureMap())) {
+            featureMap.putAll(item.getFeatureMap());
+        }
+        if (MapUtils.isNotEmpty(userFeatureMap)) {
+            featureMap.putAll(userFeatureMap);
+        }
+        if (MapUtils.isNotEmpty(sceneFeatureMap)) {
+            featureMap.putAll(sceneFeatureMap);
+        }
 
         double pro = 0.0;
-        // if (MapUtils.isNotEmpty(featureMap)) {
-        //     try {
-        //         pro = model.score(featureMap);
-        //         // LOGGER.info("fea : {}, score:{}", JSONUtils.toJson(featureMap), pro);
-        //     } catch (Exception e) {
-        //         LOGGER.error("score error for doc={} exception={}", item.getVideoId(), ExceptionUtils.getFullStackTrace(e));
-        //     }
-        // }
-        // item.setScoreRov(pro);
-        // item.getScoresMap().put("RovFMScore", pro);
-        // item.setAllFeatureMap(featureMap);
+        if (MapUtils.isNotEmpty(featureMap)) {
+            try {
+                pro = model.score(featureMap);
+                // LOGGER.info("fea : {}, score:{}", JSONUtils.toJson(featureMap), pro);
+            } catch (Exception e) {
+                LOGGER.error("score error for doc={} exception={}", item.getVideoId(), ExceptionUtils.getFullStackTrace(e));
+            }
+        }
+        item.setLrScore(pro);
+        item.getScoreMap().put("ctcvrScore", pro);
         return pro;
     }
 }

+ 1 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/VlogRovLRScorer.java

@@ -148,7 +148,7 @@ public class VlogRovLRScorer extends BaseLRV2ModelScorer {
                 LOGGER.error("score error for doc={} exception={}", item.getVideoId(), ExceptionUtils.getFullStackTrace(e));
             }
         }
-        item.getScoreMap().put("rovLrScore", pro);
+        item.getScoreMap().put("ctcvrScore", pro);
         item.setLrScore(pro);
         return pro;
     }

+ 1 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/impl/RankServiceImpl.java

@@ -84,7 +84,7 @@ public class RankServiceImpl implements RankService {
         } else if (AbUtil.isInAbExp(expCodeSet, appType, newExpGroup, tacticsAndFmModelScoreExpCode)) {
             return rankBy679(requestParam);
         } else {
-            return adItemRankOld(requestParam);
+            return adItemRankWithVideoAdThompson(requestParam);
         }
     }
 

+ 18 - 11
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/impl/TacticsAndLRModelScoreRankService.java

@@ -1,12 +1,14 @@
 package com.tzld.piaoquan.ad.engine.service.score.impl;
 
 import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
+import com.tzld.piaoquan.ad.engine.commons.util.NumUtil;
 import com.tzld.piaoquan.ad.engine.service.score.RankService680;
 import com.tzld.piaoquan.ad.engine.service.score.dto.AdDirectionScore;
 import com.tzld.piaoquan.ad.engine.service.score.dto.AdPlatformCreativeDTO;
 import com.tzld.piaoquan.ad.engine.service.score.param.RankRecommendRequestParam;
 import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -30,9 +32,9 @@ public class TacticsAndLRModelScoreRankService {
 
         for (AdRankItem adRankItem : result) {
 
-            double s1 = this.calcDirectionScore(adRankItem, adDirectionScoreMap.get(adRankItem.getAdId()));
-            adRankItem.setAdDirectionScore(s1);
+            this.calcDirectionScore(adRankItem, adDirectionScoreMap.get(adRankItem.getAdId()));
 
+            double s1 = adRankItem.getAdDirectionScore();
             // 模型的打分结果已经乘CPA,此处不需要重复乘CPA
             double s2 = adRankItem.getScore();
             adRankItem.setScore(s1 * s2);
@@ -43,10 +45,11 @@ public class TacticsAndLRModelScoreRankService {
         return result;
     }
 
-    private double calcDirectionScore(AdRankItem adRankItem, AdDirectionScore adDirectionScore) {
-        if (Objects.isNull(adDirectionScore)) {
+    private void calcDirectionScore(AdRankItem adRankItem, AdDirectionScore adDirectionScore) {
+        if (Objects.isNull(adDirectionScore) || MapUtils.isEmpty(adDirectionScore.getScoreDetail())) {
+            adRankItem.getScoreMap().put("adDirectionScore", 1.0);
             adRankItem.setAdDirectionScore(1);
-            return 1;
+            return;
         }
         double exponent = Objects.nonNull(adDirectionScore.getExponent()) ? adDirectionScore.getExponent() : 1;
         Map<String, String> scoreDetail = adDirectionScore.getScoreDetail();
@@ -55,11 +58,16 @@ public class TacticsAndLRModelScoreRankService {
         double phoneModel = Double.parseDouble(scoreDetail.getOrDefault("phoneModel", "1"));
         double area = Double.parseDouble(scoreDetail.getOrDefault("area", "1"));
         double peoplePackage = Double.parseDouble(scoreDetail.getOrDefault("peoplePackage", "1"));
-        double excludeConv = Double.parseDouble(scoreDetail.getOrDefault("excludeConv", "1"));
-        double excludeClick = Double.parseDouble(scoreDetail.getOrDefault("excludeClick", "1"));
-        double excludeView = Double.parseDouble(scoreDetail.getOrDefault("excludeView", "1"));
 
-        double excludeMin = Math.min(excludeConv, Math.min(excludeClick, excludeView));
+
+        double excludeMin = 1.0;
+
+        if (scoreDetail.containsKey("excludeConv") || scoreDetail.containsKey("excludeClick") || scoreDetail.containsKey("excludeView")) {
+            double excludeConv = Double.parseDouble(scoreDetail.getOrDefault("excludeConv", "10000"));
+            double excludeClick = Double.parseDouble(scoreDetail.getOrDefault("excludeClick", "10000"));
+            double excludeView = Double.parseDouble(scoreDetail.getOrDefault("excludeView", "10000"));
+            excludeMin = NumUtil.min(excludeConv, excludeClick, excludeView);
+        }
 
         double s1 = (network * phoneModel * area * peoplePackage * excludeMin);
         double s2 = Math.pow(s1, exponent);
@@ -68,9 +76,8 @@ public class TacticsAndLRModelScoreRankService {
 
         Map<String, String> scoreDetailMap = new HashMap<>(scoreDetail);
         scoreDetailMap.put("exponent", String.valueOf(exponent));
+        scoreDetailMap.put("excludeMin", String.valueOf(excludeMin));
         adRankItem.getMetaFeatureMap().put("adDirectionScoreDetail", scoreDetailMap);
-
-        return s2;
     }
 
 }

Some files were not shown because too many files changed in this diff