jch hai 1 mes
pai
achega
ff0b6736bb

+ 1 - 1
src/main/scala/com/aliyun/odps/spark/examples/myUtils/ConvertUtils.java

@@ -16,7 +16,7 @@ public class ConvertUtils {
         if (null != data && !data.isEmpty()) {
             UserShareReturnProfile user = JSON.parseObject(data, UserShareReturnProfile.class);
             if (null != user) {
-                for (List<UserSRBO> list : Arrays.asList(user.getM_s_s(), user.getM_r_s(), user.getL_s_s(), user.getL_r_s())) {
+                for (List<UserSRBO> list : Arrays.asList(user.getM_s_s(), user.getM_r_s(), user.getL_s_s(), user.getL_r_s(), user.getL_r1_s())) {
                     if (null != list) {
                         for (UserSRBO u : list) {
                             if (null != u) {

+ 30 - 5
src/main/scala/com/aliyun/odps/spark/examples/myUtils/FeatureTransformV2.java

@@ -33,6 +33,12 @@ public class FeatureTransformV2 {
     private static final List<String> userAttrList = Arrays.asList("province", "city", "model", "brand", "system", "user_channel", "user_level");
     private static final Set<String> appSet = new HashSet<>(Arrays.asList("0", "2", "4"));
     private static final Set<String> hotSceneSet = new HashSet<>(Arrays.asList("1008", "1007", "1058", "1074", "1010"));
+    private static final Map<String, String> histotyVideoAttrMAP = new HashMap<>();
+
+    static {
+        histotyVideoAttrMAP.put("merge_first_level_cate", "cate1");
+        histotyVideoAttrMAP.put("merge_second_level_cate", "cate2");
+    }
 
     public static void getContextFeature(long currentMs, String appType, String hotSceneType, Map<String, Double> featureMap) {
         Calendar calendar = Calendar.getInstance();
@@ -239,10 +245,11 @@ public class FeatureTransformV2 {
         if (null == profile) {
             return;
         }
-        getRSCrossFeature("c9_mss", currentMs, seqMaxN, profile.getM_s_s(), rankVideo, hVideoMap, featMap);
-        getRSCrossFeature("c9_mrs", currentMs, seqMaxN, profile.getM_r_s(), rankVideo, hVideoMap, featMap);
-        getRSCrossFeature("c9_lss", currentMs, seqLastN, profile.getL_s_s(), rankVideo, hVideoMap, featMap);
-        getRSCrossFeature("c9_lrs", currentMs, seqLastN, profile.getL_r_s(), rankVideo, hVideoMap, featMap);
+        getRSCrossFeature(false, "c9_mss", currentMs, seqMaxN, profile.getM_s_s(), rankVideo, hVideoMap, featMap);
+        getRSCrossFeature(false, "c9_mrs", currentMs, seqMaxN, profile.getM_r_s(), rankVideo, hVideoMap, featMap);
+        getRSCrossFeature(true, "c9_lss", currentMs, seqLastN, profile.getL_s_s(), rankVideo, hVideoMap, featMap);
+        getRSCrossFeature(false, "c9_lrs", currentMs, seqLastN, profile.getL_r_s(), rankVideo, hVideoMap, featMap);
+        getRSCrossFeature(true, "c9_lr1s", currentMs, seqLastN, profile.getL_r1_s(), rankVideo, hVideoMap, featMap);
 
         if (null == rankVideo || rankVideo.isEmpty()) {
             return;
@@ -253,7 +260,7 @@ public class FeatureTransformV2 {
         getVideoAttrSRCrossFeature("c9_l2s", rankVideo.getOrDefault("festive_label2", ""), profile.getL2_s(), featMap);
     }
 
-    private static void getRSCrossFeature(String prefix, long currentMs, int maxN, List<UserSRBO> list, Map<String, String> rankVideo, Map<String, Map<String, String>> hVideoMap, Map<String, Double> featMap) {
+    private static void getRSCrossFeature(boolean flag, String prefix, long currentMs, int maxN, List<UserSRBO> list, Map<String, String> rankVideo, Map<String, Map<String, String>> hVideoMap, Map<String, Double> featMap) {
         if (null != list && !list.isEmpty()) {
             for (int i = 0; i < list.size() && i < maxN; i++) {
                 UserSRBO u = list.get(i);
@@ -284,6 +291,9 @@ public class FeatureTransformV2 {
                         if (null != hVideoMap && hVideoMap.containsKey(vid)) {
                             Map<String, String> hVideo = hVideoMap.get(vid);
                             getTwoVideoCrossFeature(baseKey, hVideoSimAttrs, hVideo, rankVideo, featMap);
+                            if (flag) {
+                                getHistoryVideoCateFeature(baseKey, hVideo, featMap);
+                            }
                         }
                     }
                 }
@@ -561,4 +571,19 @@ public class FeatureTransformV2 {
         }
         return map.isEmpty() ? 0 : Double.parseDouble(map.getOrDefault(name, "0.0"));
     }
+
+    private static void getHistoryVideoCateFeature(String prefix, Map<String, String> videoInfo, Map<String, Double> featMap) {
+        if (null == videoInfo || videoInfo.isEmpty()) {
+            return;
+        }
+        for (Map.Entry<String, String> entry : histotyVideoAttrMAP.entrySet()) {
+            String attr = entry.getKey();
+            String attrVal = videoInfo.getOrDefault(attr, "");
+            attrVal = attrVal.trim();
+            if (!attrVal.isEmpty() && !attrVal.equals("unknown")) {
+                String key = String.format("%s@%s@%s", prefix, attr, attrVal);
+                featMap.put(key, 1.0);
+            }
+        }
+    }
 }

+ 6 - 1
src/main/scala/com/aliyun/odps/spark/examples/myUtils/UserShareReturnProfile.java

@@ -18,7 +18,8 @@ public class UserShareReturnProfile {
     private List<UserSRBO> m_s_s;    // max_share_seq(最大分享序列)
     private List<UserSRBO> m_r_s;   // max_return_seq(最大回流序列)
     private List<UserSRBO> l_s_s;    // last_share_seq(最近分享序列)
-    private List<UserSRBO> l_r_s;   // last_return_seq(最近回流序列)
+    private List<UserSRBO> l_r_s;   // last_return_seq(最近n层回流序列)
+    private List<UserSRBO> l_r1_s;   // last_return_seq(最近1层回流序列)
     private Map<String, VideoAttrSRBO> c1_s;   // cate1_seq(merge_first_level_cate序列-回流率)
     private Map<String, VideoAttrSRBO> c2_s;   // cate2_seq(merge_second_level_cate序列-回流率)
     private Map<String, VideoAttrSRBO> l1_s;   // label1_seq(festive_label1序列-回流率)
@@ -40,6 +41,10 @@ public class UserShareReturnProfile {
         this.l_r_s = JSON.parseArray(data, UserSRBO.class);
     }
 
+    public void setL_r1_s(String data) {
+        this.l_r1_s = JSON.parseArray(data, UserSRBO.class);
+    }
+
     public void setC1_s(String data) {
         this.c1_s = parseVideoAttrSR(data);
     }