Преглед изворни кода

remove unused rank strategy

丁云鹏 пре 3 месеци
родитељ
комит
4b2f482c6a

+ 4 - 83
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankRouter.java

@@ -12,119 +12,40 @@ public class RankRouter {
     @Autowired
     private RankService rankService;
     @Autowired
-    private RankStrategy4Rankv2Model rankStrategy4Rankv2Model;
-    @Autowired
-    private RankStrategy4RankModel rankStrategy4RankModel;
-    @Autowired
-    private RankStrategy4Density rankStrategy4Density;
-    @Autowired
     private RankStrategy4RegionMergeModelV536 rankStrategy4RegionMergeModelV536;
     @Autowired
-    private RankStrategy4RegionMergeModelV546 rankStrategy4RegionMergeModelV546;
-    @Autowired
-    private RankStrategy4RegionMergeModelV547 rankStrategy4RegionMergeModelV547;
-    @Autowired
-    private RankStrategy4RegionMergeModelV548 rankStrategy4RegionMergeModelV548;
-    @Autowired
-    private RankStrategy4RegionMergeModelV551 rankStrategy4RegionMergeModelV551;
-    @Autowired
-    private RankStrategy4RegionMergeModelV552 rankStrategy4RegionMergeModelV552;
-    @Autowired
-    private RankStrategy4RegionMergeModelV553 rankStrategy4RegionMergeModelV553;
-    @Autowired
     private RankStrategy4RegionMergeModelV562 rankStrategy4RegionMergeModelV562;
     @Autowired
     private RankStrategy4RegionMergeModelV563 rankStrategy4RegionMergeModelV563;
     @Autowired
     private RankStrategy4RegionMergeModelV564 rankStrategy4RegionMergeModelV564;
     @Autowired
-    private RankStrategy4RegionMergeModelV565 rankStrategy4RegionMergeModelV565;
-    @Autowired
-    private RankStrategy4RegionMergeModelV566 rankStrategy4RegionMergeModelV566;
-    @Autowired
     private RankStrategy4RegionMergeModelV567 rankStrategy4RegionMergeModelV567;
     @Autowired
-    private RankStrategy4RegionMergeModelV999 rankStrategy4RegionMergeModelV999;
-    @Autowired
     private RankStrategy4RegionMergeModelV569 rankStrategy4RegionMergeModelV569;
-    @Autowired
-    private RankStrategy4RegionMergeModelV650 rankStrategy4RegionMergeModelV650;
-    @Autowired
-    private RankStrategy4RegionMergeModelV654 rankStrategy4RegionMergeModelV654;
-    @Autowired
-    private RankStrategy4RegionMergeModelV655 rankStrategy4RegionMergeModelV655;
-    @Autowired
-    private RankStrategy4RegionMergeModelV656 rankStrategy4RegionMergeModelV656;
-    @Autowired
-    private FestivalStrategy4RankModel festivalStrategy4RankModel;
-
-    @Autowired
-    private RankStrategyFlowThompsonModel rankStrategyFlowThompsonModel;
-    @Autowired
-    private RankStrategy4RegionMerge rankStrategy4RegionMerge;
-    @Autowired
-    private RankStrategy4ShareDeepAndWidth rankStrategy4ShareDeepAndWidth;
 
     public RankResult rank(RankParam param) {
         String abCode = param.getAbCode();
         if (StringUtils.isBlank(abCode)) {
             return rankService.rank(param);
         }
+        // 536 562 563 564 567 569
         switch (abCode) {
-            case "60105": // 551
-                return rankStrategy4RegionMergeModelV551.rank(param); // 60105 新模型自动更新 实验关闭
-            case "60106": // 552
-                return rankStrategy4RegionMergeModelV552.rank(param); // 60106 新模型自动更新+样本采样 实验关闭
-            case "60107": // 553
-                return rankStrategy4RegionMergeModelV553.rank(param); // 60107 历史内容召回 实验关闭
+
             case "60112": // 562
-                return rankStrategy4RegionMergeModelV562.rank(param); // 60112 + vov公式 实验关闭
-            case "60101":
-                return rankStrategy4RankModel.rank(param); // 实验不存在
+                return rankStrategy4RegionMergeModelV562.rank(param);
             case "60113": // 563
                 return rankStrategy4RegionMergeModelV563.rank(param); // 60113 CF召回 doing
             case "60114": // 564
                 return rankStrategy4RegionMergeModelV564.rank(param); // 60114 排序r-cnt实验 doing
-            case "60115": // 565
-                return rankStrategy4RegionMergeModelV565.rank(param); // 60115 VoV排序 v2 实验关闭
-            case "60116": // 566
-                return rankStrategy4RegionMergeModelV566.rank(param); // 60116 流量池数据汤姆森 实验关闭
             case "60117": // 567
                 return rankStrategy4RegionMergeModelV567.rank(param); // 60117 cf叠加r-cnt模型 doing
-            case "60118": // 568
-                return rankStrategy4RegionMergeModelV999.rank(param); // rov fm模型 60118 实验关闭
             case "60119": // 569
                 return rankStrategy4RegionMergeModelV569.rank(param); // rov fm模型 60119 实验关闭
-            case "60120": // 576
-                return rankStrategy4RegionMerge.rank(param); // 地域召回实时性 实验关闭
             case "60121": // 536
+            default: // base 536
                 return rankStrategy4RegionMergeModelV536.rank(param); // vor统计量 doing
-            case "60122": // 537
-                return rankStrategy4RegionMergeModelV546.rank(param); // 新实验 实验关闭
-            case "60124": // 546
-                return rankStrategy4RegionMergeModelV546.rank(param); // 新实验+时间倾向24小时 实验关闭
-            case "60125": // 547
-                return rankStrategy4RegionMergeModelV547.rank(param); // 新实验+时间倾向24小时+0.6 实验关闭
-            case "60126": // 548
-                return rankStrategy4RegionMergeModelV548.rank(param); // 新实验+排序分子用全部回流+召回汤姆森 实验关闭
-            case "60130": // 算法祝福类内容召回 实验关闭
-            case "60131": // 算法祝福类内容召回(密度提升) 实验关闭
-            case "60132": // 算法祝福类内容召回(概率提升) 实验关闭
-                return festivalStrategy4RankModel.rank(param);
-            case "60150": // 645
-                return rankStrategy4ShareDeepAndWidth.rank(param); // 分享深度、广度内容召回 实验关闭
-            case "60151": // 650
-                return rankStrategy4RegionMergeModelV650.rank(param); // 基于SRT和Title的CB 实验关闭
-            case "60654": // 654
-                return rankStrategy4RegionMergeModelV654.rank(param); // 60654 + CF-ROVn 实验关闭
-            case "60655": // 655
-                return rankStrategy4RegionMergeModelV655.rank(param); // 60655 + CF-ROVn - sim - return 实验关闭
-            case "60656": // 656
-                return rankStrategy4RegionMergeModelV656.rank(param); // 60656 算法实验上线流程模拟 实验关闭
-            default:
-                break;
         }
-        return rankService.rank(param);
     }
 }
 

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

@@ -1,83 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.rank.strategy;
-
-import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
-import com.tzld.piaoquan.recommend.server.service.rank.RankResult;
-import com.tzld.piaoquan.recommend.server.service.rank.RankService;
-import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * @author sunxy
- */
-@Service
-@Slf4j
-public class FestivalStrategy4RankModel extends RankService {
-
-    @Resource
-    private RankStrategy4Density rankStrategy4Density;
-
-    @Override
-    public List<Video> mergeAndRankRovRecall(RankParam param) {
-        List<Video> rovRecallRank = new ArrayList<>();
-        rovRecallRank.addAll(extractAndSort(param, RegionHRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionHDupRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, Region24HRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionRelative24HRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionRelative24HDupRecallStrategy.PUSH_FORM));
-        removeDuplicate(rovRecallRank);
-        String abCode = param.getAbCode();
-        int sizeReturn = param.getSize();
-        if (abCode != null && this.regionRecallReturnSize != null &&
-                this.regionRecallReturnSize.containsKey(abCode) &&
-                this.regionRecallReturnSize.get(abCode) != null) {
-            sizeReturn = this.regionRecallReturnSize.get(abCode).getOrDefault("result_size", sizeReturn);
-        }
-        rovRecallRank = rovRecallRank.size() <= sizeReturn
-                ? rovRecallRank
-                : rovRecallRank.subList(0, sizeReturn);
-
-        List<Video> festivalRecallVideoList = extractAndSort(param, FestivalRecallStrategyV1.PUSH_FORM);
-        // 截断
-        if (CollectionUtils.isNotEmpty(festivalRecallVideoList)) {
-            rovRecallRank.addAll(festivalRecallVideoList.stream().limit(30).collect(Collectors.toList()));
-        }
-        // merge sim recall 和 return recall
-        rovRecallRank.addAll(extractAndSort(param, SimHotVideoRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, ReturnVideoRecallStrategy.PUSH_FORM));
-        // 地域召回要做截取,再做融合排序
-        removeDuplicate(rovRecallRank);
-
-        // 融合排序
-        List<String> videoIdKeys = rovRecallRank.stream()
-                .map(t -> param.getRankKeyPrefix() + t.getVideoId())
-                .collect(Collectors.toList());
-        List<String> videoScores = redisTemplate.opsForValue().multiGet(videoIdKeys);
-        if (CollectionUtils.isNotEmpty(videoScores)
-                && videoScores.size() == rovRecallRank.size()) {
-            for (int i = 0; i < videoScores.size(); i++) {
-                rovRecallRank.get(i).setSortScore(NumberUtils.toDouble(videoScores.get(i), 0.0));
-            }
-            Collections.sort(rovRecallRank,
-                    Comparator.comparingDouble(o -> -(o.getSortScore() * 0.1 * (o.getRovScore() / 100))));
-        }
-
-        return rovRecallRank;
-    }
-
-    @Override
-    public RankResult mergeAndSort(RankParam param, List<Video> rovRecallRank,
-                                   List<Video> flowPoolRank) {
-        return rankStrategy4Density.mergeAndSort(param, rovRecallRank, flowPoolRank);
-    }
-}

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

@@ -1,156 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.rank.strategy;
-
-
-import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
-import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
-import com.tzld.piaoquan.recommend.server.service.rank.RankResult;
-import com.tzld.piaoquan.recommend.server.service.rank.RankService;
-import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorItemTags;
-import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorBoost;
-import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorDensity;
-import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorInsert;
-import com.tzld.piaoquan.recommend.server.service.rank.processor.RankProcessorTagFilter;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.RandomUtils;
-import org.springframework.stereotype.Service;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * @author zhangbo sunxiaoyi
- * @desc 后处理规则 + roc池flow池的合并
- * 后处理参考文档:https://w42nne6hzg.feishu.cn/wiki/MYaGwCnF1iTFXUkSddAcA6CanFe
- * roc池flow池的合并 文档: 暂无
- */
-@Service
-@Slf4j
-public class RankStrategy4Density extends RankService {
-    @ApolloJsonValue("${RankStrategy4DensityFilterV2:}")
-    private Map<String,Map<String, Map<String, String>>> filterRules = new HashMap<>();
-
-
-    @Override
-    public RankResult mergeAndSort(RankParam param, List<Video> rovVideos, List<Video> flowVideos) {
-
-        //1 兜底策略,rov池子不足时,用冷启池填补。直接返回。
-        if (CollectionUtils.isEmpty(rovVideos)) {
-            if (param.getSize() < flowVideos.size()) {
-                return new RankResult(flowVideos.subList(0, param.getSize()));
-            } else {
-                return new RankResult(flowVideos);
-            }
-        }
-
-        //2 根据实验号解析阿波罗参数。
-        String abCode = param.getAbCode();
-        Map<String, Map<String, String>> rulesMap = this.filterRules.getOrDefault(abCode, new HashMap<>(0));
-
-        //3 标签读取
-        if (rulesMap != null && !rulesMap.isEmpty()){
-            RankExtractorItemTags extractorItemTags = new RankExtractorItemTags(this.redisTemplate);
-            extractorItemTags.processor(rovVideos, flowVideos);
-        }
-        //6 合并结果时间卡控
-        if (rulesMap != null && !rulesMap.isEmpty()){
-            RankProcessorTagFilter.processor(rovVideos, flowVideos, rulesMap);
-        }
-
-        //4 rov池提权功能
-        RankProcessorBoost.boostByTag(rovVideos, rulesMap);
-
-        //5 rov池强插功能
-        RankProcessorInsert.insertByTag(param, rovVideos, rulesMap);
-
-        //7 流量池按比例强插
-        List<Video> result = new ArrayList<>();
-        for (int i = 0; i < param.getTopK() && i < rovVideos.size(); i++) {
-            result.add(rovVideos.get(i));
-        }
-        double flowPoolP = getFlowPoolP(param);
-        int flowPoolIndex = 0;
-        int rovPoolIndex = param.getTopK();
-        for (int i = 0; i < param.getSize() - param.getTopK(); i++) {
-            double rand = RandomUtils.nextDouble(0, 1);
-            if (rand < flowPoolP) {
-                if (flowPoolIndex < flowVideos.size()) {
-                    result.add(flowVideos.get(flowPoolIndex++));
-                } else {
-                    break;
-                }
-            } else {
-                if (rovPoolIndex < rovVideos.size()) {
-                    result.add(rovVideos.get(rovPoolIndex++));
-                } else {
-                    break;
-                }
-            }
-        }
-        if (rovPoolIndex >= rovVideos.size()) {
-            for (int i = flowPoolIndex; i < flowVideos.size() && result.size() < param.getSize(); i++) {
-                result.add(flowVideos.get(i));
-            }
-        }
-        if (flowPoolIndex >= flowVideos.size()) {
-            for (int i = rovPoolIndex; i < rovVideos.size() && result.size() < param.getSize(); i++) {
-                result.add(rovVideos.get(i));
-            }
-        }
-
-        //8 合并结果密度控制
-        Map<String, Integer> densityRules = new HashMap<>();
-        if (rulesMap != null && !rulesMap.isEmpty()) {
-            for (Map.Entry<String, Map<String, String>> entry : rulesMap.entrySet()) {
-                String key = entry.getKey();
-                Map<String, String> value = entry.getValue();
-                if (value.containsKey("density")) {
-                    densityRules.put(key, Integer.valueOf(value.get("density")));
-                }
-            }
-        }
-        Set<Long> videosSet = result.stream().map(Video::getVideoId).collect(Collectors.toSet());
-        List<Video> rovRecallRankNew = rovVideos.stream().filter(r -> !videosSet.contains(r.getVideoId())).collect(Collectors.toList());
-        List<Video> flowPoolRankNew = flowVideos.stream().filter(r -> !videosSet.contains(r.getVideoId())).collect(Collectors.toList());
-        List<Video> resultWithDensity = RankProcessorDensity.mergeDensityControl(result,
-                rovRecallRankNew, flowPoolRankNew, densityRules);
-
-        return new RankResult(resultWithDensity);
-    }
-
-}
-
-
-
-
-//    public Video getTestVideo(Long id, String s){
-//        Video a1 = new Video();
-//        a1.setVideoId(id);
-//        a1.setFlowPool(s);
-//        return a1;
-//    }
-
-// 1 读取多样性密度控制规则------------------
-//        String appType = String.valueOf(param.getAppType());
-//        String ruleStr = this.redisTemplate.opsForValue().get("TAGS_FILTER_RULE_V1_JSON");
-//        Map<String, Integer> densityRules = new HashMap<>();
-//        if (ruleStr != null){
-//            Map<String, Map<String, Object>> ruleOrigin = JSONUtils.fromJson(ruleStr,
-//                    new TypeToken<Map<String, Map<String, Object>>>() {},
-//                    Collections.emptyMap());
-//            for (Map.Entry<String, Map<String, Object>> entry : ruleOrigin.entrySet()){
-//                String k = entry.getKey();
-//                if (!entry.getValue().containsKey(appType)){
-//                    continue;
-//                }
-//                JSONObject jb = (JSONObject) entry.getValue().get(appType);
-//                try{
-//                    if (jb.containsKey("density") && jb.get("density") instanceof Integer){
-//                        densityRules.put(k, jb.getInteger("density"));
-//                    }
-//                }catch (Exception e){
-//                    log.error("parse densityRules is wrong:", e);
-//                }
-//            }
-//        }

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

@@ -1,370 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.rank.strategy;
-
-
-import com.alibaba.fastjson.JSONObject;
-import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
-import com.google.common.reflect.TypeToken;
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
-import com.tzld.piaoquan.recommend.server.service.rank.RankService;
-import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorItemFeature;
-import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorUserFeature;
-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.JSONUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
-import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-import org.springframework.stereotype.Service;
-
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * @author zhangbo
- * @desc 模型的排序实验
- */
-@Service
-@Slf4j
-public class RankStrategy4RankModel extends RankService {
-
-    @ApolloJsonValue("${video.model.weightv1:}")
-    private Map<String, Double> mergeWeightNew;
-    final private String CLASS_NAME = this.getClass().getSimpleName();
-
-    @Override
-    public List<Video> mergeAndRankRovRecall(RankParam param) {
-
-        //-------------------地域内部融合-------------------
-        List<Video> rovRecallRank = new ArrayList<>();
-//        rovRecallRank.add(0, getTestVideo(1070462L, ""));
-//        rovRecallRank.add(0, getTestVideo(1085062L, ""));
-        rovRecallRank.addAll(extractAndSort(param, RegionHRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionHDupRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, Region24HRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionRelative24HRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionRelative24HDupRecallStrategy.PUSH_FORM));
-
-        //-------------------地域内部去重+截断-------------------
-        removeDuplicate(rovRecallRank);
-        rovRecallRank = rovRecallRank.size() <= param.getSize()
-                ? rovRecallRank
-                : rovRecallRank.subList(0, param.getSize());
-
-        //-------------------地域 sim returnv2 融合-------------------
-        rovRecallRank.addAll(extractAndSort(param, SimHotVideoRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, ReturnVideoRecallStrategy.PUSH_FORM));
-        //-------------------地域 sim returnv2 去重-------------------
-        removeDuplicate(rovRecallRank);
-
-        //-------------------排-------------------
-        //-------------------序-------------------
-        //-------------------逻-------------------
-        //-------------------辑-------------------
-        List<String> videoIdKeys = rovRecallRank.stream()
-                .map(t -> param.getRankKeyPrefix() + t.getVideoId())
-                .collect(Collectors.toList());
-        List<String> videoScores = this.redisTemplate.opsForValue().multiGet(videoIdKeys);
-        if (CollectionUtils.isNotEmpty(videoScores)
-                && videoScores.size() == rovRecallRank.size()) {
-            for (int i = 0; i < videoScores.size(); i++) {
-                rovRecallRank.get(i).setSortScore(NumberUtils.toDouble(videoScores.get(i), 0.0));
-            }
-            Collections.sort(rovRecallRank, Comparator.comparingDouble(o -> -o.getSortScore()));
-        }
-
-        //------------------- todo zhangbo 增加排序str ros模型逻辑 合并二者得分-------------------
-        List<Video> videosWithModel = model(rovRecallRank, param);
-        Map<String, Double> mergeWeight = this.mergeWeightNew == null ? new HashMap<>() : this.mergeWeightNew;
-        double alpha = mergeWeight.getOrDefault("alpha", 1.0D);
-        double beta = mergeWeight.getOrDefault("beta", 0.0D);
-        double gamma = mergeWeight.getOrDefault("gamma", 0.0D);
-        for (Video v : videosWithModel) {
-            double score = alpha * v.getSortScore() + beta * v.getScoreStr() + gamma * v.getScoreRos();
-            if (mergeWeight.containsKey("mul") && mergeWeight.getOrDefault("mul", 0.0D) > 0.5) {
-                score = alpha * v.getSortScore() + (beta + v.getScoreStr()) * (gamma + v.getScoreRos());
-            }
-            v.setScoreRegion(v.getSortScore());
-            v.score = score;
-            v.setSortScore(score);
-        }
-        videosWithModel.sort(Comparator.comparingDouble(o -> -o.score));
-
-        //------------------- 增加日志 -------------------
-        int size = 4;
-        List<Long> oldRes = rovRecallRank.subList(0, Math.min(rovRecallRank.size(), size)).stream().map(r -> r.getVideoId()).collect(Collectors.toList());
-        List<Long> newRes = videosWithModel.subList(0, Math.min(videosWithModel.size(), size)).stream().map(r -> r.getVideoId()).collect(Collectors.toList());
-        int diffpos = 0;
-        int difftop = 0;
-        for (int i = 0; i < newRes.size(); ++i) {
-            if (!oldRes.get(i).equals(newRes.get(i))) {
-                ++diffpos;
-            }
-            if (!oldRes.contains(newRes.get(i))) {
-                ++difftop;
-            }
-        }
-
-        return videosWithModel;
-    }
-
-    public List<Video> model(List<Video> videos, RankParam param) {
-        if (videos.isEmpty()) {
-            return videos;
-        }
-
-        RedisStandaloneConfiguration redisSC = new RedisStandaloneConfiguration();
-        redisSC.setPort(6379);
-        redisSC.setPassword("Wqsd@2019");
-        redisSC.setHostName("r-bp1pi8wyv6lzvgjy5z.redis.rds.aliyuncs.com");
-        RedisConnectionFactory connectionFactory = new JedisConnectionFactory(redisSC);
-        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
-        redisTemplate.setConnectionFactory(connectionFactory);
-        redisTemplate.setDefaultSerializer(new StringRedisSerializer());
-        redisTemplate.afterPropertiesSet();
-
-        // 0: 场景特征处理
-        Map<String, String> sceneFeatureMap = this.getSceneFeature(param);
-
-        // 1: user特征处理
-        Map<String, String> userFeatureMap = new HashMap<>();
-        if (param.getMid() != null && !param.getMid().isEmpty()) {
-            String midKey = "user_info_4video_" + param.getMid();
-            String userFeatureStr = redisTemplate.opsForValue().get(midKey);
-            if (userFeatureStr != null) {
-                try {
-                    userFeatureMap = JSONUtils.fromJson(userFeatureStr,
-                            new TypeToken<Map<String, String>>() {
-                            },
-                            userFeatureMap);
-                } catch (Exception e) {
-                    log.error(String.format("parse user json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-            } else {
-                return videos;
-            }
-        }
-        final Set<String> userFeatureSet = new HashSet<>(Arrays.asList(
-                "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system",
-                "u_1day_exp_cnt", "u_1day_click_cnt", "u_1day_share_cnt", "u_1day_return_cnt",
-                "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt"
-        ));
-        Iterator<Map.Entry<String, String>> iterator = userFeatureMap.entrySet().iterator();
-        while (iterator.hasNext()) {
-            Map.Entry<String, String> entry = iterator.next();
-            if (!userFeatureSet.contains(entry.getKey())) {
-                iterator.remove();
-            }
-        }
-        Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
-                new HashSet<String>(Arrays.asList(
-                        "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
-                ))
-        );
-        Map<String, String> f2 = RankExtractorUserFeature.getUserRateFeature(userFeatureMap);
-        Map<String, String> f3 = RankExtractorUserFeature.cntFeatureChange(userFeatureMap,
-                new HashSet<String>(Arrays.asList(
-                        "u_1day_exp_cnt", "u_1day_click_cnt", "u_1day_share_cnt", "u_1day_return_cnt",
-                        "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt"
-                ))
-        );
-        f1.putAll(f2);
-        f1.putAll(f3);
-
-        // 2-1: item特征处理
-        final Set<String> itemFeatureSet = new HashSet<>(Arrays.asList(
-                "total_time", "play_count_total",
-                "i_1day_exp_cnt", "i_1day_click_cnt", "i_1day_share_cnt", "i_1day_return_cnt",
-                "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt"
-        ));
-
-        List<RankItem> rankItems = CommonCollectionUtils.toList(videos, RankItem::new);
-        List<Long> videoIds = CommonCollectionUtils.toListDistinct(videos, Video::getVideoId);
-        List<String> videoFeatureKeys = videoIds.stream().map(r -> "video_info_" + r)
-                .collect(Collectors.toList());
-        List<String> videoFeatures = redisTemplate.opsForValue().multiGet(videoFeatureKeys);
-        if (videoFeatures != null) {
-            for (int i = 0; i < videoFeatures.size(); ++i) {
-                String vF = videoFeatures.get(i);
-                Map<String, String> vfMap = new HashMap<>();
-                if (vF == null) {
-                    continue;
-                }
-                try {
-                    vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {
-                    }, vfMap);
-                    Iterator<Map.Entry<String, String>> iteratorIn = vfMap.entrySet().iterator();
-                    while (iteratorIn.hasNext()) {
-                        Map.Entry<String, String> entry = iteratorIn.next();
-                        if (!itemFeatureSet.contains(entry.getKey())) {
-                            iteratorIn.remove();
-                        }
-                    }
-                    Map<String, String> f4 = RankExtractorItemFeature.getItemRateFeature(vfMap);
-                    Map<String, String> f5 = RankExtractorItemFeature.cntFeatureChange(vfMap,
-                            new HashSet<String>(Arrays.asList(
-                                    "total_time", "play_count_total",
-                                    "i_1day_exp_cnt", "i_1day_click_cnt", "i_1day_share_cnt", "i_1day_return_cnt",
-                                    "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt"))
-                    );
-                    f4.putAll(f5);
-                    rankItems.get(i).setFeatureMap(f4);
-                } catch (Exception e) {
-                    log.error(String.format("parse video json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-            }
-        }
-        // 2-2: item 实时特征处理
-        List<String> rtFeaPartKey = new ArrayList<>(Arrays.asList("item_rt_fea_1day_partition", "item_rt_fea_1h_partition"));
-        List<String> rtFeaPart = this.redisTemplate.opsForValue().multiGet(rtFeaPartKey);
-        Calendar calendar = Calendar.getInstance();
-        String date = new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
-        String hour = new SimpleDateFormat("HH").format(calendar.getTime());
-        String rtFeaPart1day = date + hour;
-        String rtFeaPart1h = date + hour;
-        if (rtFeaPart != null) {
-            if (rtFeaPart.get(0) != null) {
-                rtFeaPart1day = rtFeaPart.get(0);
-            }
-            if (rtFeaPart.get(1) != null) {
-                rtFeaPart1h = rtFeaPart.get(1);
-            }
-        }
-
-        List<String> videoRtKeys1 = videoIds.stream().map(r -> "item_rt_fea_1day_" + r)
-                .collect(Collectors.toList());
-        List<String> videoRtKeys2 = videoIds.stream().map(r -> "item_rt_fea_1h_" + r)
-                .collect(Collectors.toList());
-        videoRtKeys1.addAll(videoRtKeys2);
-        List<String> videoRtFeatures = this.redisTemplate.opsForValue().multiGet(videoRtKeys1);
-
-
-        if (videoRtFeatures != null) {
-            int j = 0;
-            for (RankItem item : rankItems) {
-                String vF = videoRtFeatures.get(j);
-                ++j;
-                if (vF == null) {
-                    continue;
-                }
-                Map<String, String> vfMap = new HashMap<>();
-                Map<String, Map<String, Double>> vfMapNew = new HashMap<>();
-                try {
-                    vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {
-                    }, vfMap);
-                    for (Map.Entry<String, String> entry : vfMap.entrySet()) {
-                        String value = entry.getValue();
-                        if (value == null) {
-                            continue;
-                        }
-                        String[] var1 = value.split(",");
-                        Map<String, Double> tmp = new HashMap<>();
-                        for (String var2 : var1) {
-                            String[] var3 = var2.split(":");
-                            tmp.put(var3[0], Double.valueOf(var3[1]));
-                        }
-                        vfMapNew.put(entry.getKey(), tmp);
-                    }
-                } catch (Exception e) {
-                    log.error(String.format("parse video item_rt_fea_1day_ json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-                Map<String, String> f8 = RankExtractorItemFeature.getItemRealtimeRate(vfMapNew, rtFeaPart1day);
-                item.getFeatureMap().putAll(f8);
-            }
-            for (RankItem item : rankItems) {
-                String vF = videoRtFeatures.get(j);
-                ++j;
-                if (vF == null) {
-                    continue;
-                }
-                Map<String, String> vfMap = new HashMap<>();
-                Map<String, Map<String, Double>> vfMapNew = new HashMap<>();
-                try {
-                    vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {
-                    }, vfMap);
-                    for (Map.Entry<String, String> entry : vfMap.entrySet()) {
-                        String value = entry.getValue();
-                        if (value == null) {
-                            continue;
-                        }
-                        String[] var1 = value.split(",");
-                        Map<String, Double> tmp = new HashMap<>();
-                        for (String var2 : var1) {
-                            String[] var3 = var2.split(":");
-                            tmp.put(var3[0], Double.valueOf(var3[1]));
-                        }
-                        vfMapNew.put(entry.getKey(), tmp);
-                    }
-                } catch (Exception e) {
-                    log.error(String.format("parse video item_rt_fea_1h_ json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-                Map<String, String> f8 = RankExtractorItemFeature.getItemRealtimeRate(vfMapNew, rtFeaPart1h);
-                item.getFeatureMap().putAll(f8);
-            }
-        }
-
-
-        List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_CONF)
-                .scoring(sceneFeatureMap, userFeatureMap, rankItems);
-        return CommonCollectionUtils.toList(rovRecallScore, i -> {
-            // hard code 将排序分数 赋值给video的sortScore
-            Video v = i.getVideo();
-            v.setScoreStr(i.getScoreStr());
-            v.setScoreRos(i.getScoreRos());
-            return v;
-        });
-    }
-
-    private Map<String, String> getSceneFeature(RankParam param) {
-        Map<String, String> sceneFeatureMap = new HashMap<>();
-        String provinceCn = param.getProvince();
-        provinceCn = provinceCn.replaceAll("省$", "");
-        sceneFeatureMap.put("ctx_region", provinceCn);
-        String city = param.getCity();
-        if ("台北市".equals(city) |
-                "高雄市".equals(city) |
-                "台中市".equals(city) |
-                "桃园市".equals(city) |
-                "新北市".equals(city) |
-                "台南市".equals(city) |
-                "基隆市".equals(city) |
-                "吉林市".equals(city) |
-                "新竹市".equals(city) |
-                "嘉义市".equals(city)
-        ) {
-        } else {
-            city = city.replaceAll("市$", "");
-        }
-        sceneFeatureMap.put("ctx_city", city);
-
-        Calendar calendar = Calendar.getInstance();
-        sceneFeatureMap.put("ctx_week", (calendar.get(Calendar.DAY_OF_WEEK) + 6) % 7 + "");
-        sceneFeatureMap.put("ctx_hour", new SimpleDateFormat("HH").format(calendar.getTime()));
-
-        return sceneFeatureMap;
-    }
-
-    public static void main(String[] args) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(Calendar.YEAR, 2022);
-        calendar.set(Calendar.MONTH, 0); // January is 0
-        calendar.set(Calendar.DAY_OF_MONTH, 1);
-        calendar.set(Calendar.HOUR_OF_DAY, 0);
-        calendar.set(Calendar.MINUTE, 12);
-        calendar.set(Calendar.SECOND, 30);
-        System.out.println(new SimpleDateFormat("HH").format(calendar.getTime()));
-
-        String provinceCn = "吉林省2";
-        provinceCn = provinceCn.replaceAll("省$", "");
-        System.out.println(provinceCn);
-    }
-
-}

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

@@ -1,374 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.rank.strategy;
-
-
-import com.alibaba.fastjson.JSONObject;
-import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
-import com.google.common.reflect.TypeToken;
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.model.Video;
-import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
-import com.tzld.piaoquan.recommend.server.service.rank.RankService;
-import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorItemFeature;
-import com.tzld.piaoquan.recommend.server.service.rank.extractor.RankExtractorUserFeature;
-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.JSONUtils;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
-import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-import org.springframework.stereotype.Service;
-
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * @author zhangbo
- * @desc 模型的排序实验
- */
-@Service
-@Slf4j
-public class RankStrategy4Rankv2Model extends RankService {
-
-    @ApolloJsonValue("${video.model.weightv2:}")
-    private Map<String, Double> mergeWeight;
-    final private String CLASS_NAME = this.getClass().getSimpleName();
-
-//    public Video getTestVideo(Long id, String s){
-//        Video a1 = new Video();
-//        a1.setVideoId(id);
-//        a1.setFlowPool(s);
-//        a1.setPushFrom("recall_pool_region_h");
-//        return a1;
-//    }
-    @Override
-    public List<Video> mergeAndRankRovRecall(RankParam param) {
-
-        //-------------------地域内部融合-------------------
-        List<Video> rovRecallRank = new ArrayList<>();
-//        rovRecallRank.add(0, getTestVideo(1070462L, ""));
-//        rovRecallRank.add(0, getTestVideo(1085062L, ""));
-        rovRecallRank.addAll(extractAndSort(param, RegionHRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionHDupRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, Region24HRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionRelative24HRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, RegionRelative24HDupRecallStrategy.PUSH_FORM));
-
-        //-------------------地域内部去重+截断-------------------
-        removeDuplicate(rovRecallRank);
-        rovRecallRank = rovRecallRank.size() <= param.getSize()
-                ? rovRecallRank
-                : rovRecallRank.subList(0, param.getSize());
-
-        //-------------------地域 sim returnv2 融合-------------------
-        rovRecallRank.addAll(extractAndSort(param, SimHotVideoRecallStrategy.PUSH_FORM));
-        rovRecallRank.addAll(extractAndSort(param, ReturnVideoRecallStrategy.PUSH_FORM));
-        //-------------------地域 sim returnv2 去重-------------------
-        removeDuplicate(rovRecallRank);
-
-        //-------------------排-------------------
-        //-------------------序-------------------
-        //-------------------逻-------------------
-        //-------------------辑-------------------
-        List<String> videoIdKeys = rovRecallRank.stream()
-                .map(t -> param.getRankKeyPrefix() + t.getVideoId())
-                .collect(Collectors.toList());
-        List<String> videoScores = this.redisTemplate.opsForValue().multiGet(videoIdKeys);
-        if (CollectionUtils.isNotEmpty(videoScores)
-                && videoScores.size() == rovRecallRank.size()) {
-            for (int i = 0; i < videoScores.size(); i++) {
-                rovRecallRank.get(i).setSortScore(NumberUtils.toDouble(videoScores.get(i), 0.0));
-            }
-            Collections.sort(rovRecallRank, Comparator.comparingDouble(o -> -o.getSortScore()));
-        }
-
-        //------------------- todo zhangbo 增加排序str ros模型逻辑 合并二者得分-------------------
-        List<Video> videosWithModel = model(rovRecallRank, param);
-        Map<String, Double> mergeWeight = this.mergeWeight == null? new HashMap<>(): this.mergeWeight;
-        double alpha = mergeWeight.getOrDefault("alpha", 1.0D);
-        double beta = mergeWeight.getOrDefault("beta", 0.0D);
-        double gamma = mergeWeight.getOrDefault("gamma", 0.0D);
-        for (Video v : videosWithModel){
-            double score = alpha * v.getSortScore() + beta * v.getScoreStr() + gamma * v.getScoreRos();
-            if (mergeWeight.containsKey("mul") && mergeWeight.getOrDefault("mul", 0.0D) > 0.5){
-                score = alpha * v.getSortScore() + (beta + v.getScoreStr()) * (gamma + v.getScoreRos());
-            }
-            v.setScoreRegion(v.getSortScore());
-            v.score = score;
-            v.setSortScore(score);
-        }
-        videosWithModel.sort(Comparator.comparingDouble(o -> -o.score));
-
-        //------------------- 增加日志 -------------------
-        int size = 4;
-        List<Long> oldRes = rovRecallRank.subList(0, Math.min(rovRecallRank.size(), size)).stream().map(r-> r.getVideoId()).collect(Collectors.toList());
-        List<Long> newRes = videosWithModel.subList(0, Math.min(videosWithModel.size(), size)).stream().map(r-> r.getVideoId()).collect(Collectors.toList());
-        int diffpos = 0;
-        int difftop = 0;
-        for (int i=0; i<newRes.size(); ++i){
-            if (!oldRes.get(i).equals(newRes.get(i))){
-                ++diffpos;
-            }
-            if (!oldRes.contains(newRes.get(i))){
-                ++difftop;
-            }
-        }
-
-        return videosWithModel;
-    }
-
-    public List<Video> model(List<Video> videos, RankParam param){
-        if (videos.isEmpty()){
-            return videos;
-        }
-
-        RedisStandaloneConfiguration redisSC = new RedisStandaloneConfiguration();
-        redisSC.setPort(6379);
-        redisSC.setPassword("Wqsd@2019");
-        redisSC.setHostName("r-bp1pi8wyv6lzvgjy5z.redis.rds.aliyuncs.com");
-        RedisConnectionFactory connectionFactory = new JedisConnectionFactory(redisSC);
-        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
-        redisTemplate.setConnectionFactory(connectionFactory);
-        redisTemplate.setDefaultSerializer(new StringRedisSerializer());
-        redisTemplate.afterPropertiesSet();
-
-        // 0: 场景特征处理
-        Map<String, String> sceneFeatureMap =  this.getSceneFeature(param);
-
-        // 1: user特征处理
-        Map<String, String> userFeatureMap = new HashMap<>();
-        if (param.getMid() != null && !param.getMid().isEmpty()){
-            String midKey = "user_info_4video_" + param.getMid();
-            String userFeatureStr = redisTemplate.opsForValue().get(midKey);
-            if (userFeatureStr != null){
-                try{
-                    userFeatureMap = JSONUtils.fromJson(userFeatureStr,
-                            new TypeToken<Map<String, String>>() {},
-                            userFeatureMap);
-                }catch (Exception e){
-                    log.error(String.format("parse user json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-            }else{
-                return videos;
-            }
-        }
-        final Set<String> userFeatureSet = new HashSet<>(Arrays.asList(
-            "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system",
-            "u_1day_exp_cnt", "u_1day_click_cnt", "u_1day_share_cnt", "u_1day_return_cnt",
-            "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt"
-        ));
-        Iterator<Map.Entry<String, String>> iterator = userFeatureMap.entrySet().iterator();
-        while (iterator.hasNext()) {
-            Map.Entry<String, String> entry = iterator.next();
-            if (!userFeatureSet.contains(entry.getKey())) {
-                iterator.remove();
-            }
-        }
-        Map<String, String> f1 = RankExtractorUserFeature.getOriginFeature(userFeatureMap,
-                new HashSet<String>(Arrays.asList(
-                    "machineinfo_brand", "machineinfo_model", "machineinfo_platform", "machineinfo_system"
-                ))
-        );
-        Map<String, String> f2 = RankExtractorUserFeature.getUserRateFeature(userFeatureMap);
-        Map<String, String> f3 = RankExtractorUserFeature.cntFeatureChange(userFeatureMap,
-                new HashSet<String>(Arrays.asList(
-                    "u_1day_exp_cnt", "u_1day_click_cnt", "u_1day_share_cnt", "u_1day_return_cnt",
-                    "u_3day_exp_cnt", "u_3day_click_cnt", "u_3day_share_cnt", "u_3day_return_cnt"
-                ))
-        );
-        f1.putAll(f2);
-        f1.putAll(f3);
-
-        // 2-1: item特征处理
-        final Set<String> itemFeatureSet = new HashSet<>(Arrays.asList(
-                "total_time", "play_count_total",
-                "i_1day_exp_cnt", "i_1day_click_cnt", "i_1day_share_cnt", "i_1day_return_cnt",
-                "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt"
-                ));
-
-        List<RankItem> rankItems = CommonCollectionUtils.toList(videos, RankItem::new);
-        List<Long> videoIds = CommonCollectionUtils.toListDistinct(videos, Video::getVideoId);
-        List<String> videoFeatureKeys = videoIds.stream().map(r-> "video_info_" + r)
-                .collect(Collectors.toList());
-        List<String> videoFeatures = redisTemplate.opsForValue().multiGet(videoFeatureKeys);
-        if (videoFeatures != null){
-            for (int i=0; i<videoFeatures.size(); ++i){
-                String vF = videoFeatures.get(i);
-                Map<String, String> vfMap = new HashMap<>();
-                if (vF == null){
-                    continue;
-                }
-                try{
-                    vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {}, vfMap);
-                    Iterator<Map.Entry<String, String>> iteratorIn = vfMap.entrySet().iterator();
-                    while (iteratorIn.hasNext()) {
-                        Map.Entry<String, String> entry = iteratorIn.next();
-                        if (!itemFeatureSet.contains(entry.getKey())) {
-                            iteratorIn.remove();
-                        }
-                    }
-                    Map<String, String> f4 = RankExtractorItemFeature.getItemRateFeature(vfMap);
-                    Map<String, String> f5 = RankExtractorItemFeature.cntFeatureChange(vfMap,
-                            new HashSet<String>(Arrays.asList(
-                            "total_time", "play_count_total",
-                            "i_1day_exp_cnt", "i_1day_click_cnt", "i_1day_share_cnt", "i_1day_return_cnt",
-                            "i_3day_exp_cnt", "i_3day_click_cnt", "i_3day_share_cnt", "i_3day_return_cnt"))
-                    );
-                    f4.putAll(f5);
-                    rankItems.get(i).setFeatureMap(f4);
-                }catch (Exception e){
-                    log.error(String.format("parse video json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-            }
-        }
-        // 2-2: item 实时特征处理
-        List<String> rtFeaPartKey = new ArrayList<>(Arrays.asList("item_rt_fea_1day_partition", "item_rt_fea_1h_partition"));
-        List<String> rtFeaPart = this.redisTemplate.opsForValue().multiGet(rtFeaPartKey);
-        Calendar calendar = Calendar.getInstance();
-        String date = new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());
-        String hour = new SimpleDateFormat("HH").format(calendar.getTime());
-        String rtFeaPart1day = date + hour;
-        String rtFeaPart1h = date + hour;
-        if (rtFeaPart != null){
-            if (rtFeaPart.get(0) != null){
-                rtFeaPart1day = rtFeaPart.get(0);
-            }
-            if (rtFeaPart.get(1) != null){
-                rtFeaPart1h = rtFeaPart.get(1);
-            }
-        }
-
-        List<String> videoRtKeys1 = videoIds.stream().map(r-> "item_rt_fea_1day_" + r)
-                .collect(Collectors.toList());
-        List<String> videoRtKeys2 = videoIds.stream().map(r-> "item_rt_fea_1h_" + r)
-                .collect(Collectors.toList());
-        videoRtKeys1.addAll(videoRtKeys2);
-        List<String> videoRtFeatures = this.redisTemplate.opsForValue().multiGet(videoRtKeys1);
-
-
-        if (videoRtFeatures != null){
-            int j = 0;
-            for (RankItem item: rankItems){
-                String vF = videoRtFeatures.get(j);
-                ++j;
-                if (vF == null){
-                    continue;
-                }
-                Map<String, String> vfMap = new HashMap<>();
-                Map<String, Map<String, Double>> vfMapNew = new HashMap<>();
-                try{
-                    vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {}, vfMap);
-                    for (Map.Entry<String, String> entry : vfMap.entrySet()){
-                        String value = entry.getValue();
-                        if (value == null){
-                            continue;
-                        }
-                        String [] var1 = value.split(",");
-                        Map<String, Double> tmp = new HashMap<>();
-                        for (String var2 : var1){
-                            String [] var3 = var2.split(":");
-                            tmp.put(var3[0], Double.valueOf(var3[1]));
-                        }
-                        vfMapNew.put(entry.getKey(), tmp);
-                    }
-                }catch (Exception e){
-                    log.error(String.format("parse video item_rt_fea_1day_ json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-                Map<String, String> f8 = RankExtractorItemFeature.getItemRealtimeRate(vfMapNew, rtFeaPart1day);
-                item.getFeatureMap().putAll(f8);
-            }
-            for (RankItem item: rankItems){
-                String vF = videoRtFeatures.get(j);
-                ++j;
-                if (vF == null){
-                    continue;
-                }
-                Map<String, String> vfMap = new HashMap<>();
-                Map<String, Map<String, Double>> vfMapNew = new HashMap<>();
-                try{
-                    vfMap = JSONUtils.fromJson(vF, new TypeToken<Map<String, String>>() {}, vfMap);
-                    for (Map.Entry<String, String> entry : vfMap.entrySet()){
-                        String value = entry.getValue();
-                        if (value == null){
-                            continue;
-                        }
-                        String [] var1 = value.split(",");
-                        Map<String, Double> tmp = new HashMap<>();
-                        for (String var2 : var1){
-                            String [] var3 = var2.split(":");
-                            tmp.put(var3[0], Double.valueOf(var3[1]));
-                        }
-                        vfMapNew.put(entry.getKey(), tmp);
-                    }
-                }catch (Exception e){
-                    log.error(String.format("parse video item_rt_fea_1h_ json is wrong in {} with {}", this.CLASS_NAME, e));
-                }
-                Map<String, String> f8 = RankExtractorItemFeature.getItemRealtimeRate(vfMapNew, rtFeaPart1h);
-                item.getFeatureMap().putAll(f8);
-            }
-        }
-
-
-
-        List<RankItem> rovRecallScore = ScorerUtils.getScorerPipeline(ScorerUtils.BASE_CONF)
-                .scoring(sceneFeatureMap, userFeatureMap, rankItems);
-        return CommonCollectionUtils.toList(rovRecallScore, i -> {
-            // hard code 将排序分数 赋值给video的sortScore
-            Video v = i.getVideo();
-            v.setScoreStr(i.getScoreStr());
-            v.setScoreRos(i.getScoreRos());
-            return v;
-        });
-    }
-
-    private Map<String, String> getSceneFeature(RankParam param) {
-        Map<String, String> sceneFeatureMap = new HashMap<>();
-        String provinceCn = param.getProvince();
-        provinceCn = provinceCn.replaceAll("省$", "");
-        sceneFeatureMap.put("ctx_region", provinceCn);
-        String city = param.getCity();
-        if ("台北市".equals(city) |
-            "高雄市".equals(city) |
-            "台中市".equals(city) |
-            "桃园市".equals(city) |
-            "新北市".equals(city) |
-            "台南市".equals(city) |
-            "基隆市".equals(city) |
-            "吉林市".equals(city) |
-            "新竹市".equals(city) |
-            "嘉义市".equals(city)
-        ){
-        }else{
-            city = city.replaceAll("市$", "");
-        }
-        sceneFeatureMap.put("ctx_city", city);
-
-        Calendar calendar = Calendar.getInstance();
-        sceneFeatureMap.put("ctx_week", (calendar.get(Calendar.DAY_OF_WEEK) + 6) % 7 + "");
-        sceneFeatureMap.put("ctx_hour", new SimpleDateFormat("HH").format(calendar.getTime()));
-
-        return sceneFeatureMap;
-    }
-
-    public static void main(String[] args) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(Calendar.YEAR, 2022);
-        calendar.set(Calendar.MONTH, 0); // January is 0
-        calendar.set(Calendar.DAY_OF_MONTH, 1);
-        calendar.set(Calendar.HOUR_OF_DAY, 0);
-        calendar.set(Calendar.MINUTE, 12);
-        calendar.set(Calendar.SECOND, 30);
-        System.out.println(new SimpleDateFormat("HH").format(calendar.getTime()));
-
-        String provinceCn = "吉林省2";
-        provinceCn = provinceCn.replaceAll("省$", "");
-        System.out.println(provinceCn);
-    }
-
-}