|  | @@ -1,6 +1,7 @@
 | 
	
		
			
				|  |  |  package com.tzld.piaoquan.recommend.server.service.rank.strategy;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  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;
 | 
	
	
		
			
				|  | @@ -11,7 +12,9 @@ import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.apache.commons.collections4.MapUtils;
 | 
	
		
			
				|  |  | +import org.apache.commons.math3.util.Pair;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.io.BufferedReader;
 | 
	
	
		
			
				|  | @@ -19,6 +22,9 @@ import java.io.IOException;
 | 
	
		
			
				|  |  |  import java.io.InputStream;
 | 
	
		
			
				|  |  |  import java.io.InputStreamReader;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.concurrent.Callable;
 | 
	
		
			
				|  |  | +import java.util.concurrent.Future;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
	
		
			
				|  | @@ -33,6 +39,9 @@ public class RankStrategy4RegionMergeModelV563 extends RankStrategy4RegionMergeM
 | 
	
		
			
				|  |  |      Map<String, double[]> bucketsMap = new HashMap<>();
 | 
	
		
			
				|  |  |      Map<String, Double> bucketsLen = new HashMap<>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Value("${similarity.concurrent: false}")
 | 
	
		
			
				|  |  | +    private boolean similarityConcurrent;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public List<Video> mergeAndRankRovRecall(RankParam param) {
 | 
	
		
			
				|  |  |          Map<String, Double> mergeWeight = this.mergeWeight != null ? this.mergeWeight : new HashMap<>(0);
 | 
	
	
		
			
				|  | @@ -221,14 +230,41 @@ public class RankStrategy4RegionMergeModelV563 extends RankStrategy4RegionMergeM
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              String title = videoInfo.getOrDefault("title", "");
 | 
	
		
			
				|  |  |              if (!title.isEmpty()) {
 | 
	
		
			
				|  |  | -                for (String name : Arrays.asList("c3_feature", "c4_feature", "c5_feature", "c6_feature", "c7_feature")) {
 | 
	
		
			
				|  |  | -                    for (String key_time : Arrays.asList("tags_1d", "tags_3d", "tags_7d")) {
 | 
	
		
			
				|  |  | -                        String tags = c34567Map.getOrDefault(name + "_" + key_time, "");
 | 
	
		
			
				|  |  | -                        if (!tags.isEmpty()) {
 | 
	
		
			
				|  |  | -                            Double[] doubles = ExtractorUtils.funcC34567ForTags(tags, title);
 | 
	
		
			
				|  |  | -                            featureMap.put(name + "_" + key_time + "_matchnum", doubles[0]);
 | 
	
		
			
				|  |  | -                            featureMap.put(name + "_" + key_time + "_maxscore", doubles[1]);
 | 
	
		
			
				|  |  | -                            featureMap.put(name + "_" + key_time + "_avgscore", doubles[2]);
 | 
	
		
			
				|  |  | +                if (similarityConcurrent) {
 | 
	
		
			
				|  |  | +                    List<Future<Pair<String, Double[]>>> futures = new ArrayList<>();
 | 
	
		
			
				|  |  | +                    for (String name : Arrays.asList("c3_feature", "c4_feature", "c5_feature", "c6_feature", "c7_feature")) {
 | 
	
		
			
				|  |  | +                        for (String key_time : Arrays.asList("tags_1d", "tags_3d", "tags_7d")) {
 | 
	
		
			
				|  |  | +                            String key = name + "_" + key_time;
 | 
	
		
			
				|  |  | +                            String tags = c34567Map.getOrDefault(key, "");
 | 
	
		
			
				|  |  | +                            if (!tags.isEmpty()) {
 | 
	
		
			
				|  |  | +                                Future<Pair<String, Double[]>> future = ThreadPoolFactory.defaultPool().submit(() -> {
 | 
	
		
			
				|  |  | +                                    Double[] doubles = ExtractorUtils.funcC34567ForTags(tags, title);
 | 
	
		
			
				|  |  | +                                    return Pair.create(key, doubles);
 | 
	
		
			
				|  |  | +                                });
 | 
	
		
			
				|  |  | +                                futures.add(future);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    try {
 | 
	
		
			
				|  |  | +                        for (Future<Pair<String, Double[]>> future : futures) {
 | 
	
		
			
				|  |  | +                            Pair<String, Double[]> pair = future.get(1000, TimeUnit.MILLISECONDS);
 | 
	
		
			
				|  |  | +                            featureMap.put(pair.getFirst() + "_matchnum", pair.getSecond()[0]);
 | 
	
		
			
				|  |  | +                            featureMap.put(pair.getFirst() + "_maxscore", pair.getSecond()[1]);
 | 
	
		
			
				|  |  | +                            featureMap.put(pair.getFirst() + "_avgscore", pair.getSecond()[2]);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    } catch (Exception e) {
 | 
	
		
			
				|  |  | +                        log.error("concurrent similarity error", e);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    for (String name : Arrays.asList("c3_feature", "c4_feature", "c5_feature", "c6_feature", "c7_feature")) {
 | 
	
		
			
				|  |  | +                        for (String key_time : Arrays.asList("tags_1d", "tags_3d", "tags_7d")) {
 | 
	
		
			
				|  |  | +                            String tags = c34567Map.getOrDefault(name + "_" + key_time, "");
 | 
	
		
			
				|  |  | +                            if (!tags.isEmpty()) {
 | 
	
		
			
				|  |  | +                                Double[] doubles = ExtractorUtils.funcC34567ForTags(tags, title);
 | 
	
		
			
				|  |  | +                                featureMap.put(name + "_" + key_time + "_matchnum", doubles[0]);
 | 
	
		
			
				|  |  | +                                featureMap.put(name + "_" + key_time + "_maxscore", doubles[1]);
 | 
	
		
			
				|  |  | +                                featureMap.put(name + "_" + key_time + "_avgscore", doubles[2]);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -295,34 +331,30 @@ public class RankStrategy4RegionMergeModelV563 extends RankStrategy4RegionMergeM
 | 
	
		
			
				|  |  |          // 3 排序
 | 
	
		
			
				|  |  |          Map<String, String> sceneFeatureMap = new HashMap<>(0);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_xgb_20240828.conf")
 | 
	
		
			
				|  |  | +        List<RankItem> items = ScorerUtils.getScorerPipeline("feeds_score_config_20240807.conf")
 | 
	
		
			
				|  |  |                  .scoring(sceneFeatureMap, userFeatureMap, rankItems);
 | 
	
		
			
				|  |  | -        Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, "redis:vid_hasreturn_rov:");
 | 
	
		
			
				|  |  | -        Map<String, Map<String, String>> vid2VovFeatureMap = this.getVideoRedisFeature(vids, "redis:vid_vov_1d3d:");
 | 
	
		
			
				|  |  | -        double alpha_vov = mergeWeight.getOrDefault("alpha_vov", 2.0);
 | 
	
		
			
				|  |  | +        String redisScoreKey =  mergeWeight.getOrDefault("redisScoreKey", 0.0) < 0.5 ? "redis:vid_hasreturn_rov:" : "redis:vid_hasreturn_rov_7d:";
 | 
	
		
			
				|  |  | +        Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, redisScoreKey);
 | 
	
		
			
				|  |  |          List<Video> result = new ArrayList<>();
 | 
	
		
			
				|  |  | -//        String hasReturnRovKey = mergeWeight.getOrDefault("hasReturnRovKey", 1.0) < 0.5 ? "rate_1" : "rate_n";
 | 
	
		
			
				|  |  | -//        Double chooseFunction = mergeWeight.getOrDefault("chooseFunction", 0.0);
 | 
	
		
			
				|  |  | +        String hasReturnRovKey = mergeWeight.getOrDefault("hasReturnRovKey", 1.0) < 0.5 ? "rate_1" : "rate_n";
 | 
	
		
			
				|  |  | +        Double chooseFunction = mergeWeight.getOrDefault("chooseFunction", 0.0);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for (RankItem item : items) {
 | 
	
		
			
				|  |  |              double score = 0.0;
 | 
	
		
			
				|  |  | -            double recommend_rate_1d = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
 | 
	
		
			
				|  |  | -                    .getOrDefault("recommend_rate_1d", "0"));
 | 
	
		
			
				|  |  | -            double recommend_exp_per_1d = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
 | 
	
		
			
				|  |  | -                    .getOrDefault("recommend_exp_per_1d", "0"));
 | 
	
		
			
				|  |  | -            double vorScore =  recommend_rate_1d * recommend_exp_per_1d;
 | 
	
		
			
				|  |  | -            item.getScoresMap().put("recommend_rate_1d", recommend_rate_1d);
 | 
	
		
			
				|  |  | -            item.getScoresMap().put("recommend_exp_per_1d", recommend_exp_per_1d);
 | 
	
		
			
				|  |  | -            item.getScoresMap().put("vorScore", vorScore);
 | 
	
		
			
				|  |  | -            item.getScoresMap().put("alpha_vov", alpha_vov);
 | 
	
		
			
				|  |  |              double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>())
 | 
	
		
			
				|  |  | -                    .getOrDefault("rate_n", "0"));
 | 
	
		
			
				|  |  | +                    .getOrDefault(hasReturnRovKey, "0"));
 | 
	
		
			
				|  |  |              item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
 | 
	
		
			
				|  |  | -            double rovRateOrigin = item.getScoreRov();
 | 
	
		
			
				|  |  | -            item.getScoresMap().put("rovRateOrigin", rovRateOrigin);
 | 
	
		
			
				|  |  | -            double rovRate = restoreScore(rovRateOrigin);
 | 
	
		
			
				|  |  | -            item.getScoresMap().put("rovRate", rovRate);
 | 
	
		
			
				|  |  | -            score = rovRate * (1 + hasReturnRovScore) * (1.0 + alpha_vov * recommend_rate_1d);
 | 
	
		
			
				|  |  | +            double fmRovOrigin = item.getScoreRov();
 | 
	
		
			
				|  |  | +            item.getScoresMap().put("fmRovOrigin", fmRovOrigin);
 | 
	
		
			
				|  |  | +            double fmRov = restoreScore(fmRovOrigin);
 | 
	
		
			
				|  |  | +            item.getScoresMap().put("fmRov", fmRov);
 | 
	
		
			
				|  |  | +            if (chooseFunction == 0){
 | 
	
		
			
				|  |  | +                score = fmRov * (1 + hasReturnRovScore);
 | 
	
		
			
				|  |  | +            }else if (chooseFunction == 1){
 | 
	
		
			
				|  |  | +                score = fmRov * (1 + Math.log(hasReturnRovScore + 1));
 | 
	
		
			
				|  |  | +            }else {
 | 
	
		
			
				|  |  | +                score = fmRov * ExtractorUtils.sigmoid(hasReturnRovScore);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              Video video = item.getVideo();
 | 
	
		
			
				|  |  |              video.setScore(score);
 | 
	
	
		
			
				|  | @@ -346,7 +378,7 @@ public class RankStrategy4RegionMergeModelV563 extends RankStrategy4RegionMergeM
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private void readBucketFile() {
 | 
	
		
			
				|  |  | -        InputStream resourceStream = RankStrategy4RegionMergeModelV563.class.getClassLoader().getResourceAsStream("20240609_bucket_274.txt");
 | 
	
		
			
				|  |  | +        InputStream resourceStream = RankStrategy4RegionMergeModelV552.class.getClassLoader().getResourceAsStream("20240609_bucket_274.txt");
 | 
	
		
			
				|  |  |          if (resourceStream != null) {
 | 
	
		
			
				|  |  |              try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceStream))) {
 | 
	
		
			
				|  |  |                  Map<String, double[]> bucketsMap = new HashMap<>();
 |