丁云鹏 před 1 rokem
rodič
revize
1223cb89c8

+ 37 - 20
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/common/base/ItemFeature.java

@@ -2,8 +2,6 @@ package com.tzld.piaoquan.recommend.server.common.base;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
-import lombok.Data;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 
@@ -18,6 +16,7 @@ public class ItemFeature {
 
     /**
      * 有多个标题,暂时不会用到所以先不处理
+     *
      * @since 2023-12-05
      */
     private String title;
@@ -41,32 +40,32 @@ public class ItemFeature {
     private UserActionFeature month3_cnt_features;
 
 
-    public void setVideoId(String key){
-        if(key == null){
+    public void setVideoId(String key) {
+        if (key == null) {
             this.videoId = "0";
         } else {
             this.videoId = key;
         }
     }
 
-    public void setUpId(String key){
-        if(key == null){
+    public void setUpId(String key) {
+        if (key == null) {
             this.upId = "0";
         } else {
             this.upId = key;
         }
     }
 
-    public void setTags(String key){
-        if(key == null){
+    public void setTags(String key) {
+        if (key == null) {
             this.tags = "0";
         } else {
             this.tags = key;
         }
     }
 
-    public void setTitle(String key){
-        if(key == null){
+    public void setTitle(String key) {
+        if (key == null) {
             this.title = "0";
         } else {
             this.title = key;
@@ -74,28 +73,28 @@ public class ItemFeature {
     }
 
 
-    public void setDay1_cnt_features(UserActionFeature feature){
+    public void setDay1_cnt_features(UserActionFeature feature) {
         this.day1_cnt_features = feature;
     }
 
 
-    public void setDay3_cnt_features(UserActionFeature feature){
+    public void setDay3_cnt_features(UserActionFeature feature) {
         this.day3_cnt_features = feature;
 
     }
 
-    public void setDay7_cnt_features(UserActionFeature feature){
+    public void setDay7_cnt_features(UserActionFeature feature) {
         this.day7_cnt_features = feature;
 
     }
 
-    public void setMonth3_cnt_features(UserActionFeature feature){
-        this.month3_cnt_features= feature;
+    public void setMonth3_cnt_features(UserActionFeature feature) {
+        this.month3_cnt_features = feature;
 
     }
 
     public void setTitleLength(String key) {
-        if(key == null){
+        if (key == null) {
             this.titleLength = "0";
         } else {
             this.titleLength = key;
@@ -104,7 +103,7 @@ public class ItemFeature {
 
 
     public void setDaysSinceUpload(String key) {
-        if(key == null){
+        if (key == null) {
             this.daysSinceUpload = "0";
         } else {
             this.daysSinceUpload = key;
@@ -112,7 +111,7 @@ public class ItemFeature {
     }
 
     public void setPlayLength(String key) {
-        if(key == null){
+        if (key == null) {
             this.playLength = "0";
         } else {
             this.playLength = key;
@@ -120,7 +119,7 @@ public class ItemFeature {
     }
 
     public void setTotalTime(String key) {
-        if(key == null){
+        if (key == null) {
             this.totalTime = "0";
         } else {
             this.totalTime = key;
@@ -131,10 +130,28 @@ public class ItemFeature {
         return this.videoId;
     }
 
-    public String getValue(){
+    public String getValue() {
         Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
         return gson.toJson(this);
     }
 
+    public static ItemFeature defaultInstance(String videoId) {
+        ItemFeature feature = new ItemFeature();
+        feature.setDay1_cnt_features(null);
+        feature.setDay3_cnt_features(null);
+        feature.setDay7_cnt_features(null);
+        feature.setDaysSinceUpload(null);
+        feature.setMonth3_cnt_features(null);
+        feature.setPlayLength(null);
+        feature.setTags(null);
+        feature.setTitle(null);
+        feature.setTitleLength(null);
+        feature.setTotalTime(null);
+        feature.setUpId(null);
+        feature.setVideoId(videoId);
+
+        return feature;
+    }
+
 
 }

+ 30 - 20
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/common/base/UserFeature.java

@@ -2,16 +2,13 @@ package com.tzld.piaoquan.recommend.server.common.base;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
-import lombok.Data;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 
-import java.util.Map;
-
 @Getter
 @NoArgsConstructor
 public class UserFeature {
+
     private String uid;
     // 当天统计量信息
     private UserActionFeature day1_cnt_features;
@@ -26,53 +23,53 @@ public class UserFeature {
     private String user_cycle_bucket_30days;
     private String user_share_bucket_30days;
 
-    public void setUid(String key){
+    public void setUid(String key) {
         this.uid = key;
-        if(key == null)
+        if (key == null)
             this.uid = "0";
     }
 
 
-    public void setDay1_cnt_features(UserActionFeature key){
+    public void setDay1_cnt_features(UserActionFeature key) {
         this.day1_cnt_features = key;
-        if(key == null)
+        if (key == null)
             this.day1_cnt_features = new UserActionFeature();
     }
 
-    public void setDay3_cnt_features(UserActionFeature key){
+    public void setDay3_cnt_features(UserActionFeature key) {
         this.day3_cnt_features = key;
-        if(key == null)
+        if (key == null)
             this.day3_cnt_features = new UserActionFeature();
     }
 
-    public void setDay7_cnt_features(UserActionFeature key){
+    public void setDay7_cnt_features(UserActionFeature key) {
         this.day7_cnt_features = key;
-        if(key == null)
+        if (key == null)
             this.day7_cnt_features = new UserActionFeature();
     }
 
     public void setMonth3_cnt_features(UserActionFeature key) {
         this.month3_cnt_features = key;
-        if(key == null)
+        if (key == null)
             this.month3_cnt_features = new UserActionFeature();
     }
 
 
-    public void setUser_cycle_bucket_7days(String key){
+    public void setUser_cycle_bucket_7days(String key) {
         this.user_cycle_bucket_7days = key;
-        if(key == null)
+        if (key == null)
             this.user_cycle_bucket_7days = "0";
     }
 
-    public void setUser_cycle_bucket_30days(String key){
+    public void setUser_cycle_bucket_30days(String key) {
         this.user_cycle_bucket_30days = key;
-        if(key == null)
+        if (key == null)
             this.user_cycle_bucket_30days = "0";
     }
 
-    public void setUser_share_bucket_30days(String key){
+    public void setUser_share_bucket_30days(String key) {
         this.user_share_bucket_30days = key;
-        if(key == null)
+        if (key == null)
             this.user_share_bucket_30days = "0";
     }
 
@@ -81,9 +78,22 @@ public class UserFeature {
         return this.uid;
     }
 
-    public String getValue(){
+    public String getValue() {
         Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
         return gson.toJson(this);
     }
 
+    public static UserFeature defaultInstance(String uid) {
+        UserFeature userFeature = new UserFeature();
+        userFeature.setUid(uid);
+        userFeature.setUser_share_bucket_30days(null);
+        userFeature.setUser_cycle_bucket_30days(null);
+        userFeature.setUser_cycle_bucket_7days(null);
+        userFeature.setMonth3_cnt_features(null);
+        userFeature.setDay7_cnt_features(null);
+        userFeature.setDay3_cnt_features(null);
+        userFeature.setDay1_cnt_features(null);
+        return userFeature;
+    }
+
 }

+ 4 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -164,6 +164,7 @@ public class RankService {
 
     private List<Video> mergeAndRankRovRecallNew(RankParam param) {
         UserFeature userFeature = featureRemoteService.getUserFeature(param.getUid());
+
         List<Video> recallVideos = param.getRecallResult().mergeRecallVideos();
         List<RankItem> rankItems = CommonCollectionUtils.toList(recallVideos, RankItem::new);
 
@@ -188,6 +189,9 @@ public class RankService {
 
     private ScoreParam convert(RankParam param) {
         ScoreParam scoreParam = new ScoreParam();
+
+        scoreParam.setUid(param.getUid());
+
         // TODO hardcode 为了兼容写入逻辑
         RequestContext context = new RequestContext();
         context.setApptype(param.getAppType() + "");

+ 1 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/ScoreParam.java

@@ -8,5 +8,6 @@ import lombok.Data;
  */
 @Data
 public class ScoreParam {
+    private String uid;
     private RequestContext requestContext;
 }

+ 6 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogShareLRScorer.java

@@ -3,7 +3,6 @@ package com.tzld.piaoquan.recommend.server.service.score;
 
 import com.tzld.piaoquan.recommend.server.common.base.*;
 import com.tzld.piaoquan.recommend.server.gen.recommend.LRSamples;
-import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
 import com.tzld.piaoquan.recommend.server.service.score.feature.VlogShareLRFeatureExtractor;
 import com.tzld.piaoquan.recommend.server.service.score.model.LRModel;
 import org.apache.commons.collections4.CollectionUtils;
@@ -39,7 +38,7 @@ public class VlogShareLRScorer extends BaseLRModelScorer {
                                   final UserFeature userFeature,
                                   final List<RankItem> rankItems) {
 
-        if (userFeature == null || CollectionUtils.isEmpty(rankItems)) {
+        if (CollectionUtils.isEmpty(rankItems)) {
             return rankItems;
         }
 
@@ -48,7 +47,8 @@ public class VlogShareLRScorer extends BaseLRModelScorer {
         LOGGER.debug("model size: [{}]", model.getModelSize());
 
         List<RankItem> result = rankItems;
-        result = rankByJava(rankItems, param.getRequestContext(), userFeature);
+        result = rankByJava(rankItems, param.getRequestContext(),
+                userFeature == null ? UserFeature.defaultInstance(param.getUid()) : userFeature);
 
         LOGGER.debug("ctr ranker time java items size={}, time={} ", result != null ? result.size() : 0,
                 System.currentTimeMillis() - startTime);
@@ -99,7 +99,9 @@ public class VlogShareLRScorer extends BaseLRModelScorer {
         bytesFeatureExtractor = new VlogShareLRFeatureExtractor();
 
         try {
-            VideoBytesFeature newsInfoBytes = new VideoBytesFeature(item.getItemFeature());
+            VideoBytesFeature newsInfoBytes = new VideoBytesFeature(item.getItemFeature() == null
+                    ? ItemFeature.defaultInstance(item.getVideoId() + "")
+                    : item.getItemFeature());
             lrSamples = bytesFeatureExtractor.single(userInfoBytes, newsInfoBytes,
                     new RequestContextBytesFeature(requestContext));
         } catch (Exception e) {