Browse Source

扩展特征

jch 20 hours ago
parent
commit
ab274e6d2c

+ 3 - 0
src/main/scala/com/aliyun/odps/spark/examples/myUtils/ConvertV2.java

@@ -14,6 +14,8 @@ public class ConvertV2 {
         // origin info
         String ts = record.get("ts");
         long currentMs = Long.parseLong(ts) * 1000;
+        String uid = record.getOrDefault("uid", "");
+        String mid = record.getOrDefault("mid", "");
         String vid = record.get("vid");
         String appType = record.getOrDefault("apptype", "");
         String hotSencetype = record.getOrDefault("hotsencetype", "");
@@ -42,6 +44,7 @@ public class ConvertV2 {
         // user feature
         FeatureTransformV2.getUserFeature(userOriginInfo, featMap);
         FeatureTransformV2.getUserProfileFeature(userProfile, record, featMap);
+        FeatureTransformV2.getMid(uid, mid, currentMs, userProfile, featMap);
 
         // user & video feature
         FeatureTransformV2.getUserTagsCrossVideoFeature("c5", rankInfo, userOriginInfo.get("alg_mid_feature_return_tags"), featMap);

+ 25 - 0
src/main/scala/com/aliyun/odps/spark/examples/myUtils/FeatureTransformV2.java

@@ -10,6 +10,7 @@ public class FeatureTransformV2 {
     private static final double smoothPlus = 5.0;
     private static final double largerSmoothPlus = 30.0;
     private static final double log1Scale = 10.0;
+    private static final long midValidTs = 14 * 24 * 3600 * 1000;
     private static final List<String> c1Periods = Arrays.asList("72h", "168h");
     private static final List<String> b0Periods = Arrays.asList("1h", "3h", "6h", "12h");
     private static final List<String> b1Periods = Arrays.asList("1h", "3h", "6h", "24h", "72h", "168h");
@@ -62,6 +63,30 @@ public class FeatureTransformV2 {
         oneTypeStatFeature("c1", "return_1_uv", c1Periods, userOriginInfo.get("mid_global_feature_20250212"), featMap);
     }
 
+    public static void getMid(String uid, String mid, long currentMs, UserShareReturnProfile profile, Map<String, Double> featMap) {
+        if (null == profile) {
+            return;
+        }
+        String key = "";
+        if (null != uid && !uid.isEmpty() && !uid.equals("null")) {
+            key = uid;
+        } else if (null != mid && !mid.isEmpty() && !mid.equals("null")) {
+            key = mid;
+        }
+        if (!key.isEmpty()) {
+            List<UserSRBO> l_r_s = profile.getL_r_s();
+            if (null != l_r_s && !l_r_s.isEmpty()) {
+                UserSRBO user = l_r_s.get(0);
+                if (null != user) {
+                    long ts = user.getTs() * 1000;
+                    if (ts > currentMs - midValidTs) {
+                        featMap.put(String.format("%s@%s", "mid", key), 1.0);
+                    }
+                }
+            }
+        }
+    }
+
     public static void getUserProfileFeature(UserShareReturnProfile profile, Map<String, String> userInfo, Map<String, Double> featMap) {
         if (null != profile) {
             long s_pv = profile.getS_pv();              // share_pv(分享pv)