ソースを参照

抽取公共方法

xueyiming 1 日 前
コミット
015342e4cf

+ 55 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBasic.java

@@ -11,6 +11,7 @@ import com.tzld.piaoquan.ad.engine.commons.redis.AdRedisHelper;
 import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
 import com.tzld.piaoquan.ad.engine.service.feature.Feature;
 import com.tzld.piaoquan.ad.engine.service.feature.FeatureService;
+import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
@@ -263,4 +264,58 @@ public abstract class RankStrategyBasic implements RankStrategy {
             return 1.0;
         }
     }
+
+    protected void putMetaFeature(AdRankItem adRankItem, Feature feature, Map<String, String> reqFeature,
+                                  Map<String, String> sceneFeatureMap, RankRecommendRequestParam request) {
+        Map<String, Map<String, String>> userFeature = feature.getUserFeature();
+        Map<String, Map<String, String>> videoFeature = feature.getVideoFeature();
+        Map<String, Map<String, Map<String, String>>> allAdVerFeature = feature.getAdVerFeature();
+        Map<String, Map<String, Map<String, String>>> allCidFeature = feature.getCidFeature();
+        Map<String, Map<String, Map<String, String>>> allSkuFeature = feature.getSkuFeature();
+        for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
+            if (MapUtils.isNotEmpty(entry.getValue())) {
+                adRankItem.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
+            if (MapUtils.isNotEmpty(entry.getValue())) {
+                adRankItem.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(adRankItem.getAdVerId(), new HashMap<>());
+        for (Map.Entry<String, Map<String, String>> entry : adVerFeature.entrySet()) {
+            if (MapUtils.isNotEmpty(entry.getValue())) {
+                adRankItem.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(String.valueOf(adRankItem.getAdId()), new HashMap<>());
+        for (Map.Entry<String, Map<String, String>> entry : cidFeature.entrySet()) {
+            if (MapUtils.isNotEmpty(entry.getValue())) {
+                adRankItem.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(adRankItem.getSkuId()), new HashMap<>());
+        for (Map.Entry<String, Map<String, String>> entry : skuFeature.entrySet()) {
+            if (MapUtils.isNotEmpty(entry.getValue())) {
+                adRankItem.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
+            }
+        }
+        long cid = adRankItem.getAdId();
+        List<AdPlatformCreativeDTO> adIdList = request.getAdIdList();
+        AdPlatformCreativeDTO adPlatformCreativeDTO = adIdList.stream()
+                .filter(dto -> cid == dto.getCreativeId())
+                .findFirst().orElse(null);
+        if (adPlatformCreativeDTO != null) {
+            reqFeature.put("cid", String.valueOf(adPlatformCreativeDTO.getCreativeId()));
+            reqFeature.put("adid", String.valueOf(adPlatformCreativeDTO.getAdId()));
+            reqFeature.put("adverid", String.valueOf(adPlatformCreativeDTO.getAdVerId()));
+            reqFeature.put("profession", adPlatformCreativeDTO.getProfession());
+        }
+        adRankItem.getMetaFeatureMap().put("reqFeature", reqFeature);
+        adRankItem.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
+    }
 }

+ 1 - 45
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy679.java

@@ -231,51 +231,7 @@ public class RankStrategyBy679 extends RankStrategyBasic {
                 item.setScore(item.getCpm() * cpmCoefficient / 1000);
             }
 
-            for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            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());
-                }
-            }
-
-            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());
-                }
-            }
-
-            Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(item.getSkuId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : skuFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-            long cid = item.getAdId();
-            List<AdPlatformCreativeDTO> adIdList = request.getAdIdList();
-            AdPlatformCreativeDTO adPlatformCreativeDTO = adIdList.stream()
-                    .filter(dto -> cid == dto.getCreativeId())
-                    .findFirst().orElse(null);
-            if (adPlatformCreativeDTO != null) {
-                reqFeature.put("cid", String.valueOf(adPlatformCreativeDTO.getCreativeId()));
-                reqFeature.put("adid", String.valueOf(adPlatformCreativeDTO.getAdId()));
-                reqFeature.put("adverid", String.valueOf(adPlatformCreativeDTO.getAdVerId()));
-                reqFeature.put("profession", adPlatformCreativeDTO.getProfession());
-            }
-            item.getMetaFeatureMap().put("reqFeature", reqFeature);
-            item.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
+            putMetaFeature(item, feature, reqFeature, sceneFeatureMap, request);
         }
 
         log.info("cost={}, feature1={}, feature2={}, feature31={}, feature32={}, feature4={}, getScorerPipeline={}, " +

+ 1 - 45
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy680.java

@@ -255,51 +255,7 @@ public class RankStrategyBy680 extends RankStrategyBasic {
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);
-            for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(top1Item.getAdVerId(), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : adVerFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(String.valueOf(top1Item.getAdId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : cidFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(top1Item.getSkuId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : skuFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-            long cid = top1Item.getAdId();
-            List<AdPlatformCreativeDTO> adIdList = request.getAdIdList();
-            AdPlatformCreativeDTO adPlatformCreativeDTO = adIdList.stream()
-                    .filter(dto -> cid == dto.getCreativeId())
-                    .findFirst().orElse(null);
-            if (adPlatformCreativeDTO != null) {
-                reqFeature.put("cid", String.valueOf(adPlatformCreativeDTO.getCreativeId()));
-                reqFeature.put("adid", String.valueOf(adPlatformCreativeDTO.getAdId()));
-                reqFeature.put("adverid", String.valueOf(adPlatformCreativeDTO.getAdVerId()));
-                reqFeature.put("profession", adPlatformCreativeDTO.getProfession());
-            }
-            top1Item.getMetaFeatureMap().put("reqFeature", reqFeature);
-            top1Item.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
+            putMetaFeature(top1Item, feature, reqFeature, sceneFeatureMap, request);
         }
         long time6 = System.currentTimeMillis();
         log.info("cost={}, getFeature={}, handleFeature={},  similar={}, bucketFeature={}, getScorerPipeline={}, " +

+ 1 - 45
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy683.java

@@ -256,51 +256,7 @@ public class RankStrategyBy683 extends RankStrategyBasic {
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);
-            for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(top1Item.getAdVerId(), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : adVerFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(String.valueOf(top1Item.getAdId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : cidFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(top1Item.getSkuId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : skuFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-            long cid = top1Item.getAdId();
-            List<AdPlatformCreativeDTO> adIdList = request.getAdIdList();
-            AdPlatformCreativeDTO adPlatformCreativeDTO = adIdList.stream()
-                    .filter(dto -> cid == dto.getCreativeId())
-                    .findFirst().orElse(null);
-            if (adPlatformCreativeDTO != null) {
-                reqFeature.put("cid", String.valueOf(adPlatformCreativeDTO.getCreativeId()));
-                reqFeature.put("adid", String.valueOf(adPlatformCreativeDTO.getAdId()));
-                reqFeature.put("adverid", String.valueOf(adPlatformCreativeDTO.getAdVerId()));
-                reqFeature.put("profession", adPlatformCreativeDTO.getProfession());
-            }
-            top1Item.getMetaFeatureMap().put("reqFeature", reqFeature);
-            top1Item.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
+            putMetaFeature(top1Item, feature, reqFeature, sceneFeatureMap, request);
         }
         long time6 = System.currentTimeMillis();
         log.info("cost={}, getFeature={}, handleFeature={},  similar={}, bucketFeature={}, getScorerPipeline={}, " +

+ 1 - 46
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy687.java

@@ -236,52 +236,7 @@ public class RankStrategyBy687 extends RankStrategyBasic {
             if (noApiAdVerIds.contains(item.getAdVerId())) {
                 item.setScore(item.getCpm() / 1000);
             }
-
-            for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            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());
-                }
-            }
-
-            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());
-                }
-            }
-
-            Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(item.getSkuId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : skuFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-            long cid = item.getAdId();
-            List<AdPlatformCreativeDTO> adIdList = request.getAdIdList();
-            AdPlatformCreativeDTO adPlatformCreativeDTO = adIdList.stream()
-                    .filter(dto -> cid == dto.getCreativeId())
-                    .findFirst().orElse(null);
-            if (adPlatformCreativeDTO != null) {
-                reqFeature.put("cid", String.valueOf(adPlatformCreativeDTO.getCreativeId()));
-                reqFeature.put("adid", String.valueOf(adPlatformCreativeDTO.getAdId()));
-                reqFeature.put("adverid", String.valueOf(adPlatformCreativeDTO.getAdVerId()));
-                reqFeature.put("profession", adPlatformCreativeDTO.getProfession());
-            }
-            item.getMetaFeatureMap().put("reqFeature", reqFeature);
-            item.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
+            putMetaFeature(item, feature, reqFeature, sceneFeatureMap, request);
         }
 
         long time4 = System.currentTimeMillis();

+ 1 - 45
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/strategy/RankStrategyBy688.java

@@ -299,51 +299,7 @@ public class RankStrategyBy688 extends RankStrategyBasic {
 
         if (CollectionUtils.isNotEmpty(result)) {
             AdRankItem top1Item = result.get(0);
-            for (Map.Entry<String, Map<String, String>> entry : videoFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            for (Map.Entry<String, Map<String, String>> entry : userFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(top1Item.getAdVerId(), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : adVerFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(String.valueOf(top1Item.getAdId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : cidFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            Map<String, Map<String, String>> skuFeature = allSkuFeature.getOrDefault(String.valueOf(top1Item.getSkuId()), new HashMap<>());
-            for (Map.Entry<String, Map<String, String>> entry : skuFeature.entrySet()) {
-                if (MapUtils.isNotEmpty(entry.getValue())) {
-                    top1Item.getMetaFeatureMap().put(entry.getKey(), entry.getValue());
-                }
-            }
-            long cid = top1Item.getAdId();
-            List<AdPlatformCreativeDTO> adIdList = request.getAdIdList();
-            AdPlatformCreativeDTO adPlatformCreativeDTO = adIdList.stream()
-                    .filter(dto -> cid == dto.getCreativeId())
-                    .findFirst().orElse(null);
-            if (adPlatformCreativeDTO != null) {
-                reqFeature.put("cid", String.valueOf(adPlatformCreativeDTO.getCreativeId()));
-                reqFeature.put("adid", String.valueOf(adPlatformCreativeDTO.getAdId()));
-                reqFeature.put("adverid", String.valueOf(adPlatformCreativeDTO.getAdVerId()));
-                reqFeature.put("profession", adPlatformCreativeDTO.getProfession());
-            }
-            top1Item.getMetaFeatureMap().put("reqFeature", reqFeature);
-            top1Item.getMetaFeatureMap().put("sceneFeature", sceneFeatureMap);
+            putMetaFeature(top1Item, feature, reqFeature, sceneFeatureMap, request);
         }
         long time6 = System.currentTimeMillis();
         log.info("cost={}, getFeature={}, handleFeature={},  similar={}, bucketFeature={}, getScorerPipeline={}, " +