Browse Source

Merge branch 'addfeature/20240520/sunxy/addPushFromRank' of algorithm/recommend-server into master

sunxiaoyi 11 months ago
parent
commit
d937cbda2e

+ 1 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/model/Video.java

@@ -38,5 +38,6 @@ public class Video {
     public double scoreRegion = 0.0D;
     public Map<String, Double> scoresMap = new HashMap<>();
     public Map<String, List<String>> pushFromIndex = new HashMap<>();
+    public Map<String, Integer> pushFromRank = new HashMap<>();
 
 }

+ 3 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -203,6 +203,9 @@ public class RecommendService {
                 map.put("score", String.valueOf(v.getScore()));
                 map.put("scoresMap", JSONUtils.toJson(v.getScoresMap()));
 
+                map.put("pushFromRank", JSONUtils.toJson(v.getPushFromRank()));
+                map.put("abExpCode", JSONUtils.toJson(param.getAbExpCodes()));
+
                 return map;
 
             }).collect(Collectors.toList());

+ 26 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -117,6 +117,7 @@ public class RankService {
         if (CollectionUtils.isEmpty(param.getRecallResult().getData())) {
             return;
         }
+        // pushFromIndex
         Map<Long, Set<String>> videoIdPushFromMap = new HashMap<>();
         for (RecallResult.RecallData data : param.getRecallResult().getData()) {
             if (CollectionUtils.isEmpty(data.getVideos())) {
@@ -127,6 +128,11 @@ public class RankService {
                 pushFromSet.add(data.getPushFrom());
             }
         }
+
+        // pushFromRank
+        Map<String, List<Video>> pushFromVideosMap = param.getRecallResult().getData().stream()
+                .collect(Collectors.toMap(RecallResult.RecallData::getPushFrom, result -> result.getVideos() == null
+                        ? new ArrayList<>() : result.getVideos(), (v1, v2) -> v2));
         for (RecallResult.RecallData data : param.getRecallResult().getData()) {
             if (CollectionUtils.isEmpty(data.getVideos())) {
                 continue;
@@ -134,12 +140,29 @@ public class RankService {
             for (Video video : data.getVideos()) {
                 Set<String> pushFromSet = videoIdPushFromMap.get(video.getVideoId());
                 if (pushFromSet != null && pushFromSet.size() > 0) {
-                    Map<String, List<String>> map = new HashMap<>();
-                    pushFromSet.forEach(p -> map.computeIfAbsent(p, k -> new ArrayList<>()));
-                    video.setPushFromIndex(map);
+                    Map<String, List<String>> pushFromIndex = new HashMap<>();
+                    Map<String, Integer> pushFromRank = new HashMap<>();
+                    pushFromSet.forEach(p -> {
+
+                        pushFromIndex.computeIfAbsent(p, k -> new ArrayList<>());
+
+                        List<Video> videos = pushFromVideosMap.get(p);
+                        if (CollectionUtils.isNotEmpty(videos)) {
+                            for (int i = 0; i < videos.size(); i++) {
+                                if (Objects.equals(videos.get(i).getVideoId(), video.getVideoId())) {
+                                    pushFromRank.put(p, i + 1);
+                                    break;
+                                }
+                            }
+                        }
+
+                    });
+                    video.setPushFromIndex(pushFromIndex);
+                    video.setPushFromRank(pushFromRank);
                 }
             }
         }
+
     }
 
     public void rankFilter(RankParam param, List<Video> rovRecallRank, List<Video> flowPoolRank) {

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

@@ -163,6 +163,8 @@ public class RankStrategy4ShareDeepAndWidth extends RankStrategy4RegionMergeMode
 
             if (sumShareCount > 30) {
                 score += a * daySharedepthMaxAvg + b * daySharewidthMaxAvg;
+                item.getScoresMap().put("dayShareDepthMaxAvg", daySharedepthMaxAvg);
+                item.getScoresMap().put("dayShareWidthMaxAvg", daySharewidthMaxAvg);
             }
 
             Video video = item.getVideo();