Browse Source

Merge branch 'feature_20240621_zhaohaipeng_fm' of algorithm/ad-engine into master

zhaohaipeng 10 months ago
parent
commit
346076fda3

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

@@ -9,4 +9,19 @@ public class NumUtil {
         return d1 / d2;
     }
 
+    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;
+    }
+
 }

+ 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);

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

@@ -100,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()));
 

+ 15 - 9
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;
 
@@ -43,11 +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();
@@ -56,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);
@@ -69,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;
     }
 
 }