Forráskód Böngészése

Merge branch 'feature_feature' into feature/zhangbo_model

# Conflicts:
#	recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV999.java
zhangbo 10 hónapja
szülő
commit
b581af55c6

+ 39 - 17
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/FeatureService.java

@@ -4,6 +4,7 @@ import com.google.common.reflect.TypeToken;
 import com.tzld.piaoquan.recommend.feature.model.feature.FeatureKeyProto;
 import com.tzld.piaoquan.recommend.server.remote.FeatureV2RemoteService;
 import com.tzld.piaoquan.recommend.server.util.JSONUtils;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,8 +25,8 @@ public class FeatureService {
     /**
      * @return k1:视频、k2:表、k3:特征、v:特征值
      */
-    public Map<String, Map<String, Map<String, String>>> getFeature(List<String> vidList, String appType,
-                                                                    String province) {
+    public Feature getFeature(String mid, List<String> vidList, String appType,
+                              String province) {
 
         List<FeatureKeyProto> protos = new ArrayList<>();
 
@@ -70,31 +71,44 @@ public class FeatureService {
 
         Map<String, String> result = remoteService.getFeature(protos);
 
-        Map<String, Map<String, Map<String, String>>> data = new HashMap<>();
+        Feature feature = new Feature();
 
         result.entrySet().forEach(e -> {
 
+            String[] uk = StringUtils.split(e.getKey(), ":");
+            String prefix = uk[0];
+            String table = uk[1];
             Map<String, String> colMap = JSONUtils.fromJson(e.getValue(), new TypeToken<Map<String, String>>() {
             }, Collections.emptyMap());
-            String feature = colMap.get("feature");
+            String featureStr = colMap.get("feature");
+
+            switch (prefix) {
+                case "v":
+                    String vid = uk[2];
+                    Map<String, Map<String, String>> tableFeatureMap = feature.getVideoFeature().getOrDefault(vid, new HashMap<>());
+                    tableFeatureMap.put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
+                    }, Collections.emptyMap()));
+                    feature.getVideoFeature().put(vid, tableFeatureMap);
+                    break;
+                case "u":
+                    feature.getUserFeature().put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
+                    }, Collections.emptyMap()));
+                    break;
+                default:
+                    break;
+            }
 
-            String[] uk = StringUtils.split(e.getKey(), ":");
-            String vid = uk[1];
-            String table = uk[0];
-            Map<String, Map<String, String>> tableFeatureMap = data.getOrDefault(vid, new HashMap<>());
-            tableFeatureMap.put(table, JSONUtils.fromJson(feature, new TypeToken<Map<String, String>>() {
-            }, Collections.emptyMap()));
-            data.put(vid, tableFeatureMap);
         });
 
         return data;
     }
 
-    private final String ukFormat = "%s:%s";
+    private final String videoUkFormat = "v:%s:%s";
+    private final String userUkFormat = "u:%s";
 
     private FeatureKeyProto genWithVid(String table, String vid) {
         return FeatureKeyProto.newBuilder()
-                .setUniqueKey(String.format(ukFormat, table, vid))
+                .setUniqueKey(String.format(videoUkFormat, table, vid))
                 .setTableName(table)
                 .putFieldValue("vid", vid)
                 .build();
@@ -102,7 +116,7 @@ public class FeatureService {
 
     private FeatureKeyProto genWithVidAndAppType(String table, String vid, String appType) {
         return FeatureKeyProto.newBuilder()
-                .setUniqueKey(String.format(ukFormat, table, vid))
+                .setUniqueKey(String.format(videoUkFormat, table, vid))
                 .setTableName(table)
                 .putFieldValue("vid", vid)
                 .putFieldValue("apptype", appType)
@@ -111,7 +125,7 @@ public class FeatureService {
 
     private FeatureKeyProto genWithVidAndProvince(String table, String vid, String province) {
         return FeatureKeyProto.newBuilder()
-                .setUniqueKey(String.format(ukFormat, table, vid))
+                .setUniqueKey(String.format(videoUkFormat, table, vid))
                 .setTableName(table)
                 .putFieldValue("vid", vid)
                 .putFieldValue("province", province)
@@ -120,7 +134,7 @@ public class FeatureService {
 
     private FeatureKeyProto genWithVidAndHeadVid(String table, String vid, String headVid) {
         return FeatureKeyProto.newBuilder()
-                .setUniqueKey(String.format(ukFormat, table, vid))
+                .setUniqueKey(String.format(videoUkFormat, table, vid))
                 .setTableName(table)
                 .putFieldValue("vid", vid)
                 .putFieldValue("headVid", )
@@ -129,11 +143,19 @@ public class FeatureService {
 
     private FeatureKeyProto genWithMid(String table, String mid) {
         return FeatureKeyProto.newBuilder()
-                .setUniqueKey(String.format(ukFormat, table, mid))
+                .setUniqueKey(String.format(userUkFormat, table))
                 .setTableName(table)
                 .putFieldValue("mid", )
                 .build();
     }
 
+    @Data
+    public static class Feature {
+        // k1:视频、k2:表、k3:特征、v:特征值
+        private Map<String, Map<String, Map<String, String>>> videoFeature = new HashMap<>();
+
+        // k1:表、k2:特征、v:特征值
+        private Map<String, Map<String, String>> userFeature = new HashMap<>();
+    }
 
 }

+ 1 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV999.java

@@ -94,7 +94,7 @@ public class RankStrategy4RegionMergeModelV999 extends RankStrategy4RegionMergeM
         // TODO 1 批量获取特征  省份参数要对齐
         List<String> vids = CommonCollectionUtils.toListDistinct(rovRecallRank, v -> String.valueOf(v.getVideoId()));
         // k1:视频、k2:表、k3:特征、v:特征值
-        Map<String, Map<String, Map<String, String>>> featureOrigin = featureService.getFeature(vids,
+        Map<String, Map<String, Map<String, String>>> featureOrigin = featureService.getFeature(param.getMid(), vids,
                 String.valueOf(param.getAppType()), param.getProvince());