浏览代码

增加用户-广告主,用户-广告sku行为相关特征

xueyiming 1 周之前
父节点
当前提交
f3f40db6c4

+ 3 - 1
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/dto/AdPlatformCreativeDTO.java

@@ -44,6 +44,8 @@ public class AdPlatformCreativeDTO {
     // 召回源,记录召回用
     // 召回源,记录召回用
     private Object recallSources;
     private Object recallSources;
 
 
-    //所属行业
+    //广告主行业
     private String profession;
     private String profession;
+
+    private Long skuId;
 }
 }

+ 7 - 1
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/score/model/PAIModelV1.java

@@ -55,7 +55,13 @@ public class PAIModelV1 {
     };
     };
 
 
     private static final String[] sparseAdLongFeatures = {
     private static final String[] sparseAdLongFeatures = {
-            "cid", "adid", "adverid"
+            "cid", "adid", "adverid",
+            "user_adverid_view_3d", "user_adverid_view_7d", "user_adverid_view_30d",
+            "user_adverid_click_3d", "user_adverid_click_7d", "user_adverid_click_30d",
+            "user_adverid_conver_3d", "user_adverid_conver_7d", "user_adverid_conver_30d",
+            "user_skuid_view_3d", "user_skuid_view_7d", "user_skuid_view_30d",
+            "user_skuid_click_3d", "user_skuid_click_7d", "user_skuid_click_30d",
+            "user_skuid_conver_3d", "user_skuid_conver_7d", "user_skuid_conver_30d"
     };
     };
 
 
     private static final String[] sparseAdStrFeatures = {
     private static final String[] sparseAdStrFeatures = {

+ 29 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/feature/FeatureService.java

@@ -27,7 +27,7 @@ public class FeatureService {
     private static final String vidUkFormat = "v:%s:%s";
     private static final String vidUkFormat = "v:%s:%s";
     private static final String midUkFormat = "m:%s:%s";
     private static final String midUkFormat = "m:%s:%s";
 
 
-    public Feature getFeature(Collection<String> cidList, Collection<String> adVerIdList, ScoreParam param) {
+    public Feature getFeature(Collection<String> cidList, Collection<String> adVerIdList, List<Long> skuIdList, ScoreParam param) {
         AdRequestContext context = param.getRequestContext();
         AdRequestContext context = param.getRequestContext();
 
 
         List<FeatureKeyProto> protos = new ArrayList<>();
         List<FeatureKeyProto> protos = new ArrayList<>();
@@ -63,9 +63,19 @@ public class FeatureService {
             }
             }
         }
         }
 
 
+        //skuid
+        for (Long skuId : skuIdList) {
+            if (StringUtils.isNotEmpty(param.getMid())) {
+                protos.add(genWithMidAndSkuId("alg_mid_feature_sku_action", param.getMid(), String.valueOf(skuId)));
+            }
+        }
+
         for (String adVerId : adVerIdList) {
         for (String adVerId : adVerIdList) {
             // adverid
             // adverid
             protos.add(genWithAdVerId("alg_cid_feature_adver_action", adVerId));
             protos.add(genWithAdVerId("alg_cid_feature_adver_action", adVerId));
+            if (StringUtils.isNotEmpty(param.getMid())) {
+                protos.add(genWithMidAndAdVerId("alg_mid_feature_adver_action", param.getMid(), adVerId));
+            }
         }
         }
 
 
         // vid
         // vid
@@ -148,6 +158,24 @@ public class FeatureService {
                 .build();
                 .build();
     }
     }
 
 
+    private FeatureKeyProto genWithMidAndAdVerId(String table, String mid, String adVerId) {
+        return FeatureKeyProto.newBuilder()
+                .setUniqueKey(String.format(avUkFormat, table, adVerId))
+                .setTableName(table)
+                .putFieldValue("mid", mid)
+                .putFieldValue("adverid", adVerId)
+                .build();
+    }
+
+    private FeatureKeyProto genWithMidAndSkuId(String table, String mid, String skuId) {
+        return FeatureKeyProto.newBuilder()
+                .setUniqueKey(String.format(cidUkFormat, table, skuId))
+                .setTableName(table)
+                .putFieldValue("mid", mid)
+                .putFieldValue("skuid", skuId)
+                .build();
+    }
+
     private FeatureKeyProto genWithCidAndRegion(String table, String cid, String region) {
     private FeatureKeyProto genWithCidAndRegion(String table, String cid, String region) {
         return FeatureKeyProto.newBuilder()
         return FeatureKeyProto.newBuilder()
                 .setUniqueKey(String.format(cidUkDoubleFieldFormat, table, cid, region))
                 .setUniqueKey(String.format(cidUkDoubleFieldFormat, table, cid, region))

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

@@ -68,7 +68,13 @@ public abstract class RankStrategyBasic implements RankStrategy {
                 .filter(StringUtils::isNotBlank)
                 .filter(StringUtils::isNotBlank)
                 .distinct()
                 .distinct()
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
-        return featureService.getFeature(cidList, adVerIdList, param);
+
+        List<Long> skuIdList = adIdList.stream()
+                .map(AdPlatformCreativeDTO::getSkuId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .collect(Collectors.toList());
+        return featureService.getFeature(cidList, adVerIdList, skuIdList, param);
     }
     }
 
 
     protected Set<String> getNoApiAdVerIds() {
     protected Set<String> getNoApiAdVerIds() {

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

@@ -179,6 +179,7 @@ public class RankStrategyBy688 extends RankStrategyBasic {
                     this.handleC1UIFeature(midTimeDiffMap, actionStaticMap, cidFeatureMap, cidStr);
                     this.handleC1UIFeature(midTimeDiffMap, actionStaticMap, cidFeatureMap, cidStr);
                     this.handleD1Feature(d1Feature, cidFeatureMap);
                     this.handleD1Feature(d1Feature, cidFeatureMap);
                     this.handleD2Feature(vidRankMaps, cidFeatureMap, cidStr);
                     this.handleD2Feature(vidRankMaps, cidFeatureMap, cidStr);
+                    this.handleH1AndH2Feature(cidFeature, adVerFeature, cidFeatureMap);
 
 
                     cidFeatureMap.put("cid", dto.getCreativeId() != null ? String.valueOf(dto.getCreativeId()) : "");
                     cidFeatureMap.put("cid", dto.getCreativeId() != null ? String.valueOf(dto.getCreativeId()) : "");
                     cidFeatureMap.put("adid", dto.getAdId() != null ? String.valueOf(dto.getAdId()) : "");
                     cidFeatureMap.put("adid", dto.getAdId() != null ? String.valueOf(dto.getAdId()) : "");
@@ -557,6 +558,33 @@ public class RankStrategyBy688 extends RankStrategyBasic {
         }
         }
     }
     }
 
 
+    private void handleH1AndH2Feature(Map<String, Map<String, String>> cidFeature,
+                                      Map<String, Map<String, String>> adVerFeature,
+                                      Map<String, String> cidFeatureMap) {
+        Map<String, String> h1Feature = adVerFeature.getOrDefault("alg_mid_feature_adver_action", new HashMap<>());
+        Map<String, String> h2Feature = adVerFeature.getOrDefault("alg_mid_feature_sku_action", new HashMap<>());
+        List<String> timeList = Arrays.asList("3d", "7d", "30d");
+        List<Tuple2<Map<String, String>, String>> featureList = Arrays.asList(
+                new Tuple2<>(h1Feature, "adverid"),
+                new Tuple2<>(h2Feature, "skuid")
+        );
+        for (Tuple2<Map<String, String>, String> tuple2 : featureList) {
+            Map<String, String> feature = tuple2.f1;
+            String prefix = tuple2.f2;
+            for (String time : timeList) {
+                String timeValue = feature.getOrDefault(time, "");
+                if (StringUtils.isNotEmpty(timeValue)) {
+                    String[] split = timeValue.split(",");
+                    cidFeatureMap.put("user" + "_" + prefix + "_" + "view" + "_" + time, split[0]);
+                    cidFeatureMap.put("user" + "_" + prefix + "_" + "click" + "_" + time, split[1]);
+                    cidFeatureMap.put("user" + "_" + prefix + "_" + "conver" + "_" + time, split[2]);
+                }
+            }
+        }
+
+
+    }
+
     private void handleD3AndB1Feature(Map<String, String> d3Feature, String cTitle, Map<String, String> featureMap,
     private void handleD3AndB1Feature(Map<String, String> d3Feature, String cTitle, Map<String, String> featureMap,
                                       ScoreParam scoreParam) {
                                       ScoreParam scoreParam) {
         if (MapUtils.isEmpty(d3Feature) || !d3Feature.containsKey("title") || StringUtils.isEmpty(cTitle)) {
         if (MapUtils.isEmpty(d3Feature) || !d3Feature.containsKey("title") || StringUtils.isEmpty(cTitle)) {
@@ -733,6 +761,24 @@ public class RankStrategyBy688 extends RankStrategyBasic {
             add("user_vid_share_cate1_14d");
             add("user_vid_share_cate1_14d");
             add("user_vid_share_cate2_14d");
             add("user_vid_share_cate2_14d");
             add("user_has_conver_1y");
             add("user_has_conver_1y");
+            add("user_adverid_view_3d");
+            add("user_adverid_click_3d");
+            add("user_adverid_conver_3d");
+            add("user_adverid_view_7d");
+            add("user_adverid_click_7d");
+            add("user_adverid_conver_7d");
+            add("user_adverid_view_30d");
+            add("user_adverid_click_30d");
+            add("user_adverid_conver_30d");
+            add("user_skuid_view_3d");
+            add("user_skuid_click_3d");
+            add("user_skuid_conver_3d");
+            add("user_skuid_view_7d");
+            add("user_skuid_click_7d");
+            add("user_skuid_conver_7d");
+            add("user_skuid_view_30d");
+            add("user_skuid_click_30d");
+            add("user_skuid_conver_30d");
         }};
         }};
     }
     }