jch 1 місяць тому
батько
коміт
5b3982bed6

+ 22 - 31
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/FeatureService.java

@@ -274,37 +274,27 @@ public class FeatureService {
             protos.add(genWithKeyMap("scene_type_vid_cf_feature_20250212", vid, ImmutableMap.of("sence_type", senceType, "vid_a", headVid, "vid_b", vid)));
             protos.add(genWithKeyMap("vid_click_cf_feature_20250212", vid, ImmutableMap.of("vid_a", headVid, "vid_b", vid)));
             protos.add(genWithKeyMap("alg_recsys_feature_cf_i2i_v2", vid, ImmutableMap.of("vid_a", headVid, "vid_b", vid)));
-            if (null != videoBaseInfoMap && videoBaseInfoMap.containsKey(vid)) {
-                Map<String, Map<String, String>> videoInfo = videoBaseInfoMap.get(vid);
-                if (null != videoInfo && videoInfo.containsKey("alg_vid_feature_basic_info")) {
-                    Map<String, String> baseInfo = videoInfo.get("alg_vid_feature_basic_info");
-                    if (null != baseInfo) {
-                        String merge_cate1 = baseInfo.get("merge_first_level_cate");
-                        if (null != merge_cate1 && !merge_cate1.isEmpty()) {
-                            protos.add(genWithKeyMap("alg_merge_cate1_recommend_exp_feature_20250212", vid, ImmutableMap.of("merge_cate1", merge_cate1)));
-                            // 特殊情况
-                            protos.add(genWithKeyMap("mid_merge_cate1_feature_20250212", vid, ImmutableMap.of("mid", mid, "merge_cate1", merge_cate1)));
-                        }
-                        String merge_cate2 = baseInfo.get("merge_second_level_cate");
-                        if (null != merge_cate2 && !merge_cate2.isEmpty()) {
-                            protos.add(genWithKeyMap("alg_merge_cate2_recommend_exp_feature_20250212", vid, ImmutableMap.of("merge_cate2", merge_cate2)));
-                            // 特殊情况
-                            protos.add(genWithKeyMap("mid_u2u_friend_index_feature_20250212", vid, ImmutableMap.of("mid", mid, "merge_cate2", merge_cate2)));
-                        }
-                        String channel = baseInfo.get("channel");
-                        if (null != channel && !channel.isEmpty()) {
-                            protos.add(genWithKeyMap("alg_channel_recommend_exp_feature_20250212", vid, ImmutableMap.of("channel", channel)));
-                        }
-                        String festive = baseInfo.get("festive_label2");
-                        if (null != festive && !festive.isEmpty()) {
-                            protos.add(genWithKeyMap("alg_festive_recommend_exp_feature_20250212", vid, ImmutableMap.of("festive", festive)));
-                        }
-                        String videoUnionid = baseInfo.get("title_time_w_h_unionid");
-                        if (null != videoUnionid && !videoUnionid.isEmpty()) {
-                            protos.add(genWithKeyMap("alg_video_unionid_recommend_exp_feature_20250212", vid, ImmutableMap.of("video_unionid", videoUnionid)));
-                        }
-                    }
-                }
+            if (null != videoBaseInfoMap) {
+                Map<String, Map<String, String>> videoInfo = videoBaseInfoMap.getOrDefault(vid, new HashMap<>());
+                Map<String, String> baseInfo = videoInfo.getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
+                String merge_cate1 = baseInfo.getOrDefault("merge_first_level_cate", "unknown");
+                protos.add(genWithKeyMap("alg_merge_cate1_recommend_exp_feature_20250212", vid, ImmutableMap.of("merge_cate1", merge_cate1)));
+                // 特殊情况
+                protos.add(genWithKeyMap("mid_merge_cate1_feature_20250212", vid, ImmutableMap.of("mid", mid, "merge_cate1", merge_cate1)));
+
+                String merge_cate2 = baseInfo.getOrDefault("merge_second_level_cate", "unknown");
+                protos.add(genWithKeyMap("alg_merge_cate2_recommend_exp_feature_20250212", vid, ImmutableMap.of("merge_cate2", merge_cate2)));
+                // 特殊情况
+                protos.add(genWithKeyMap("mid_merge_cate2_feature_20250212", vid, ImmutableMap.of("mid", mid, "merge_cate2", merge_cate2)));
+
+                String channel = baseInfo.getOrDefault("channel", "unknown");
+                protos.add(genWithKeyMap("alg_channel_recommend_exp_feature_20250212", vid, ImmutableMap.of("channel", channel)));
+
+                String festive = baseInfo.getOrDefault("festive_label2", "unknown");
+                protos.add(genWithKeyMap("alg_festive_recommend_exp_feature_20250212", vid, ImmutableMap.of("festive", festive)));
+
+                String videoUnionid = baseInfo.getOrDefault("title_time_w_h_unionid", "unknown");
+                protos.add(genWithKeyMap("alg_video_unionid_recommend_exp_feature_20250212", vid, ImmutableMap.of("video_unionid", videoUnionid)));
             }
         }
 
@@ -321,6 +311,7 @@ public class FeatureService {
 
         // ********************* new mid ******************
         protos.add(genWithMid("mid_global_feature_20250212", mid));
+        protos.add(genWithMid("mid_u2u_friend_index_feature_20250212", mid));
         protos.add(genWithMid("alg_recsys_feature_user_share_return_stat", mid));
 
         return getFeatureByProto(protos);

+ 13 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/bo/UserSRBO.java

@@ -0,0 +1,13 @@
+package com.tzld.piaoquan.recommend.server.service.rank.bo;
+
+import lombok.Data;
+
+@Data
+public class UserSRBO {
+    // JSON_OBJECT("id",vid,"cnt",share_cnt,"ts",ts)
+    // JSON_OBJECT("id",vid,"uv",return_n_uv_noself,"ts",ts)
+    private long id;   // return vid
+    private long cnt;  // share cnt
+    private long uv;   // return uv
+    private long ts;   // view ts
+}

+ 73 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/bo/UserShareReturnProfile.java

@@ -0,0 +1,73 @@
+package com.tzld.piaoquan.recommend.server.service.rank.bo;
+
+import com.alibaba.fastjson.JSON;
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class UserShareReturnProfile {
+    private long s_pv;                  // share_pv(分享pv)
+    private long s_cnt;                 // share_cnt(分享次数)
+    private long r_pv;                  // return_pv(回流pv)
+    private long r_uv;                  // return_uv(回流uv)
+    private long m_s_cnt;               // max_share_cnt(最大分享次数)
+    private long m_r_uv;                // max_return_uv(最大回流uv)
+    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 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序列-回流率)
+    private Map<String, VideoAttrSRBO> l2_s;   // label2_seq(festive_label2序列-回流率)
+
+    public void setM_s_s(String data) {
+        this.m_s_s = JSON.parseArray(data, UserSRBO.class);
+    }
+
+    public void setM_r_s(String data) {
+        this.m_r_s = JSON.parseArray(data, UserSRBO.class);
+    }
+
+    public void setL_s_s(String data) {
+        this.l_s_s = JSON.parseArray(data, UserSRBO.class);
+    }
+
+    public void setL_r_s(String data) {
+        this.l_r_s = JSON.parseArray(data, UserSRBO.class);
+    }
+
+    public void setC1_s(String data) {
+        this.c1_s = parseVideoAttrSR(data);
+    }
+
+    public void setC2_s(String data) {
+        this.c2_s = parseVideoAttrSR(data);
+    }
+
+    public void setL1_s(String data) {
+        this.l1_s = parseVideoAttrSR(data);
+    }
+
+    public void setL2_s(String data) {
+        this.l2_s = parseVideoAttrSR(data);
+    }
+
+    private Map<String, VideoAttrSRBO> parseVideoAttrSR(String data) {
+        Map<String, VideoAttrSRBO> map = new HashMap<>();
+        if (null != data && !data.isEmpty()) {
+            List<VideoAttrSRBO> list = JSON.parseArray(data, VideoAttrSRBO.class);
+            if (null != list) {
+                for (VideoAttrSRBO v : list) {
+                    if (null != v) {
+                        map.put(v.getNa(), v);
+                    }
+                }
+            }
+        }
+        return map;
+    }
+}

+ 16 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/bo/VideoAttrSRBO.java

@@ -0,0 +1,16 @@
+package com.tzld.piaoquan.recommend.server.service.rank.bo;
+
+import lombok.Data;
+
+@Data
+public class VideoAttrSRBO {
+    // JSON_OBJECT("na",cate1,"sp",share_pv,"rp",return_n_pv_noself,"ru",return_n_uv_noself,"mu",max_return_uv)
+    // JSON_OBJECT("na",cate2,"sp",share_pv,"rp",return_n_pv_noself,"ru",return_n_uv_noself,"mu",max_return_uv)
+    // JSON_OBJECT("na",label1,"sp",share_pv,"rp",return_n_pv_noself,"ru",return_n_uv_noself,"mu",max_return_uv)
+    // JSON_OBJECT("na",label2,"sp",share_pv,"rp",return_n_pv_noself,"ru",return_n_uv_noself,"mu",max_return_uv)
+    private String na;  // attr name
+    private long sp;    // share_pv
+    private long rp;    // return_n_pv_noself
+    private long ru;    // return_n_uv_noself
+    private long mu;    // max_return_uv
+}

+ 155 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/strategy/RankStrategy4RegionMergeModelV564.java

@@ -1,15 +1,21 @@
 package com.tzld.piaoquan.recommend.server.service.rank.strategy;
 
+import com.alibaba.fastjson.JSON;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
 import com.tzld.piaoquan.recommend.server.common.base.RankItem;
 import com.tzld.piaoquan.recommend.server.model.Video;
 import com.tzld.piaoquan.recommend.server.service.FeatureService;
 import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
+import com.tzld.piaoquan.recommend.server.service.rank.bo.UserSRBO;
+import com.tzld.piaoquan.recommend.server.service.rank.bo.UserShareReturnProfile;
 import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
+import com.tzld.piaoquan.recommend.server.service.rank.tansform.NORFeature;
 import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
 import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
 import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
+import com.tzld.piaoquan.recommend.server.util.FeatureBucketUtils;
+import com.tzld.piaoquan.recommend.server.util.JSONUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.math3.util.Pair;
@@ -38,6 +44,7 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         //-------------------逻-------------------
         //-------------------辑-------------------
 
+        long currentMs = System.currentTimeMillis();
         List<Video> oldRovs = new ArrayList<>();
         oldRovs.addAll(extractAndSort(param, RegionHRecallStrategy.PUSH_FORM));
         oldRovs.addAll(extractAndSort(param, RegionHDupRecallStrategy.PUSH_FORM));
@@ -94,6 +101,11 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         Map<String, Map<String, Map<String, String>>> featureOriginVideo = feature.getVideoFeature();
         Map<String, String> headVideoInfo = videoBaseInfoMap.getOrDefault(headVid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
 
+        // 用户信息预处理
+        Map<String, Map<String, String[]>> newC7Map = NORFeature.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_sharecf", new HashMap<>()));
+        Map<String, Map<String, String[]>> newC8Map = NORFeature.parseUCFScore(featureOriginUser.getOrDefault("alg_mid_feature_returncf", new HashMap<>()));
+        UserShareReturnProfile userProfile = parseUserProfile(featureOriginUser);
+        Map<String, Map<String, String>> userBehaviorVideoMap = getUserBehaviorVideoMap(userProfile);
 
         // 2 特征处理
         Map<String, Double> userFeatureMapDouble = new HashMap<>();
@@ -281,6 +293,11 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             item.featureMapDouble = featureMap;
         }
 
+        // get nor feature
+        Map<String, String> norUserFeatureMap = getNorUserFeature(currentMs, headVideoInfo, userProfile, featureOriginUser);
+        batchGetNorVideoFeature(currentMs, userProfile, headVideoInfo, videoBaseInfoMap,
+                newC7Map, newC8Map, featureOriginUser, userBehaviorVideoMap, featureOriginVideo, rankItems);
+
         // 3 连续值特征分桶
         readBucketFile();
         Map<String, String> userFeatureMap = new HashMap<>(userFeatureMapDouble.size());
@@ -313,8 +330,10 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             item.featureMap = featureMap;
         }
         // 4 排序模型计算
+        double xgbNorPowerWeight = mergeWeight.getOrDefault("xgbNorPowerWeight", 1.22);
+        double xgbNorPowerExp = mergeWeight.getOrDefault("xgbNorPowerExp", 1.24);
         Map<String, String> sceneFeatureMap = new HashMap<>(0);
-        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_20240807.conf").scoring(sceneFeatureMap, userFeatureMap, rankItems);
+        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_fm_xgb_20250221.conf").scoring(sceneFeatureMap, userFeatureMap, norUserFeatureMap, rankItems);
         // 5 排序公式特征
         Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, "redis:vid_hasreturn_vor:");
         List<Video> result = new ArrayList<>();
@@ -326,9 +345,11 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
             item.getScoresMap().put("fmRov", fmRov);
             double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("rov", "0"));
             item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
+            double norXGBScore = item.getScoresMap().getOrDefault("NorXGBScore", 0d);
+            double newNorXGBScore = norPowerCalibration(xgbNorPowerWeight, xgbNorPowerExp, norXGBScore);
             double vor = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("vor", "0"));
             item.getScoresMap().put("vor", vor);
-            score = fmRov * (0.1 + hasReturnRovScore) * (0.1 + vor);
+            score = fmRov * (0.1 + newNorXGBScore) * (0.1 + vor);
             Video video = item.getVideo();
             video.setScore(score);
             video.setSortScore(score);
@@ -351,4 +372,136 @@ public class RankStrategy4RegionMergeModelV564 extends RankStrategy4RegionMergeM
         result.sort(Comparator.comparingDouble(o -> -o.getSortScore()));
         return result;
     }
+
+    private UserShareReturnProfile parseUserProfile(Map<String, Map<String, String>> userOriginInfo) {
+        if (null != userOriginInfo) {
+            Map<String, String> c9 = userOriginInfo.get("alg_recsys_feature_user_share_return_stat");
+            if (null != c9 && !c9.isEmpty()) {
+                String c9Str = JSONUtils.toJson(c9);
+                if (!c9Str.isEmpty()) {
+                    try {
+                        return JSON.parseObject(c9Str, UserShareReturnProfile.class);
+                    } catch (Exception e) {
+                        log.error("parseObject user profile error! value=[{}]", c9Str, e);
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    private Map<String, Map<String, String>> getUserBehaviorVideoMap(UserShareReturnProfile userProfile) {
+        Set<String> vidSet = new HashSet<>();
+        if (null != userProfile) {
+            for (List<UserSRBO> list : Arrays.asList(userProfile.getM_s_s(), userProfile.getM_r_s(), userProfile.getL_s_s(), userProfile.getL_r_s())) {
+                if (null != list) {
+                    for (UserSRBO u : list) {
+                        if (null != u) {
+                            vidSet.add(u.getId() + "");
+                        }
+                    }
+                }
+            }
+        }
+
+        Map<String, Map<String, String>> historyVideoMap = new HashMap<>();
+        if (!vidSet.isEmpty()) {
+            Map<String, Map<String, Map<String, String>>> videoMap = featureService.getVideoBaseInfo("", new ArrayList<>(vidSet));
+            if (null != videoMap && !videoMap.isEmpty()) {
+                for (Map.Entry<String, Map<String, Map<String, String>>> entry : videoMap.entrySet()) {
+                    String vid = entry.getKey();
+                    Map<String, Map<String, String>> map = entry.getValue();
+                    if (null != map && map.containsKey("alg_vid_feature_basic_info")) {
+                        historyVideoMap.put(vid, map.get("alg_vid_feature_basic_info"));
+                    }
+                }
+            }
+        }
+        return historyVideoMap;
+    }
+
+    private Map<String, String> getNorUserFeature(long currentMs, Map<String, String> headInfo, UserShareReturnProfile userProfile, Map<String, Map<String, String>> userOriginInfo) {
+        Map<String, Double> featMap = new HashMap<>();
+        // context feature
+        NORFeature.getContextFeature(currentMs, featMap);
+
+        // head video feature
+        NORFeature.getVideoBaseFeature("h", currentMs, headInfo, featMap);
+
+        // user feature
+        NORFeature.getUserFeature(userOriginInfo, featMap);
+        NORFeature.getUserProfileFeature(userProfile, featMap);
+
+        return FeatureBucketUtils.noBucketFeature(featMap);
+    }
+
+    private Map<String, String> getNorVideoFeature(long currentMs, String vid,
+                                                   UserShareReturnProfile userProfile,
+                                                   Map<String, String> headInfo, Map<String, String> rankInfo,
+                                                   Map<String, Map<String, String[]>> c7Map,
+                                                   Map<String, Map<String, String[]>> c8Map,
+                                                   Map<String, Map<String, String>> userOriginInfo,
+                                                   Map<String, Map<String, String>> historyVideoMap,
+                                                   Map<String, Map<String, Map<String, String>>> videoOriginInfo) {
+        Map<String, Double> featMap = new HashMap<>();
+        // user & video feature
+        NORFeature.getUserTagsCrossVideoFeature("c5", rankInfo, userOriginInfo.get("alg_mid_feature_return_tags"), featMap);
+        NORFeature.getUserTagsCrossVideoFeature("c6", rankInfo, userOriginInfo.get("alg_mid_feature_share_tags"), featMap);
+        NORFeature.getUserCFFeature("c7", vid, c7Map, featMap);
+        NORFeature.getUserCFFeature("c8", vid, c8Map, featMap);
+
+        // rank video feature
+        NORFeature.getVideoBaseFeature("r", currentMs, rankInfo, featMap);
+        NORFeature.getVideoFeature(vid, videoOriginInfo, featMap);
+
+        // head&rank cross feature
+        NORFeature.getHeadRankVideoCrossFeature(headInfo, rankInfo, featMap);
+
+        // user profile & rank cross
+        NORFeature.getProfileVideoCrossFeature(currentMs, userProfile, rankInfo, historyVideoMap, featMap);
+
+        return FeatureBucketUtils.noBucketFeature(featMap);
+    }
+
+    private void batchGetNorVideoFeature(long currentMs,
+                                         UserShareReturnProfile userProfile,
+                                         Map<String, String> headInfo,
+                                         Map<String, Map<String, Map<String, String>>> videoBaseInfoMap,
+                                         Map<String, Map<String, String[]>> c7Map,
+                                         Map<String, Map<String, String[]>> c8Map,
+                                         Map<String, Map<String, String>> userOriginInfo,
+                                         Map<String, Map<String, String>> historyVideoMap,
+                                         Map<String, Map<String, Map<String, String>>> videoOriginInfo,
+                                         List<RankItem> rankItems) {
+        if (null != rankItems && !rankItems.isEmpty()) {
+            List<Future<Integer>> futures = new ArrayList<>();
+            for (RankItem item : rankItems) {
+                String vid = item.getVideoId() + "";
+                Map<String, String> rankInfo = videoBaseInfoMap.getOrDefault(vid, new HashMap<>()).getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
+                Future<Integer> future = ThreadPoolFactory.defaultPool().submit(() -> {
+                    item.norFeatureMap = getNorVideoFeature(currentMs, vid, userProfile, headInfo, rankInfo, c7Map, c8Map, userOriginInfo, historyVideoMap, videoOriginInfo);
+                    return 1;
+                });
+                futures.add(future);
+            }
+
+            try {
+                for (Future<Integer> future : futures) {
+                    future.get(1000, TimeUnit.MILLISECONDS);
+                }
+            } catch (Exception e) {
+                log.error("get nor feature error", e);
+            }
+        }
+    }
+
+    private double norPowerCalibration(double weight, double exp, double score) {
+        double newScore = weight * Math.pow(score, exp);
+        if (newScore > 100) {
+            newScore = 100;
+        } else if (newScore < score) {
+            newScore = score;
+        }
+        return newScore;
+    }
 }

+ 421 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/tansform/NORFeature.java

@@ -0,0 +1,421 @@
+package com.tzld.piaoquan.recommend.server.service.rank.tansform;
+
+import com.tzld.piaoquan.recommend.server.service.rank.bo.UserSRBO;
+import com.tzld.piaoquan.recommend.server.service.rank.bo.UserShareReturnProfile;
+import com.tzld.piaoquan.recommend.server.service.rank.bo.VideoAttrSRBO;
+import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
+import com.tzld.piaoquan.recommend.server.util.FeatureUtils;
+import com.tzld.piaoquan.recommend.server.util.SimilarityUtils;
+
+import java.util.*;
+
+public class NORFeature {
+    private static final int seqMaxN = 2;
+    private static final int seqLastN = 2;
+    private static final double smoothPlus = 5.0;
+    private static final List<String> c1Periods = Arrays.asList("72h", "168h");
+    private static final List<String> c4Periods = Arrays.asList("72h", "168h");
+    private static final List<String> b1Periods = Arrays.asList("1h", "3h", "24h", "72h", "168h");
+    private static final List<String> b2Periods = Arrays.asList("1h", "3h", "24h");
+    private static final List<String> b3Periods = Arrays.asList("24h", "168h");
+    private static final List<String> b4Periods = Arrays.asList("1h", "12h");
+    private static final List<String> b5Periods = Arrays.asList("72h", "168h");
+    private static final List<String> b6Periods = Arrays.asList("1h", "24h");
+    private static final List<String> b7Periods = Arrays.asList("24h", "168h");
+    private static final List<String> b8Periods = Arrays.asList("24h");
+    private static final List<String> b9Periods = Arrays.asList("24h");
+    private static final List<String> b10Periods = Arrays.asList("1h", "12h");
+    private static final List<String> b11Periods = Arrays.asList("12h", "168h");
+    private static final List<String> b13Periods = Arrays.asList("24h", "168h");
+    private static final List<String> dayPeriods = Arrays.asList("7d", "14d", "30d", "60d");
+    private static final List<String> videoCateAttrs = Arrays.asList(FeatureUtils.cate1Attr, FeatureUtils.cate2Attr, FeatureUtils.festive1Attr);
+    private static final List<String> videoSimAttrs = Arrays.asList("title", "cate2", "cate2_list", "keywords");
+    private static final List<String> hVideoSimAttrs = Arrays.asList("title");
+    private static final List<String> cfList = Arrays.asList("share", "return");
+
+    public static void getContextFeature(long currentMs, Map<String, Double> featureMap) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTimeInMillis(currentMs);
+
+        int week = calendar.get(Calendar.DAY_OF_WEEK);
+        int hour = calendar.get(Calendar.HOUR_OF_DAY) + 1;
+        featureMap.put("week", week * 1.0);
+        featureMap.put("hour", hour * 1.0);
+    }
+
+    public static void getUserFeature(Map<String, Map<String, String>> userOriginInfo, Map<String, Double> featMap) {
+        oneTypeStatFeature("c1", "return_1_uv", c1Periods, userOriginInfo.get("mid_global_feature_20250212"), featMap);
+        Map<String, String> c4Map = userOriginInfo.get("mid_u2u_friend_index_feature_20250212");
+        for (String calType : Arrays.asList("avg_", "max_", "min_")) {
+            getRateStatFeature("c4", calType, c4Periods, c4Map, featMap);
+        }
+    }
+
+    public static void getUserProfileFeature(UserShareReturnProfile profile, Map<String, Double> featMap) {
+        if (null != profile) {
+            long s_pv = profile.getS_pv();              // share_pv(分享pv)
+            long s_cnt = profile.getS_cnt();            // share_cnt(分享次数)
+            long r_pv = profile.getR_pv();              // return_pv(回流pv)
+            long r_uv = profile.getR_uv();              // return_uv(回流uv)
+            long m_s_cnt = profile.getM_s_cnt();        // max_share_cnt(最大分享次数)
+            long m_r_uv = profile.getM_r_uv();          // max_return_uv(最大回流uv)
+            if (s_pv > 0) {
+                double s_pv_s = FeatureUtils.log1(s_pv);
+                double s_cnt_s = FeatureUtils.log1(s_cnt);
+                double r_pv_s = FeatureUtils.log1(r_pv);
+                double r_uv_s = FeatureUtils.log1(r_uv);
+                double m_s_cnt_s = FeatureUtils.log1(m_s_cnt);
+                double m_r_uv_s = FeatureUtils.log1(m_r_uv);
+                double ros_one = FeatureUtils.wilsonScore(r_pv, s_pv);
+                double ros = FeatureUtils.plusSmooth(r_uv, s_pv, smoothPlus);
+                double ros_minus = FeatureUtils.plusSmooth(r_uv, r_pv, smoothPlus);
+                featMap.put("c9_s_pv", s_pv_s);
+                featMap.put("c9_s_cnt", s_cnt_s);
+                featMap.put("c9_r_pv", r_pv_s);
+                featMap.put("c9_r_uv", r_uv_s);
+                featMap.put("c9_m_s_cnt", m_s_cnt_s);
+                featMap.put("c9_m_r_uv", m_r_uv_s);
+                featMap.put("c9_ros_one", ros_one);
+                featMap.put("c9_ros", ros);
+                featMap.put("c9_ros_minus", ros_minus);
+            }
+        }
+    }
+
+    public static void getUserTagsCrossVideoFeature(String prefix, Map<String, String> videoInfo, Map<String, String> infoMap, Map<String, Double> featMap) {
+        if (null == videoInfo || videoInfo.isEmpty() || null == infoMap || infoMap.isEmpty()) {
+            return;
+        }
+        String title = videoInfo.getOrDefault("title", "");
+        if (title.isEmpty()) {
+            return;
+        }
+        for (String period : Arrays.asList("tags_1d", "tags_3d", "tags_7d")) {
+            String tags = infoMap.getOrDefault(period, "");
+            if (!tags.isEmpty()) {
+                Double[] doubles = ExtractorUtils.funcC34567ForTagsNew(tags, title);
+                featMap.put(prefix + "_" + period + "_matchnum", doubles[0]);
+                featMap.put(prefix + "_" + period + "_maxscore", doubles[1]);
+                featMap.put(prefix + "_" + period + "_avgscore", doubles[2]);
+            }
+        }
+    }
+
+    public static void getUserCFFeature(String prefix, String vid, Map<String, Map<String, String[]>> infoMap, Map<String, Double> featMap) {
+        if (vid.isEmpty() || null == infoMap || infoMap.isEmpty()) {
+            return;
+        }
+        for (String cfType : cfList) {
+            if (infoMap.containsKey(cfType)) {
+                Map<String, String[]> cfScoresMap = infoMap.get(cfType);
+                if (null != cfScoresMap && cfScoresMap.containsKey(vid)) {
+                    String[] scores = cfScoresMap.get(vid);
+                    Double score1 = Double.parseDouble(scores[0]);
+                    Double score2 = Double.parseDouble(scores[1]);
+                    Double score3 = Double.parseDouble(scores[2]) <= 0 ? 0D : 1.0 / Double.parseDouble(scores[2]);
+                    featMap.put(prefix + "_" + cfType + "_score", score1);
+                    featMap.put(prefix + "_" + cfType + "_num", score2);
+                    featMap.put(prefix + "_" + cfType + "_rank", score3);
+                }
+            }
+        }
+    }
+
+    public static void getVideoFeature(String vid, Map<String, Map<String, Map<String, String>>> videoOriginInfo, Map<String, Double> featMap) {
+        oneTypeStatFeature("b1", "return_1_uv", b1Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_global_feature_20250212"), featMap);
+        oneTypeStatFeature("b2", "return_n_uv", b2Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b3", "return_n_uv", b3Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_recommend_flowpool_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b4", "return_n_uv", b4Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_apptype_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b5", "return_n_uv", b5Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_province_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b6", "return_n_uv", b6Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_brand_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b7", "return_n_uv", b7Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_hotsencetype_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b8", "return_n_uv", b8Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_merge_cate1_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b9", "return_n_uv", b9Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_merge_cate2_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b10", "return_n_uv", b10Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_channel_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b11", "return_n_uv", b11Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_festive_recommend_exp_feature_20250212"), featMap);
+        //getRateStatFeature("b12", "", dayPeriods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_vid_long_period_recommend_exp_feature_20250212"), featMap);
+        oneTypeStatFeature("b13", "return_n_uv", b13Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_video_unionid_recommend_exp_feature_20250212"), featMap);
+
+        // head video cf
+        headVideoCFD1Feature("d1", videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("scene_type_vid_cf_feature_20250212"), featMap);
+        headVideoCFD2Feature("d2", videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("vid_click_cf_feature_20250212"), featMap);
+        headVideoCFD3Feature("d3", videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("alg_recsys_feature_cf_i2i_v2"), featMap);
+
+        // 特殊mid * cate
+        oneTypeStatFeature("c2", "return_n_uv", c1Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("mid_merge_cate1_feature_20250212"), featMap);
+        oneTypeStatFeature("c3", "return_n_uv", c1Periods, videoOriginInfo.getOrDefault(vid, new HashMap<>()).get("mid_merge_cate2_feature_20250212"), featMap);
+    }
+
+    public static void getVideoBaseFeature(String prefix, long currentMs, Map<String, String> videoInfo, Map<String, Double> featMap) {
+        if (null == videoInfo || videoInfo.isEmpty()) {
+            return;
+        }
+        featMap.put(prefix + "@total_time", Double.parseDouble(videoInfo.getOrDefault("total_time", "0")));
+        featMap.put(prefix + "@bit_rate", Double.parseDouble(videoInfo.getOrDefault("bit_rate", "0")));
+
+        // cate
+        // getVideoCateFeature(prefix, videoInfo, featMap);
+        if (videoInfo.containsKey("title")) {
+            int id = FeatureUtils.judgeVideoTimeType(videoInfo.get("title"));
+            if (id > 0) {
+                String key = String.format("%s@%s@%d", prefix, "tt", id);
+                featMap.put(key, 1.0);
+            }
+        }
+
+        // time
+        try {
+            if (videoInfo.containsKey("gmt_create_timestamp")) {
+                String createMsStr = videoInfo.get("gmt_create_timestamp");
+                long createMs = Long.parseLong(createMsStr);
+                double createTime = FeatureUtils.getTimeDiff(currentMs, createMs);
+                featMap.put(prefix + "@ts", 1 - createTime);
+            }
+        } catch (Exception ignored) {
+        }
+    }
+
+    public static void getHeadRankVideoCrossFeature(Map<String, String> headInfo, Map<String, String> rankInfo, Map<String, Double> featMap) {
+        getTwoVideoCrossFeature("hr_sim", NORFeature.videoSimAttrs, headInfo, rankInfo, featMap);
+    }
+
+    public static void getProfileVideoCrossFeature(long currentMs, UserShareReturnProfile profile, Map<String, String> rankVideo, Map<String, Map<String, String>> hVideoMap, Map<String, Double> featMap) {
+        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);
+
+        if (null == rankVideo || rankVideo.isEmpty()) {
+            return;
+        }
+        getVideoAttrSRCrossFeature("c9_c1s", rankVideo.getOrDefault("merge_first_level_cate", ""), profile.getC1_s(), featMap);
+        getVideoAttrSRCrossFeature("c9_c2s", rankVideo.getOrDefault("merge_second_level_cate", ""), profile.getC2_s(), featMap);
+        getVideoAttrSRCrossFeature("c9_l1s", rankVideo.getOrDefault("festive_label1", ""), profile.getL1_s(), featMap);
+        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) {
+        if (null != list && !list.isEmpty()) {
+            for (int i = 0; i < list.size() && i < maxN; i++) {
+                UserSRBO u = list.get(i);
+                if (null != u) {
+                    long id = u.getId();
+                    long cnt = u.getCnt();
+                    long uv = u.getUv();
+                    long ts = u.getTs();
+                    if (id > 0) {
+                        String vid = id + "";
+                        String baseKey = String.format("%s@%d", prefix, i + 1);
+                        if (cnt > 0) {
+                            featMap.put(baseKey + "@cnt", FeatureUtils.log1(cnt));
+                        }
+                        if (uv > 0) {
+                            featMap.put(baseKey + "@uv", FeatureUtils.log1(uv));
+                        }
+                        if (ts > 0) {
+                            featMap.put(baseKey + "@ts", 1 - FeatureUtils.getTimeDiff(currentMs, ts * 1000));
+                        }
+                        if (null != hVideoMap && hVideoMap.containsKey(vid)) {
+                            Map<String, String> hVideo = hVideoMap.get(vid);
+                            //getVideoCateFeature(baseKey, hVideo, featMap);
+                            getTwoVideoCrossFeature(baseKey, hVideoSimAttrs, hVideo, rankVideo, featMap);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private static void getVideoAttrSRCrossFeature(String prefix, String attr, Map<String, VideoAttrSRBO> attrMap, Map<String, Double> featMap) {
+        if (null == attrMap || attrMap.isEmpty()) {
+            return;
+        }
+        if (attrMap.containsKey(attr)) {
+            VideoAttrSRBO bo = attrMap.get(attr);
+            if (null != bo) {
+                long sp = bo.getSp();    // share_pv
+                long rp = bo.getRp();    // return_n_pv_noself
+                long ru = bo.getRu();    // return_n_uv_noself
+                long mu = bo.getMu();    // max_return_uv
+                if (sp > 0) {
+                    double sp_s = FeatureUtils.log1(sp);
+                    double rp_s = FeatureUtils.log1(rp);
+                    double ru_s = FeatureUtils.log1(ru);
+                    double mu_s = FeatureUtils.log1(mu);
+
+                    double ros_one = FeatureUtils.wilsonScore(rp, sp);
+                    double ros = FeatureUtils.plusSmooth(ru, sp, smoothPlus);
+                    double ros_minus = FeatureUtils.plusSmooth(ru, rp, smoothPlus);
+
+                    featMap.put(prefix + "@sp", sp_s);
+                    featMap.put(prefix + "@rp", rp_s);
+                    featMap.put(prefix + "@ru", ru_s);
+                    featMap.put(prefix + "@mu", mu_s);
+                    featMap.put(prefix + "@ros_one", ros_one);
+                    featMap.put(prefix + "@ros", ros);
+                    featMap.put(prefix + "@ros_minus", ros_minus);
+                }
+            }
+        }
+    }
+
+    private static void getVideoCateFeature(String prefix, Map<String, String> videoInfo, Map<String, Double> featMap) {
+        if (null == videoInfo || videoInfo.isEmpty()) {
+            return;
+        }
+        for (String attr : videoCateAttrs) {
+            String attrVal = videoInfo.getOrDefault(attr, "");
+            int attrId = FeatureUtils.getAttrId(attr, attrVal);
+            if (attrId > 0) {
+                String key = String.format("%s@%s@%d", prefix, attr, attrId);
+                featMap.put(key, 1.0);
+            }
+        }
+    }
+
+    private static void getTwoVideoCrossFeature(String prefix, List<String> attrs, Map<String, String> video1, Map<String, String> video2, Map<String, Double> featMap) {
+        if (null == video1 || video1.isEmpty() || null == video2 || video2.isEmpty()) {
+            return;
+        }
+        for (String attr : attrs) {
+            String attr1 = video1.getOrDefault(attr, "");
+            String attr2 = video2.getOrDefault(attr, "");
+            if (!"".equals(attr1) && !"unknown".equals(attr1) && !"".equals(attr2) && !"unknown".equals(attr2)) {
+                double simScore = SimilarityUtils.word2VecSimilarity(attr1, attr2);
+                featMap.put(prefix + "_" + attr, simScore);
+            }
+        }
+    }
+
+    private static void headVideoCFD1Feature(String prefix, Map<String, String> infoMap, Map<String, Double> featMap) {
+        double ros_cf_score = getOneInfo("ros_cf_score", infoMap);
+        double ros_cf_rank = getOneInfo("ros_cf_rank", infoMap);
+        double rov_cf_score = getOneInfo("rov_cf_score", infoMap);
+        double rov_cf_rank = getOneInfo("rov_cf_rank", infoMap);
+        featMap.put(prefix + "_ros_cf_score", ros_cf_score);
+        featMap.put(prefix + "_ros_cf_rank", ros_cf_rank);
+        featMap.put(prefix + "_rov_cf_score", rov_cf_score);
+        featMap.put(prefix + "_rov_cf_rank", rov_cf_rank);
+    }
+
+    private static void headVideoCFD2Feature(String prefix, Map<String, String> infoMap, Map<String, Double> featMap) {
+        double score = getOneInfo("score", infoMap);
+        double rank = getOneInfo("rank", infoMap);
+        double onlines = getOneInfo("onlines", infoMap);
+        featMap.put(prefix + "_score", score);
+        featMap.put(prefix + "_rank", rank);
+        featMap.put(prefix + "_onlines", onlines);
+    }
+
+    private static void headVideoCFD3Feature(String prefix, Map<String, String> infoMap, Map<String, Double> featMap) {
+        double exp = getOneInfo("exp", infoMap);
+        double return_n = getOneInfo("return_n", infoMap);
+        double rovn = getOneInfo("rovn", infoMap);
+        featMap.put(prefix + "_exp", FeatureUtils.log1(exp));
+        featMap.put(prefix + "_return_n", FeatureUtils.log1(return_n));
+        featMap.put(prefix + "_rovn", rovn);
+    }
+
+    public static Map<String, Map<String, String[]>> parseUCFScore(Map<String, String> mapInfo) {
+        Map<String, Map<String, String[]>> allScoresMap = new HashMap<>();
+        for (String cfType : cfList) {
+            String data = mapInfo.getOrDefault(cfType, "");
+            if (!data.isEmpty()) {
+                Map<String, String[]> oneScoresMap = new HashMap<>();
+                String[] entries = data.split(",");
+                for (String entry : entries) {
+                    String[] rList = entry.split(":");
+                    if (rList.length >= 4) { // 确保分割后有四个元素
+                        String key = rList[0];
+                        String value1 = rList[1];
+                        String value2 = rList[2];
+                        String value3 = rList[3];
+                        String[] strs = {value1, value2, value3};
+                        oneScoresMap.put(key, strs);
+                    }
+                }
+                if (!oneScoresMap.isEmpty()) {
+                    allScoresMap.put(cfType, oneScoresMap);
+                }
+            }
+        }
+        return allScoresMap;
+    }
+
+    private static void getRateStatFeature(String prefix, String calType, List<String> periods, Map<String, String> infoMap, Map<String, Double> featMap) {
+        if (null == infoMap || infoMap.isEmpty()) {
+            return;
+        }
+        for (String period : periods) {
+            double str_one = getOneInfo(calType + "str_one_" + period, infoMap);
+            double ros_one = getOneInfo(calType + "ros_one_" + period, infoMap);
+            double str = getOneInfo(calType + "str_" + period, infoMap);
+            double ros = getOneInfo(calType + "ros_" + period, infoMap);
+            double str_plus = getOneInfo(calType + "str_plus_" + period, infoMap);
+            double ros_minus = getOneInfo(calType + "ros_minus_" + period, infoMap);
+            double rovn = getOneInfo(calType + "rovn_" + period, infoMap);
+
+            featMap.put(prefix + "_" + period + "_" + calType + "str_one", str_one);
+            featMap.put(prefix + "_" + period + "_" + calType + "ros_one", ros_one);
+            featMap.put(prefix + "_" + period + "_" + calType + "str", str);
+            featMap.put(prefix + "_" + period + "_" + calType + "ros", ros);
+            featMap.put(prefix + "_" + period + "_" + calType + "str_plus", str_plus);
+            featMap.put(prefix + "_" + period + "_" + calType + "ros_minus", ros_minus);
+            featMap.put(prefix + "_" + period + "_" + calType + "rovn", rovn);
+        }
+    }
+
+    private static void oneTypeStatFeature(String prefix, String uvPrefix, List<String> periods, Map<String, String> infoMap, Map<String, Double> featMap) {
+        if (null == infoMap || infoMap.isEmpty()) {
+            return;
+        }
+        for (String period : periods) {
+            double exp = getOneInfo("exp_" + period, infoMap);
+            if (!FeatureUtils.greaterThanZero(exp)) {
+                continue;
+            }
+            double is_share = getOneInfo("is_share_" + period, infoMap);
+            double share_cnt = getOneInfo("share_cnt_" + period, infoMap);
+            double is_return_1 = getOneInfo("is_return_1_" + period, infoMap);
+            double return_n_uv = getOneInfo(uvPrefix + "_" + period, infoMap);
+
+            double exp_s = FeatureUtils.log1(exp);
+            double is_share_s = FeatureUtils.log1(is_share);
+            double share_cnt_s = FeatureUtils.log1(share_cnt);
+            double is_return_1_s = FeatureUtils.log1(is_return_1);
+            double return_n_uv_s = FeatureUtils.log1(return_n_uv);
+
+            double str = FeatureUtils.wilsonScore(is_share, exp);
+            double str_plus = FeatureUtils.wilsonScore(is_return_1, exp);
+            double ros_one = FeatureUtils.wilsonScore(is_return_1, is_share);
+
+            double rovn = FeatureUtils.plusSmooth(return_n_uv, exp, smoothPlus);
+            double ros = FeatureUtils.plusSmooth(return_n_uv, is_share, smoothPlus);
+            double ros_n = FeatureUtils.plusSmooth(return_n_uv, share_cnt, smoothPlus);
+            double ros_minus = FeatureUtils.plusSmooth(return_n_uv, is_return_1, smoothPlus);
+
+            featMap.put(prefix + "_" + period + "_" + "exp", exp_s);
+            featMap.put(prefix + "_" + period + "_" + "is_share", is_share_s);
+            featMap.put(prefix + "_" + period + "_" + "share_cnt", share_cnt_s);
+            featMap.put(prefix + "_" + period + "_" + "is_return_1", is_return_1_s);
+            featMap.put(prefix + "_" + period + "_" + "return_n_uv", return_n_uv_s);
+            featMap.put(prefix + "_" + period + "_" + "str", str);
+            featMap.put(prefix + "_" + period + "_" + "str_plus", str_plus);
+            featMap.put(prefix + "_" + period + "_" + "ros_one", ros_one);
+            featMap.put(prefix + "_" + period + "_" + "rovn", rovn);
+            featMap.put(prefix + "_" + period + "_" + "ros", ros);
+            featMap.put(prefix + "_" + period + "_" + "ros_n", ros_n);
+            featMap.put(prefix + "_" + period + "_" + "ros_minus", ros_minus);
+        }
+    }
+
+    private static double getOneInfo(String name, Map<String, String> map) {
+        if (null == map) {
+            return 0.0;
+        }
+        return map.isEmpty() ? 0 : Double.parseDouble(map.getOrDefault(name, "0.0"));
+    }
+}

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

@@ -34,7 +34,7 @@ public final class ScorerUtils {
         ScorerUtils.init("feeds_score_config_20240807.conf");
         ScorerUtils.init("feeds_score_config_fm_xgb_20241209.conf");
         ScorerUtils.init("feeds_score_config_fm_xgb_20250208.conf");
-        ScorerUtils.init("feeds_score_config_fm_xgb_20250218.conf");
+        ScorerUtils.init("feeds_score_config_fm_xgb_20250221.conf");
         ScorerUtils.init("feeds_score_config_xgb_20241209.conf");
         ScorerUtils.init("feeds_score_config_xgb_20250109.conf");
         ScorerUtils.init("feeds_score_config_xgb_rov_20241209.conf");

+ 65 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/util/FeatureUtils.java

@@ -2,6 +2,8 @@ package com.tzld.piaoquan.recommend.server.util;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 public class FeatureUtils {
     public static final String cate1Attr = "cate1_list";
@@ -10,7 +12,14 @@ public class FeatureUtils {
     private static final Map<String, Integer> cate1MAP = new HashMap<>();
     private static final Map<String, Integer> cate2MAP = new HashMap<>();
     private static final Map<String, Integer> festive1Map = new HashMap<>();
-    public static final double oneYearMs = 365 * 24 * 3600 * 1000.0;
+    public static final double twoMonthMs = 2 * 30 * 24 * 3600 * 1000.0;
+
+    private static final String goodMorningRegex = "(早安|早上好|早晨好|上午好)";
+    private static final String goodAfternoonRegex = "(午安|中午好|下午好)";
+    private static final String goodEveningRegex = "(晚安|晚上好)";
+    private static final Pattern goodMorningPattern = Pattern.compile(goodMorningRegex);
+    private static final Pattern goodAfternoonPattern = Pattern.compile(goodAfternoonRegex);
+    private static final Pattern goodEveningPattern = Pattern.compile(goodEveningRegex);
 
     static {
         cate1MAP.put("情感", 1);
@@ -77,11 +86,64 @@ public class FeatureUtils {
         }
     }
 
-    public static double getCreateTime(long currentMs, long createMs) {
-        double diff = (currentMs - createMs) / oneYearMs;
+    public static int judgeVideoTimeType(String s) {
+        if (null != s && !s.isEmpty()) {
+            Matcher morning = goodMorningPattern.matcher(s);
+            if (morning.find()) {
+                return 1;
+            }
+//            Matcher afternoon = goodAfternoonPattern.matcher(s);
+//            if (afternoon.find()) {
+//                return 2;
+//            }
+//            Matcher evening = goodEveningPattern.matcher(s);
+//            if (evening.find()) {
+//                return 3;
+//            }
+        }
+        return 0;
+    }
+
+    public static double getTimeDiff(long currentMs, long historyMs) {
+        double diff = (currentMs - historyMs) / twoMonthMs;
         if (diff > 1.0) {
             diff = 1.0;
         }
         return diff;
     }
+
+    public static double log1(double data) {
+        if (data <= 0) {
+            return 0D;
+        }
+        return Math.log(data + 1.0);
+    }
+
+    public static double plusSmooth(double a, double b, double plus) {
+        if (a == 0 || b == 0) {
+            return 0D;
+        }
+        return a / (b + plus);
+    }
+
+    public static double wilsonScore(double click, double exposure) {
+        if (exposure <= 0) {
+            return 0.0;
+        }
+
+        double z = 1.96;
+        double ctr = click / exposure;
+        if (ctr > 1.0) {
+            ctr = 1.0;
+        }
+
+        double numerator_1 = ctr + Math.pow(z, 2) / (2 * exposure);
+        double numerator_2 = z * Math.sqrt((ctr * (1 - ctr)) / exposure + Math.pow(z / (2 * exposure), 2));
+        double denominator = 1.0 + Math.pow(z, 2) / exposure;
+        return (numerator_1 - numerator_2) / denominator;
+    }
+
+    public static boolean greaterThanZero(double value) {
+        return value > 1E-8;
+    }
 }

+ 444 - 0
recommend-server-service/src/main/resources/feeds_score_config_fm_xgb_20250221.conf

@@ -0,0 +1,444 @@
+scorer-config = {
+  rov-score-config = {
+     scorer-name = "com.tzld.piaoquan.recommend.server.service.score.VlogRovFMScorer"
+     scorer-priority = 96
+     model-path = "zhangbo/model_aka8_new2.txt"
+  }
+  nor-score-config = {
+    scorer-name = "com.tzld.piaoquan.recommend.server.service.score.NorXGBRegressionScorer"
+    scorer-priority = 97
+    model-path = "zhangbo/model_xgb_for_recsys_v4_nor.tar.gz"
+    param = {
+      localDir = "xgboost/recsys_v4_nor"
+      features = [
+      "b10_12h_is_share",
+      "b10_12h_return_n_uv",
+      "b10_12h_ros",
+      "b10_12h_ros_minus",
+      "b10_12h_rovn",
+      "b10_12h_str",
+      "b10_12h_str_plus",
+      "b10_1h_is_share",
+      "b10_1h_return_n_uv",
+      "b10_1h_ros",
+      "b10_1h_ros_minus",
+      "b10_1h_rovn",
+      "b10_1h_str",
+      "b10_1h_str_plus",
+      "b11_12h_is_share",
+      "b11_12h_return_n_uv",
+      "b11_12h_ros",
+      "b11_12h_ros_minus",
+      "b11_12h_rovn",
+      "b11_12h_str",
+      "b11_12h_str_plus",
+      "b11_168h_is_share",
+      "b11_168h_return_n_uv",
+      "b11_168h_ros",
+      "b11_168h_ros_minus",
+      "b11_168h_rovn",
+      "b11_168h_str",
+      "b11_168h_str_plus",
+      "b13_168h_is_share",
+      "b13_168h_return_n_uv",
+      "b13_168h_ros",
+      "b13_168h_ros_minus",
+      "b13_168h_ros_n",
+      "b13_168h_ros_one",
+      "b13_168h_rovn",
+      "b13_168h_str",
+      "b13_168h_str_plus",
+      "b13_24h_is_share",
+      "b13_24h_return_n_uv",
+      "b13_24h_ros",
+      "b13_24h_ros_minus",
+      "b13_24h_ros_n",
+      "b13_24h_ros_one",
+      "b13_24h_rovn",
+      "b13_24h_str",
+      "b13_24h_str_plus",
+      "b1_168h_exp",
+      "b1_168h_is_return_1",
+      "b1_168h_is_share",
+      "b1_168h_return_n_uv",
+      "b1_168h_ros",
+      "b1_168h_ros_minus",
+      "b1_168h_ros_n",
+      "b1_168h_ros_one",
+      "b1_168h_rovn",
+      "b1_168h_share_cnt",
+      "b1_168h_str",
+      "b1_168h_str_plus",
+      "b1_1h_exp",
+      "b1_1h_is_return_1",
+      "b1_1h_is_share",
+      "b1_1h_return_n_uv",
+      "b1_1h_ros",
+      "b1_1h_ros_minus",
+      "b1_1h_ros_n",
+      "b1_1h_ros_one",
+      "b1_1h_rovn",
+      "b1_1h_share_cnt",
+      "b1_1h_str",
+      "b1_1h_str_plus",
+      "b1_24h_exp",
+      "b1_24h_is_return_1",
+      "b1_24h_is_share",
+      "b1_24h_return_n_uv",
+      "b1_24h_ros",
+      "b1_24h_ros_minus",
+      "b1_24h_ros_n",
+      "b1_24h_ros_one",
+      "b1_24h_rovn",
+      "b1_24h_share_cnt",
+      "b1_24h_str",
+      "b1_24h_str_plus",
+      "b1_3h_exp",
+      "b1_3h_is_return_1",
+      "b1_3h_is_share",
+      "b1_3h_return_n_uv",
+      "b1_3h_ros",
+      "b1_3h_ros_minus",
+      "b1_3h_ros_n",
+      "b1_3h_ros_one",
+      "b1_3h_rovn",
+      "b1_3h_share_cnt",
+      "b1_3h_str",
+      "b1_3h_str_plus",
+      "b1_72h_exp",
+      "b1_72h_is_return_1",
+      "b1_72h_is_share",
+      "b1_72h_return_n_uv",
+      "b1_72h_ros",
+      "b1_72h_ros_minus",
+      "b1_72h_ros_n",
+      "b1_72h_ros_one",
+      "b1_72h_rovn",
+      "b1_72h_share_cnt",
+      "b1_72h_str",
+      "b1_72h_str_plus",
+      "b2_1h_is_return_1",
+      "b2_1h_is_share",
+      "b2_1h_return_n_uv",
+      "b2_1h_ros",
+      "b2_1h_ros_minus",
+      "b2_1h_ros_n",
+      "b2_1h_ros_one",
+      "b2_1h_rovn",
+      "b2_1h_share_cnt",
+      "b2_1h_str",
+      "b2_1h_str_plus",
+      "b2_24h_is_return_1",
+      "b2_24h_is_share",
+      "b2_24h_return_n_uv",
+      "b2_24h_ros",
+      "b2_24h_ros_minus",
+      "b2_24h_ros_n",
+      "b2_24h_ros_one",
+      "b2_24h_rovn",
+      "b2_24h_share_cnt",
+      "b2_24h_str",
+      "b2_24h_str_plus",
+      "b2_3h_is_return_1",
+      "b2_3h_is_share",
+      "b2_3h_return_n_uv",
+      "b2_3h_ros",
+      "b2_3h_ros_minus",
+      "b2_3h_ros_n",
+      "b2_3h_ros_one",
+      "b2_3h_rovn",
+      "b2_3h_share_cnt",
+      "b2_3h_str",
+      "b2_3h_str_plus",
+      "b3_168h_is_return_1",
+      "b3_168h_is_share",
+      "b3_168h_return_n_uv",
+      "b3_168h_ros",
+      "b3_168h_ros_minus",
+      "b3_168h_ros_n",
+      "b3_168h_ros_one",
+      "b3_168h_rovn",
+      "b3_168h_share_cnt",
+      "b3_168h_str",
+      "b3_168h_str_plus",
+      "b3_24h_is_return_1",
+      "b3_24h_is_share",
+      "b3_24h_return_n_uv",
+      "b3_24h_ros",
+      "b3_24h_ros_minus",
+      "b3_24h_ros_n",
+      "b3_24h_ros_one",
+      "b3_24h_rovn",
+      "b3_24h_share_cnt",
+      "b3_24h_str",
+      "b3_24h_str_plus",
+      "b4_12h_is_return_1",
+      "b4_12h_is_share",
+      "b4_12h_return_n_uv",
+      "b4_12h_ros",
+      "b4_12h_ros_minus",
+      "b4_12h_ros_n",
+      "b4_12h_ros_one",
+      "b4_12h_rovn",
+      "b4_12h_share_cnt",
+      "b4_12h_str",
+      "b4_12h_str_plus",
+      "b4_1h_is_return_1",
+      "b4_1h_is_share",
+      "b4_1h_return_n_uv",
+      "b4_1h_ros",
+      "b4_1h_ros_minus",
+      "b4_1h_ros_n",
+      "b4_1h_ros_one",
+      "b4_1h_rovn",
+      "b4_1h_share_cnt",
+      "b4_1h_str",
+      "b4_1h_str_plus",
+      "b5_168h_is_share",
+      "b5_168h_return_n_uv",
+      "b5_168h_ros",
+      "b5_168h_ros_minus",
+      "b5_168h_ros_n",
+      "b5_168h_ros_one",
+      "b5_168h_rovn",
+      "b5_168h_str",
+      "b5_168h_str_plus",
+      "b5_72h_is_share",
+      "b5_72h_return_n_uv",
+      "b5_72h_ros",
+      "b5_72h_ros_minus",
+      "b5_72h_ros_n",
+      "b5_72h_ros_one",
+      "b5_72h_rovn",
+      "b5_72h_str",
+      "b5_72h_str_plus",
+      "b6_1h_is_share",
+      "b6_1h_return_n_uv",
+      "b6_1h_ros",
+      "b6_1h_ros_minus",
+      "b6_1h_ros_n",
+      "b6_1h_ros_one",
+      "b6_1h_rovn",
+      "b6_1h_str",
+      "b6_1h_str_plus",
+      "b6_24h_is_share",
+      "b6_24h_return_n_uv",
+      "b6_24h_ros",
+      "b6_24h_ros_minus",
+      "b6_24h_ros_n",
+      "b6_24h_ros_one",
+      "b6_24h_rovn",
+      "b6_24h_str",
+      "b6_24h_str_plus",
+      "b7_168h_is_share",
+      "b7_168h_return_n_uv",
+      "b7_168h_ros",
+      "b7_168h_ros_minus",
+      "b7_168h_rovn",
+      "b7_168h_str",
+      "b7_168h_str_plus",
+      "b7_24h_is_share",
+      "b7_24h_return_n_uv",
+      "b7_24h_ros",
+      "b7_24h_ros_minus",
+      "b7_24h_rovn",
+      "b7_24h_str",
+      "b7_24h_str_plus",
+      "b8_24h_is_share",
+      "b8_24h_return_n_uv",
+      "b8_24h_ros",
+      "b8_24h_ros_minus",
+      "b8_24h_rovn",
+      "b8_24h_str",
+      "b8_24h_str_plus",
+      "b9_24h_is_share",
+      "b9_24h_return_n_uv",
+      "b9_24h_ros",
+      "b9_24h_ros_minus",
+      "b9_24h_rovn",
+      "b9_24h_str",
+      "b9_24h_str_plus",
+      "c1_168h_is_return_1",
+      "c1_168h_is_share",
+      "c1_168h_return_n_uv",
+      "c1_168h_ros",
+      "c1_168h_ros_minus",
+      "c1_168h_ros_n",
+      "c1_168h_ros_one",
+      "c1_168h_rovn",
+      "c1_168h_share_cnt",
+      "c1_168h_str",
+      "c1_168h_str_plus",
+      "c1_72h_is_return_1",
+      "c1_72h_is_share",
+      "c1_72h_return_n_uv",
+      "c1_72h_ros",
+      "c1_72h_ros_minus",
+      "c1_72h_ros_n",
+      "c1_72h_ros_one",
+      "c1_72h_rovn",
+      "c1_72h_share_cnt",
+      "c1_72h_str",
+      "c1_72h_str_plus",
+      "c4_168h_avg_ros",
+      "c4_168h_avg_ros_minus",
+      "c4_168h_avg_ros_one",
+      "c4_168h_avg_rovn",
+      "c4_168h_avg_str",
+      "c4_168h_avg_str_one",
+      "c4_168h_avg_str_plus",
+      "c4_168h_max_ros",
+      "c4_168h_max_ros_minus",
+      "c4_168h_max_ros_one",
+      "c4_168h_max_rovn",
+      "c4_168h_max_str",
+      "c4_168h_max_str_one",
+      "c4_168h_max_str_plus",
+      "c4_168h_min_ros",
+      "c4_168h_min_ros_minus",
+      "c4_168h_min_ros_one",
+      "c4_168h_min_rovn",
+      "c4_168h_min_str",
+      "c4_168h_min_str_one",
+      "c4_168h_min_str_plus",
+      "c4_72h_avg_ros",
+      "c4_72h_avg_ros_minus",
+      "c4_72h_avg_ros_one",
+      "c4_72h_avg_rovn",
+      "c4_72h_avg_str",
+      "c4_72h_avg_str_one",
+      "c4_72h_avg_str_plus",
+      "c4_72h_max_ros",
+      "c4_72h_max_ros_minus",
+      "c4_72h_max_ros_one",
+      "c4_72h_max_rovn",
+      "c4_72h_max_str",
+      "c4_72h_max_str_one",
+      "c4_72h_max_str_plus",
+      "c4_72h_min_ros",
+      "c4_72h_min_ros_minus",
+      "c4_72h_min_ros_one",
+      "c4_72h_min_rovn",
+      "c4_72h_min_str",
+      "c4_72h_min_str_one",
+      "c4_72h_min_str_plus",
+      "c5_tags_1d_avgscore",
+      "c5_tags_1d_matchnum",
+      "c5_tags_1d_maxscore",
+      "c5_tags_3d_avgscore",
+      "c5_tags_3d_matchnum",
+      "c5_tags_3d_maxscore",
+      "c5_tags_7d_avgscore",
+      "c5_tags_7d_matchnum",
+      "c5_tags_7d_maxscore",
+      "c6_tags_1d_avgscore",
+      "c6_tags_1d_matchnum",
+      "c6_tags_1d_maxscore",
+      "c6_tags_3d_avgscore",
+      "c6_tags_3d_matchnum",
+      "c6_tags_3d_maxscore",
+      "c6_tags_7d_avgscore",
+      "c6_tags_7d_matchnum",
+      "c6_tags_7d_maxscore",
+      "c7_return_num",
+      "c7_return_rank",
+      "c7_return_score",
+      "c7_share_num",
+      "c7_share_rank",
+      "c7_share_score",
+      "c8_return_num",
+      "c8_return_rank",
+      "c8_return_score",
+      "c8_share_num",
+      "c8_share_rank",
+      "c8_share_score",
+      "c9_c1s@mu",
+      "c9_c1s@ros",
+      "c9_c1s@ros_minus",
+      "c9_c1s@ros_one",
+      "c9_c1s@rp",
+      "c9_c1s@ru",
+      "c9_c1s@sp",
+      "c9_c2s@mu",
+      "c9_c2s@ros",
+      "c9_c2s@ros_minus",
+      "c9_c2s@ros_one",
+      "c9_c2s@rp",
+      "c9_c2s@ru",
+      "c9_c2s@sp",
+      "c9_l1s@mu",
+      "c9_l1s@ros",
+      "c9_l1s@ros_minus",
+      "c9_l1s@ros_one",
+      "c9_l1s@rp",
+      "c9_l1s@ru",
+      "c9_l1s@sp",
+      "c9_l2s@mu",
+      "c9_l2s@ros",
+      "c9_l2s@ros_minus",
+      "c9_l2s@ros_one",
+      "c9_l2s@rp",
+      "c9_l2s@ru",
+      "c9_l2s@sp",
+      "c9_lrs@1@ts",
+      "c9_lrs@1@uv",
+      "c9_lrs@1_title",
+      "c9_lrs@2@ts",
+      "c9_lrs@2@uv",
+      "c9_lrs@2_title",
+      "c9_lss@1@cnt",
+      "c9_lss@1@ts",
+      "c9_lss@1_title",
+      "c9_lss@2@cnt",
+      "c9_lss@2@ts",
+      "c9_lss@2_title",
+      "c9_m_r_uv",
+      "c9_m_s_cnt",
+      "c9_mrs@1@ts",
+      "c9_mrs@1@uv",
+      "c9_mrs@1_title",
+      "c9_mrs@2@ts",
+      "c9_mrs@2@uv",
+      "c9_mrs@2_title",
+      "c9_mss@1@cnt",
+      "c9_mss@1@ts",
+      "c9_mss@1_title",
+      "c9_mss@2@cnt",
+      "c9_mss@2@ts",
+      "c9_mss@2_title",
+      "c9_r_pv",
+      "c9_r_uv",
+      "c9_ros",
+      "c9_ros_minus",
+      "c9_ros_one",
+      "c9_s_cnt",
+      "c9_s_pv",
+      "d1_ros_cf_rank",
+      "d1_ros_cf_score",
+      "d1_rov_cf_rank",
+      "d1_rov_cf_score",
+      "d2_onlines",
+      "d2_rank",
+      "d2_score",
+      "d3_exp",
+      "d3_return_n",
+      "d3_rovn",
+      "h@bit_rate",
+      "h@total_time",
+      "h@ts",
+      "h@tt@1",
+      "hour",
+      "hr_sim_cate1_list",
+      "hr_sim_cate2",
+      "hr_sim_cate2_list",
+      "hr_sim_keywords",
+      "hr_sim_title",
+      "hr_sim_topic",
+      "r@bit_rate",
+      "r@total_time",
+      "r@ts",
+      "r@tt@1"
+      ]
+    }
+  }
+}