丁云鹏 3 месяцев назад
Родитель
Сommit
5d413ad958
29 измененных файлов с 0 добавлено и 2175 удалено
  1. 0 19
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseGBDTModelScorer.java
  2. 0 20
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseLRV2ModelScorer.java
  3. 0 32
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseThompsonSamplingScorer.java
  4. 0 33
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseXGBoostModelScorer.java
  5. 0 159
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogRovLRScorer.java
  6. 0 140
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogThompsonScorer.java
  7. 0 120
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VovH24Weight562Scorer.java
  8. 0 190
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VovH24WeightScorer.java
  9. 0 209
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VovH24WeightV2Scorer.java
  10. 0 196
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/GBDTModel.java
  11. 0 111
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/LRV2Model.java
  12. 0 90
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/ThompsonSamplingModel.java
  13. 0 46
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/VovH24WeightModel.java
  14. 0 52
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/Model4Recall2List.java
  15. 0 48
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/Model4RecallList.java
  16. 0 56
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/Model4RecallVovLongTerm.java
  17. 0 44
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/VideoTagModel4RecallMap.java
  18. 0 3
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/BlessRecallScore.java
  19. 0 59
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/ContentBaseRecallScore.java
  20. 0 43
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/DynamicGaussianFunction.java
  21. 0 175
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/FestivalRecallScore.java
  22. 0 36
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV2.java
  23. 0 41
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV3.java
  24. 0 33
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV4.java
  25. 0 34
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV5HighValue.java
  26. 0 38
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV5RootRov.java
  27. 0 70
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV7VovLongTerm.java
  28. 0 39
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/ShareDeepRecallScore.java
  29. 0 39
      recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/ShareWidthRecallScore.java

+ 0 - 19
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseGBDTModelScorer.java

@@ -1,19 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.tzld.piaoquan.recommend.server.service.score.model.GBDTModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class BaseGBDTModelScorer extends AbstractScorer {
-    private static Logger LOGGER = LoggerFactory.getLogger(BaseGBDTModelScorer.class);
-
-    public BaseGBDTModelScorer(ScorerConfigInfo scorerConfigInfo) {
-        super(scorerConfigInfo);
-    }
-
-    @Override
-    public synchronized void loadModel() {
-        doLoadModel(GBDTModel.class);
-    }
-
-}

+ 0 - 20
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseLRV2ModelScorer.java

@@ -1,20 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.tzld.piaoquan.recommend.server.service.score.model.LRV2Model;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public abstract class BaseLRV2ModelScorer extends AbstractScorer {
-
-    private static Logger LOGGER = LoggerFactory.getLogger(BaseLRV2ModelScorer.class);
-
-    public BaseLRV2ModelScorer(ScorerConfigInfo scorerConfigInfo) {
-        super(scorerConfigInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(LRV2Model.class);
-    }
-}

+ 0 - 32
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseThompsonSamplingScorer.java

@@ -1,32 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.service.score.model.ThompsonSamplingModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Map;
-
-
-public abstract class BaseThompsonSamplingScorer extends AbstractScorer {
-
-    private static Logger LOGGER = LoggerFactory.getLogger(BaseThompsonSamplingScorer.class);
-
-    public BaseThompsonSamplingScorer(ScorerConfigInfo scorerConfigInfo) {
-        super(scorerConfigInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(ThompsonSamplingModel.class);
-    }
-    @Override
-    public List<RankItem> scoring(final Map<String, String> sceneFeatureMap,
-                                           final Map<String, String> userFeatureMap,
-                                           final List<RankItem> rankItems){
-
-        return rankItems;
-    }
-
-}

+ 0 - 33
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/BaseXGBoostModelScorer.java

@@ -1,33 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.google.common.reflect.TypeToken;
-import com.typesafe.config.ConfigObject;
-import com.typesafe.config.ConfigValue;
-import com.tzld.piaoquan.recommend.server.service.score.model.XGBoostModel;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-
-
-public abstract class BaseXGBoostModelScorer extends AbstractScorer {
-
-    private static Logger LOGGER = LoggerFactory.getLogger(BaseXGBoostModelScorer.class);
-
-    public BaseXGBoostModelScorer(ScorerConfigInfo scorerConfigInfo) {
-        super(scorerConfigInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(XGBoostModel.class);
-        XGBoostModel model = (XGBoostModel) this.getModel();
-        ConfigObject paramMap = scorerConfigInfo.getParamMap();
-        if (paramMap != null) {
-            ConfigValue value = paramMap.get("features");
-            List<String> features = (List<String>) value.unwrapped();
-            model.setFeatures(features.toArray(new String[features.size()]));
-        }
-    }
-}

+ 0 - 159
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogRovLRScorer.java

@@ -1,159 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-
-import com.tzld.piaoquan.recommend.feature.domain.video.base.UserFeature;
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.service.score.model.LRV2Model;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.*;
-import java.util.concurrent.*;
-
-
-public class VlogRovLRScorer extends BaseLRV2ModelScorer {
-
-    private static final int LOCAL_TIME_OUT = 150;
-    private final static Logger LOGGER = LoggerFactory.getLogger(VlogRovLRScorer.class);
-    private static final ExecutorService executorService = Executors.newFixedThreadPool(128);
-
-
-    public VlogRovLRScorer(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-
-    @Override
-    public List<RankItem> scoring(final ScoreParam param,
-                                  final UserFeature userFeature,
-                                  final List<RankItem> rankItems) {
-        throw new NoSuchMethodError();
-    }
-
-    @Override
-    public List<RankItem> scoring(final Map<String, String> sceneFeatureMap,
-                                  final Map<String, String> userFeatureMap,
-                                  final List<RankItem> rankItems) {
-        if (CollectionUtils.isEmpty(rankItems)) {
-            return rankItems;
-        }
-
-        long startTime = System.currentTimeMillis();
-        LRV2Model model = (LRV2Model) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        List<RankItem> result = rankItems;
-        result = rankByJava(
-                sceneFeatureMap, userFeatureMap, rankItems
-        );
-
-        LOGGER.debug("ctr ranker time java items size={}, time={} ", result != null ? result.size() : 0,
-                System.currentTimeMillis() - startTime);
-
-        return result;
-    }
-
-    private List<RankItem> rankByJava(final Map<String, String> sceneFeatureMap,
-                                      final Map<String, String> userFeatureMap,
-                                      final List<RankItem> items) {
-        long startTime = System.currentTimeMillis();
-        LRV2Model model = (LRV2Model) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        // 所有都参与打分,按照ctr排序
-        multipleCtrScore(items, userFeatureMap, sceneFeatureMap, model);
-
-        // debug log
-        if (LOGGER.isDebugEnabled()) {
-            for (int i = 0; i < items.size(); i++) {
-                LOGGER.debug("before enter feeds model predict ctr score [{}] [{}]", items.get(i), items.get(i));
-            }
-        }
-
-        Collections.sort(items);
-
-        LOGGER.debug("ctr ranker java execute time: [{}]", System.currentTimeMillis() - startTime);
-        LOGGER.debug("[ctr ranker time java] items size={}, cost={} ", items != null ? items.size() : 0,
-                System.currentTimeMillis() - startTime);
-        return items;
-    }
-
-    private void multipleCtrScore(final List<RankItem> items,
-                                  final Map<String, String> userFeatureMap,
-                                  final Map<String, String> sceneFeatureMap,
-                                  final LRV2Model model) {
-
-        List<Callable<Object>> calls = new ArrayList<Callable<Object>>();
-        for (int index = 0; index < items.size(); index++) {
-            final int fIndex = index;
-            calls.add(new Callable<Object>() {
-                @Override
-                public Object call() throws Exception {
-                    try {
-                        calcScore(model, items.get(fIndex), userFeatureMap, sceneFeatureMap);
-                    } catch (Exception e) {
-                        LOGGER.error("ctr exception: [{}] [{}]", items.get(fIndex).videoId, ExceptionUtils.getFullStackTrace(e));
-                    }
-                    return new Object();
-                }
-            });
-        }
-
-        List<Future<Object>> futures = null;
-        try {
-            futures = executorService.invokeAll(calls, LOCAL_TIME_OUT, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException e) {
-            LOGGER.error("execute invoke fail: {}", ExceptionUtils.getFullStackTrace(e));
-        }
-
-        //等待所有请求的结果返回, 超时也返回
-        int cancel = 0;
-        if (futures != null) {
-            for (Future<Object> future : futures) {
-                try {
-                    if (!future.isDone() || future.isCancelled() || future.get() == null) {
-                        cancel++;
-                    }
-                } catch (InterruptedException e) {
-                    LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
-                } catch (ExecutionException e) {
-                    LOGGER.error("ExecutionException {},{}", sceneFeatureMap.size(),
-                            ExceptionUtils.getFullStackTrace(e));
-                }
-            }
-        }
-    }
-
-    public double calcScore(final LRV2Model lrModel,
-                            final RankItem item,
-                            final Map<String, String> userFeatureMap,
-                            final Map<String, String> sceneFeatureMap) {
-
-
-        Map<String, String> featureMap = new HashMap<>();
-        if (MapUtils.isNotEmpty(item.getFeatureMap())) {
-            featureMap.putAll(item.getFeatureMap());
-        }
-        if (MapUtils.isNotEmpty(userFeatureMap)) {
-            featureMap.putAll(userFeatureMap);
-        }
-        if (MapUtils.isNotEmpty(sceneFeatureMap)) {
-            featureMap.putAll(sceneFeatureMap);
-        }
-
-        double pro = 0.0;
-        if (MapUtils.isNotEmpty(featureMap)) {
-            try {
-                pro = lrModel.score(featureMap);
-                // LOGGER.info("fea : {}, score:{}", JSONUtils.toJson(featureMap), pro);
-            } catch (Exception e) {
-                LOGGER.error("score error for doc={} exception={}", item.getVideoId(), ExceptionUtils.getFullStackTrace(e));
-            }
-        }
-        item.setScoreRov(pro);
-        return pro;
-    }
-}

+ 0 - 140
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogThompsonScorer.java

@@ -1,140 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.tzld.piaoquan.recommend.feature.domain.video.base.RequestContext;
-import com.tzld.piaoquan.recommend.feature.domain.video.base.UserFeature;
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.service.score.model.ThompsonSamplingModel;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.*;
-
-
-//@Service
-public class VlogThompsonScorer extends BaseThompsonSamplingScorer {
-
-    private static final int LOCAL_TIME_OUT = 150;
-    private final static Logger LOGGER = LoggerFactory.getLogger(VlogThompsonScorer.class);
-    private static final ExecutorService executorService = Executors.newFixedThreadPool(128);
-
-    public VlogThompsonScorer(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-
-    @Override
-    public List<RankItem> scoring(final ScoreParam param,
-                                  final UserFeature userFeature,
-                                  final List<RankItem> rankItems) {
-
-        if (userFeature == null || CollectionUtils.isEmpty(rankItems)) {
-            return rankItems;
-        }
-
-        long startTime = System.currentTimeMillis();
-        ThompsonSamplingModel model = (ThompsonSamplingModel) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        List<RankItem> result = rankItems;
-        result = rankByJava(rankItems, param.getRequestContext(), userFeature);
-
-        LOGGER.debug("thompson sampling ctr ranker time java items size={}, time={} ", result != null ? result.size() : 0,
-                System.currentTimeMillis() - startTime);
-
-        return result;
-    }
-
-    private List<RankItem> rankByJava(final List<RankItem> items,
-                                      final RequestContext requestContext,
-                                      final UserFeature user) {
-        long startTime = System.currentTimeMillis();
-        ThompsonSamplingModel model = (ThompsonSamplingModel) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        // 所有都参与打分,按照ROV Thompson排序
-        multipleCtrScore(items, model);
-
-        // debug log
-        if (LOGGER.isDebugEnabled()) {
-            for (int i = 0; i < items.size(); i++) {
-                LOGGER.debug("after enter feeds model predict ctr score [{}] [{}]", items.get(i), items.get(i).getScore());
-            }
-        }
-
-        LOGGER.debug("thompson ranker java execute time: [{}]", System.currentTimeMillis() - startTime);
-        LOGGER.debug("[thompson ranker time java] items size={}, cost={} ", items != null ? items.size() : 0,
-                System.currentTimeMillis() - startTime);
-        return items;
-    }
-
-
-    /**
-     * 计算 predict ROV
-     */
-    public double calcScore(final ThompsonSamplingModel model,
-                            final RankItem item) {
-        double score = 0d;
-        try {
-            score = model.score(item);
-        } catch (Exception e) {
-            LOGGER.error("score error for doc={} exception={}", item.getVideo(), ExceptionUtils.getFullStackTrace(e));
-        }
-        item.setScore(score);
-        return score;
-    }
-
-
-    /**
-     * 并行打分 Thompson ROV
-     *
-     * @param items
-     * @param model
-     */
-    private void multipleCtrScore(final List<RankItem> items,
-                                  final ThompsonSamplingModel model) {
-
-        List<Callable<Object>> calls = new ArrayList<Callable<Object>>();
-        for (int index = 0; index < items.size(); index++) {
-            final int fIndex = index;
-            items.get(fIndex).setScore(0.0);   //设置为原始值为0
-            calls.add(new Callable<Object>() {
-                @Override
-                public Object call() throws Exception {
-                    try {
-                        calcScore(model, items.get(fIndex));
-                    } catch (Exception e) {
-                        LOGGER.error("thompson exception: [{}] [{}]", items.get(fIndex).videoId, ExceptionUtils.getFullStackTrace(e));
-                    }
-                    return new Object();
-                }
-            });
-        }
-
-        List<Future<Object>> futures = null;
-        try {
-            futures = executorService.invokeAll(calls, LOCAL_TIME_OUT, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException e) {
-            LOGGER.error("execute invoke fail: {}", ExceptionUtils.getFullStackTrace(e));
-        }
-
-        //等待所有请求的结果返回, 超时也返回
-        int cancel = 0;
-        if (futures != null) {
-            for (Future<Object> future : futures) {
-                try {
-                    if (!future.isDone() || future.isCancelled() || future.get() == null) {
-                        cancel++;
-                    }
-                } catch (InterruptedException e) {
-                    LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
-                } catch (ExecutionException e) {
-                    LOGGER.error("ExecutionException {},{}", ExceptionUtils.getFullStackTrace(e));
-                }
-            }
-        }
-        LOGGER.debug("ROV-Thompson Score {}, Total: {}, Cancel: {}", items.size(), cancel);
-    }
-}

+ 0 - 120
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VovH24Weight562Scorer.java

@@ -1,120 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Slf4j
-public class VovH24Weight562Scorer {
-    public static void scoring(Map<String, Double> mergeWeight, Map<String, Map<String, String>> vid2VovFeatureMap, final List<RankItem> items) {
-        try {
-            if (MapUtils.isEmpty(mergeWeight) || MapUtils.isEmpty(vid2VovFeatureMap) || CollectionUtils.isEmpty(items)) {
-                return;
-            }
-
-            // 融合权重
-            double vov_thresh = mergeWeight.getOrDefault("vov_thresh", 0.1);
-            double view_thresh = mergeWeight.getOrDefault("view_thresh", 1535.0);
-            double level50_vov = mergeWeight.getOrDefault("level50_vov", 0.123);
-            double level_95_vov = mergeWeight.getOrDefault("level_95_vov", 0.178);
-            double beta_vov = mergeWeight.getOrDefault("beta_vov", 100.0);
-
-            List<Double> weightList = new ArrayList<>(7);
-            weightList.add(mergeWeight.getOrDefault("d2_ago_vov_w", 0.0));
-            weightList.add(mergeWeight.getOrDefault("d1_ago_vov_w", 0.0));
-            weightList.add(mergeWeight.getOrDefault("h48_ago_vov_w", 0.0));
-            weightList.add(mergeWeight.getOrDefault("h24_ago_vov_w", 0.0));
-            weightList.add(mergeWeight.getOrDefault("h3_ago_vov_w", 0.0));
-            weightList.add(mergeWeight.getOrDefault("h2_ago_vov_w", 0.0));
-            weightList.add(mergeWeight.getOrDefault("h1_ago_vov_w", 0.0));
-
-            for (RankItem item : items) {
-                // 获取VoV输入特征
-                double h1_ago_vov = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("h1_ago_vov", "-2")); // 如果没有时,默认为多少?? 需要考虑
-                double h2_ago_vov = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("h2_ago_vov", "-2")); // 如果没有时,默认为多少?? 需要考虑
-                double h3_ago_vov = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("h3_ago_vov", "-2")); // 如果没有时,默认为多少?? 需要考虑
-                double h24_ago_vov = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("h24_ago_vov", "-2")); // 如果没有时,默认为多少?? 需要考虑
-                double h48_ago_vov = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("h48_ago_vov", "-2")); // 如果没有时,默认为多少?? 需要考虑
-                double d1_ago_vov = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("d1_ago_vov", "-2")); // 如果没有时,默认为多少?? 需要考虑
-                double d2_ago_vov = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("d2_ago_vov", "-2")); // 如果没有时,默认为多少?? 需要考虑
-                double h1_ago_view = Double.parseDouble(vid2VovFeatureMap.getOrDefault(item.getVideoId() + "", new HashMap<>())
-                        .getOrDefault("h1_ago_view", "-2")); // 如果没有时,默认为多少?? 需要考虑
-
-                // log feature
-                item.getScoresMap().put("h1_ago_vov", h1_ago_vov);
-                item.getScoresMap().put("h2_ago_vov", h2_ago_vov);
-                item.getScoresMap().put("h3_ago_vov", h3_ago_vov);
-                item.getScoresMap().put("h24_ago_vov", h24_ago_vov);
-                item.getScoresMap().put("h48_ago_vov", h48_ago_vov);
-                item.getScoresMap().put("d1_ago_vov", d1_ago_vov);
-                item.getScoresMap().put("d2_ago_vov", d2_ago_vov);
-                item.getScoresMap().put("h1_ago_view", h1_ago_view);
-
-                List<Double> featureList = new ArrayList<>(7);
-                featureList.add(d2_ago_vov);
-                featureList.add(d1_ago_vov);
-                featureList.add(h48_ago_vov);
-                featureList.add(h24_ago_vov);
-                featureList.add(h3_ago_vov);
-                featureList.add(h2_ago_vov);
-                featureList.add(h1_ago_vov);
-                double vovScore562 = calcScore(featureList, weightList, item, vov_thresh, view_thresh, h1_ago_view, level50_vov, level_95_vov, beta_vov);
-                item.getScoresMap().put("vovScore562", vovScore562);
-            }
-        } catch (Exception e) {
-            log.error(String.format("something is wrong in VovH24Weight562Scorer with {}", e));
-        }
-    }
-
-
-    private static double calcScore(List<Double> featureList, List<Double> weightList, RankItem rankItem,
-                                    double vov_thresh, double view_thresh, double h1_ago_view, double level50_vov, double level_95_vov, double beta_vov) {
-        // 检查 h1_ago_view 条件
-        if (h1_ago_view == -2 || h1_ago_view == -1 || h1_ago_view < view_thresh) {
-            return 0;
-        }
-
-        // 计算有效特征的总权重和得分
-        double score = 0;
-        List<Integer> validIndices = new ArrayList<>();
-        for (int i = 0; i < featureList.size(); i++) {
-            if (featureList.get(i) != -1) {
-                validIndices.add(i);
-            }
-        }
-
-        // 如果没有有效特征,返回 0
-        if (validIndices.isEmpty()) {
-            return 0;
-        }
-
-        // 计算得分,动态调整权重
-        for (int index : validIndices) {
-            double weight = weightList.get(index);
-            score += featureList.get(index) * weight;
-        }
-
-        // 调整vov
-        if (score < vov_thresh) {
-            score = 0;
-        } else {
-            double term1 = 1 / (1 + Math.exp(-1 * beta_vov * (score - level50_vov)));
-            double term2 = 1 + Math.exp(-1 * beta_vov * (level_95_vov - level50_vov));
-            score = term1 * term2;
-        }
-        return score;
-    }
-}

+ 0 - 190
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VovH24WeightScorer.java

@@ -1,190 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.tzld.piaoquan.recommend.feature.domain.video.base.UserFeature;
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.service.score.model.VovH24WeightModel;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.*;
-import java.util.concurrent.*;
-
-public class VovH24WeightScorer extends AbstractScorer {
-
-    private static final int LOCAL_TIME_OUT = 150;
-    private final static Logger LOGGER = LoggerFactory.getLogger(VlogRovFMScorer.class);
-    private static final ExecutorService executorService = Executors.newFixedThreadPool(128);
-
-    private static final Map<String, String> numeratorAndDenominatorMap = new HashMap<String, String>(32) {{
-        put("1_vovh0分子", "1_vovh分母");
-        put("2_vovh0分子", "2_vovh分母");
-        put("2_vovh1分子", "2_vovh分母");
-        put("3_vovh0分子", "3_vovh分母");
-        put("3_vovh1分子", "3_vovh分母");
-        put("3_vovh2分子", "3_vovh分母");
-        put("4_vovh0分子", "4_vovh分母");
-        put("4_vovh1分子", "4_vovh分母");
-        put("4_vovh3分子", "4_vovh分母");
-        put("7_vovh0分子", "7_vovh分母");
-        put("7_vovh1分子", "7_vovh分母");
-        put("7_vovh6分子", "7_vovh分母");
-        put("13_vovh0分子", "13_vovh分母");
-        put("13_vovh1分子", "13_vovh分母");
-        put("13_vovh12分子", "13_vovh分母");
-        put("25_vovh0分子", "25_vovh分母");
-        put("25_vovh1分子", "25_vovh分母");
-        put("25_vovh24分子", "25_vovh分母");
-        put("1_vovd0分子", "1_vovd分母");
-        put("2_vovd0分子", "2_vovd分母");
-        put("2_vovd1分子", "2_vovd分母");
-        put("3_vovd0分子", "3_vovd分母");
-        put("3_vovd1分子", "3_vovd分母");
-        put("3_vovd2分子", "3_vovd分母");
-    }};
-
-    public VovH24WeightScorer(ScorerConfigInfo scorerConfigInfo) {
-        super(scorerConfigInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(VovH24WeightModel.class);
-    }
-
-    @Override
-    public List<RankItem> scoring(ScoreParam param, UserFeature userFeature, List<RankItem> rankItems) {
-        throw new NoSuchMethodError();
-    }
-
-    @Override
-    public List<RankItem> scoring(final Map<String, String> sceneFeatureMap,
-                                  final Map<String, String> userFeatureMap,
-                                  final List<RankItem> rankItems) {
-        if (CollectionUtils.isEmpty(rankItems)) {
-            return rankItems;
-        }
-
-        long startTime = System.currentTimeMillis();
-        VovH24WeightModel model = (VovH24WeightModel) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        List<RankItem> result = rankByJava(
-                sceneFeatureMap, userFeatureMap, rankItems
-        );
-
-        LOGGER.debug("vovh24 scorer time java items size={}, time={} ",
-                result.size(), System.currentTimeMillis() - startTime);
-
-        return result;
-    }
-
-    private List<RankItem> rankByJava(final Map<String, String> sceneFeatureMap,
-                                      final Map<String, String> userFeatureMap,
-                                      final List<RankItem> items) {
-        long startTime = System.currentTimeMillis();
-        VovH24WeightModel model = (VovH24WeightModel) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        // 所有都参与打分,按照ctr排序
-        multipleCtrScore(items, userFeatureMap, sceneFeatureMap, model);
-
-        // debug log
-        if (LOGGER.isDebugEnabled()) {
-            for (RankItem item : items) {
-                LOGGER.debug("before enter feeds model predict ctr score [{}] [{}]", item, item);
-            }
-        }
-
-        Collections.sort(items);
-
-        LOGGER.debug("[vovh24 scorer time java] items size={}, cost={} ",
-                items.size(), System.currentTimeMillis() - startTime);
-        return items;
-    }
-
-    private void multipleCtrScore(final List<RankItem> items,
-                                  final Map<String, String> userFeatureMap,
-                                  final Map<String, String> sceneFeatureMap,
-                                  final VovH24WeightModel model) {
-
-        List<Callable<Object>> calls = new ArrayList<Callable<Object>>();
-        for (int index = 0; index < items.size(); index++) {
-            final int fIndex = index;
-            calls.add(new Callable<Object>() {
-                @Override
-                public Object call() throws Exception {
-                    try {
-                        calcScore(model, items.get(fIndex), userFeatureMap, sceneFeatureMap);
-                    } catch (Exception e) {
-                        LOGGER.error("vovh24 scorer exception: [{}] [{}]", items.get(fIndex).videoId, ExceptionUtils.getFullStackTrace(e));
-                    }
-                    return new Object();
-                }
-            });
-        }
-
-        List<Future<Object>> futures = null;
-        try {
-            futures = executorService.invokeAll(calls, LOCAL_TIME_OUT, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException e) {
-            LOGGER.error("execute invoke fail: {}", ExceptionUtils.getFullStackTrace(e));
-        }
-
-        // 等待所有请求的结果返回, 超时也返回
-        int cancel = 0;
-        if (futures != null) {
-            for (Future<Object> future : futures) {
-                try {
-                    if (!future.isDone() || future.isCancelled() || future.get() == null) {
-                        cancel++;
-                    }
-                } catch (InterruptedException e) {
-                    LOGGER.error("InterruptedException: ", e);
-                } catch (ExecutionException e) {
-                    LOGGER.error("ExecutionException {}, ", sceneFeatureMap.size(), e);
-                }
-            }
-        }
-    }
-
-    public double calcScore(final VovH24WeightModel model,
-                            final RankItem item,
-                            final Map<String, String> userFeatureMap,
-                            final Map<String, String> sceneFeatureMap) {
-
-        double vovScore = 0.0;
-        Map<String, String> featureMap = item.getFeatureMap();
-        String weightKey = sceneFeatureMap.getOrDefault("weightKey", "");
-        Map<String, Double> weightMap = model.getWeight(weightKey);
-        if (MapUtils.isNotEmpty(featureMap) && MapUtils.isNotEmpty(weightMap)) {
-            try {
-                double numerator = 0d;
-                double denominator = 0d;
-                for (Map.Entry<String, String> entry : numeratorAndDenominatorMap.entrySet()) {
-                    String numeratorKey = entry.getKey();
-                    String denominatorKey = entry.getValue();
-
-                    double up = Double.parseDouble(featureMap.getOrDefault(numeratorKey, "0d"));
-                    double down = Double.parseDouble(featureMap.getOrDefault(denominatorKey, "0d"));
-                    double weight = weightMap.getOrDefault(numeratorKey, 0d);
-
-                    numerator += up * weight;
-                    denominator += down * weight;
-
-                }
-
-                item.getScoresMap().put("numerator", numerator);
-                item.getScoresMap().put("denominator", denominator);
-                vovScore = denominator != 0.0 ? numerator / denominator : 0.0;
-            } catch (Exception e) {
-                LOGGER.error("vovh24 scorer error for doc={} exception={}", item.getVideoId(), ExceptionUtils.getFullStackTrace(e));
-            }
-        }
-        item.getScoresMap().put("vovScore", vovScore);
-        item.setVovScore(vovScore);
-        return vovScore;
-    }
-}

+ 0 - 209
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VovH24WeightV2Scorer.java

@@ -1,209 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score;
-
-import com.tzld.piaoquan.recommend.feature.domain.video.base.UserFeature;
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.service.score.model.VovH24WeightModel;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.*;
-import java.util.concurrent.*;
-
-public class VovH24WeightV2Scorer extends AbstractScorer {
-    private static final int LOCAL_TIME_OUT = 150;
-    private final static Logger LOGGER = LoggerFactory.getLogger(VlogRovFMScorer.class);
-    private static final ExecutorService executorService = Executors.newFixedThreadPool(128);
-    private static final Set<String> rateFeatureSet = new HashSet<>(Arrays.asList(
-            "1_vovh0",
-            "2_vovh0", "2_vovh1",
-            "3_vovh0", "3_vovh1", "3_vovh2",
-            "4_vovh0", "4_vovh1", "4_vovh3",
-            "7_vovh0", "7_vovh1", "7_vovh6",
-            "13_vovh0", "13_vovh1", "13_vovh12",
-            "25_vovh0", "25_vovh1", "25_vovh24",
-            "1_vovd0",
-            "2_vovd0", "2_vovd1",
-            "3_vovd0", "3_vovd1", "3_vovd2"
-    ));
-
-    private static final Set<String> integerFeatureSet = new HashSet<>(Arrays.asList(
-            "1_vovh0分子", "1_vovh分母",
-            "2_vovh0分子", "2_vovh1分子", "2_vovh分母",
-            "3_vovh0分子", "3_vovh1分子", "3_vovh2分子", "3_vovh分母",
-            "4_vovh0分子", "4_vovh1分子", "4_vovh3分子", "4_vovh分母",
-            "7_vovh0分子", "7_vovh1分子", "7_vovh6分子", "7_vovh分母",
-            "13_vovh0分子", "13_vovh1分子", "13_vovh12分子", "13_vovh分母",
-            "25_vovh0分子", "25_vovh1分子", "25_vovh24分子", "25_vovh分母",
-            "1_vovd0分子", "1_vovd分母",
-            "2_vovd0分子", "2_vovd1分子", "2_vovd分母",
-            "3_vovd0分子", "3_vovd1分子", "3_vovd2分子", "3_vovd分母"
-    ));
-
-    private static final Set<String> numerator567Set = new HashSet<>(Arrays.asList(
-            "1_vovh0分子", "2_vovh1分子", "3_vovh2分子", "4_vovh3分子",
-            "7_vovh6分子", "13_vovh12分子", "25_vovh24分子", "2_vovd1分子"
-    ));
-
-    private static final Set<String> denominator567Set = new HashSet<>(Arrays.asList(
-            "1_vovh分母", "2_vovh分母", "3_vovh分母", "4_vovh分母",
-            "7_vovh分母", "13_vovh分母", "25_vovh分母", "2_vovd分母"
-    ));
-
-
-    public VovH24WeightV2Scorer(ScorerConfigInfo scorerConfigInfo) {
-        super(scorerConfigInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(VovH24WeightModel.class);
-    }
-
-    @Override
-    public List<RankItem> scoring(ScoreParam param, UserFeature userFeature, List<RankItem> rankItems) {
-        throw new NoSuchMethodError();
-    }
-
-    @Override
-    public List<RankItem> scoring(final Map<String, String> sceneFeatureMap,
-                                  final Map<String, String> userFeatureMap,
-                                  final List<RankItem> rankItems) {
-        if (CollectionUtils.isEmpty(rankItems)) {
-            return rankItems;
-        }
-
-        long startTime = System.currentTimeMillis();
-        VovH24WeightModel model = (VovH24WeightModel) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        List<RankItem> result = rankByJava(
-                sceneFeatureMap, userFeatureMap, rankItems
-        );
-
-        LOGGER.debug("vovh24 scorer time java items size={}, time={} ",
-                result.size(), System.currentTimeMillis() - startTime);
-        return result;
-    }
-
-    private List<RankItem> rankByJava(final Map<String, String> sceneFeatureMap,
-                                      final Map<String, String> userFeatureMap,
-                                      final List<RankItem> items) {
-        long startTime = System.currentTimeMillis();
-        VovH24WeightModel model = (VovH24WeightModel) this.getModel();
-        LOGGER.debug("model size: [{}]", model.getModelSize());
-
-        // 所有都参与打分,按照ctr排序
-        multipleCtrScore(items, userFeatureMap, sceneFeatureMap, model);
-
-        // debug log
-        if (LOGGER.isDebugEnabled()) {
-            for (RankItem item : items) {
-                LOGGER.debug("before enter feeds model predict ctr score [{}] [{}]", item, item);
-            }
-        }
-
-        Collections.sort(items);
-
-        LOGGER.debug("[vovh24 scorer time java] items size={}, cost={} ",
-                items.size(), System.currentTimeMillis() - startTime);
-        return items;
-    }
-
-    private void multipleCtrScore(final List<RankItem> items,
-                                  final Map<String, String> userFeatureMap,
-                                  final Map<String, String> sceneFeatureMap,
-                                  final VovH24WeightModel model) {
-
-        List<Callable<Object>> calls = new ArrayList<Callable<Object>>();
-        for (int index = 0; index < items.size(); index++) {
-            final int fIndex = index;
-            calls.add(new Callable<Object>() {
-                @Override
-                public Object call() throws Exception {
-                    try {
-                        calcScore(model, items.get(fIndex), userFeatureMap, sceneFeatureMap);
-                    } catch (Exception e) {
-                        LOGGER.error("vovh24 scorer exception: [{}] [{}]", items.get(fIndex).videoId, ExceptionUtils.getFullStackTrace(e));
-                    }
-                    return new Object();
-                }
-            });
-        }
-
-        List<Future<Object>> futures = null;
-        try {
-            futures = executorService.invokeAll(calls, LOCAL_TIME_OUT, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException e) {
-            LOGGER.error("execute invoke fail: {}", ExceptionUtils.getFullStackTrace(e));
-        }
-
-        // 等待所有请求的结果返回, 超时也返回
-        int cancel = 0;
-        if (futures != null) {
-            for (Future<Object> future : futures) {
-                try {
-                    if (!future.isDone() || future.isCancelled() || future.get() == null) {
-                        cancel++;
-                    }
-                } catch (InterruptedException e) {
-                    LOGGER.error("InterruptedException: ", e);
-                } catch (ExecutionException e) {
-                    LOGGER.error("ExecutionException {}, ", sceneFeatureMap.size(), e);
-                }
-            }
-        }
-    }
-
-    public double calcScore(final VovH24WeightModel model,
-                            final RankItem item,
-                            final Map<String, String> userFeatureMap,
-                            final Map<String, String> sceneFeatureMap) {
-
-        double vovScore = 0.0;
-        Map<String, String> featureMap = item.getFeatureMap();
-        String weightKey = sceneFeatureMap.getOrDefault("weightKey", "");
-        Map<String, Double> weightMap = model.getWeight(weightKey);
-        if (MapUtils.isNotEmpty(featureMap) && MapUtils.isNotEmpty(weightMap)) {
-            try {
-                vovScore += weightMap.getOrDefault("bias", 0d);
-                for (String key : rateFeatureSet) {
-                    double val = Double.parseDouble(featureMap.getOrDefault(key, "0d"));
-                    double weight = weightMap.getOrDefault(key, 0d);
-                    vovScore += val * weight;
-                }
-                for (String key : integerFeatureSet) {
-                    double val = Double.parseDouble(featureMap.getOrDefault(key, "0d"));
-                    double weight = weightMap.getOrDefault(key, 0d);
-                    vovScore += Math.log(val + 1) * weight;
-                }
-                vovScore = Math.max(0, vovScore);
-            } catch (Exception e) {
-                LOGGER.error("vovh24 scorer error for doc={} exception={}", item.getVideoId(), ExceptionUtils.getFullStackTrace(e));
-            }
-        }
-
-        double vovScore567 = 0.0;
-        double numerator567 = 0D;
-        double denominator567 = 0D;
-        if (MapUtils.isNotEmpty(featureMap)) {
-            try {
-                for (String key : numerator567Set) {
-                    numerator567 += Double.parseDouble(featureMap.getOrDefault(key, "0d"));
-                }
-                for (String key : denominator567Set) {
-                    denominator567 += Double.parseDouble(featureMap.getOrDefault(key, "0d"));
-                }
-                vovScore567 = denominator567 != 0.0 ? numerator567 / denominator567 : 0.0;
-            } catch (Exception e) {
-                LOGGER.error("vovh24 567 scorer error for doc={} exception={}", item.getVideoId(), ExceptionUtils.getFullStackTrace(e));
-            }
-        }
-        item.getScoresMap().put("vovScore", vovScore);
-        item.getScoresMap().put("vovScore567", vovScore567);
-        item.setVovScore(vovScore);
-        return vovScore;
-    }
-}

+ 0 - 196
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/GBDTModel.java

@@ -1,196 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score.model;
-
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.util.*;
-
-
-
-public class GBDTModel extends Model {
-    private static final Logger LOGGER = LoggerFactory.getLogger(GBDTModel.class);
-    private static final float LINEAR_TRANSFORM_LOWER_BOUND = 0f;
-    private static final float LINEAR_TRANSFORM_SLOPE = 1f;
-    private int featureCount = 0;
-    private Map<String, Integer> featureIdMap = null;
-    private List<HashMap<Integer, Node>> boosterModel = null;
-
-    private float transform(final float score) {
-        return (score - LINEAR_TRANSFORM_LOWER_BOUND) * LINEAR_TRANSFORM_SLOPE;
-    }
-
-    private int getFeatureId(final String feature) {
-        return featureIdMap.containsKey(feature) ? featureIdMap.get(feature) : -1;
-    }
-
-    @Override
-    public int getModelSize() {
-        return boosterModel.size();
-    }
-
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws Exception {
-        List<HashMap<Integer, Node>> model = new ArrayList<HashMap<Integer, Node>>();
-        HashMap<Integer, Node> tree = null;
-
-        featureIdMap = new HashMap<String, Integer>();
-        featureCount = 0;
-
-        BufferedReader input = new BufferedReader(in);
-        String line;
-        while ((line = input.readLine()) != null) {
-            String[] tokens = line.trim().split(":");
-            if (tokens.length == 1) {
-                if (tokens[0].startsWith("booster")) {
-                    if (tree != null && tree.size() > 0) {
-                        model.add(tree);
-                    }
-
-                    tree = new HashMap<Integer, Node>();
-                }
-            } else if (tokens.length == 2) {
-                Node node = new Node();
-
-                Integer id = Integer.parseInt(tokens[0]);
-
-                String[] items = tokens[1].split(" ");
-                if (items.length == 1) {
-                    node.isLeaf = true;
-
-                    String[] dt = items[0].split("=");
-                    node.value = Float.parseFloat(dt[1]);
-                } else if (items.length == 2) {
-                    node.isLeaf = false;
-                    String[] fieldDescriptions = null;
-                    node.compareType = NodeCompareType.LT;
-                    if (items[0].substring(1, items[0].length() - 1).contains("<=")) {
-                        fieldDescriptions = items[0].substring(1, items[0].length() - 1).split("<=");
-                        node.compareType = NodeCompareType.LE;
-                    } else {
-                        fieldDescriptions = items[0].substring(1, items[0].length() - 1).split("<");
-                    }
-                    // feature to id
-                    int featureId = getFeatureId(fieldDescriptions[0]);
-                    if (featureId < 0) {
-                        featureIdMap.put(fieldDescriptions[0], featureCount);
-                        featureId = featureCount;
-                        featureCount += 1;
-                    }
-                    node.splitFeatureId = featureId;
-
-                    if (fieldDescriptions.length == 1) {
-                        node.fieldType = NodeFieldType.BINARY;
-                    } else {
-                        node.fieldType = NodeFieldType.QUANTITATIVE;
-                        node.splitCondition = Float.parseFloat(fieldDescriptions[1]);
-                    }
-
-                    String[] childrenDescriptions = items[1].split(",");
-                    for (String childDescription : childrenDescriptions) {
-                        String[] descs = childDescription.split("=");
-                        if (descs[0].equals("yes")) {
-                            node.yes = Integer.parseInt(descs[1]);
-                        } else if (descs[0].equals("no")) {
-                            node.no = Integer.parseInt(descs[1]);
-                        } else if (descs[0].equals("missing")) {
-                            node.missing = Integer.parseInt(descs[1]);
-                        }
-                    }
-                }
-                tree.put(id, node);
-            }
-        }
-        if (tree != null && !tree.isEmpty()) {
-            model.add(tree);
-        }
-
-        LOGGER.info("Boosted tree model load over and tree number is " + model.size());
-        input.close();
-        in.close();
-        if (model != null && model.size() > 0) {
-            boosterModel = model;
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    private float score(final Map<Integer, Node> tree, final boolean[] featureIsExists, final Float[] featureValues) {
-        int id = 0;
-        while (true) {
-            Node currentNode = tree.get(id);
-            if (currentNode.isLeaf) {
-                return currentNode.value;
-            }
-
-            if (currentNode.fieldType == NodeFieldType.BINARY) {
-                if (!featureIsExists[currentNode.splitFeatureId]) {
-                    id = currentNode.no;
-                } else {
-                    id = currentNode.yes;
-                }
-            } else if (currentNode.fieldType == NodeFieldType.QUANTITATIVE) {
-                if (!featureIsExists[currentNode.splitFeatureId]) {
-                    id = currentNode.missing;
-                } else {
-                    Float value = featureValues[currentNode.splitFeatureId];
-
-                    if ((currentNode.compareType == NodeCompareType.LT && value < currentNode.splitCondition)
-                            || (currentNode.compareType == NodeCompareType.LE && value <= currentNode.splitCondition)) {
-                        id = currentNode.yes;
-                    } else {
-                        id = currentNode.no;
-                    }
-                }
-            } else {
-                LOGGER.error("Reach undefined condition: {}", id);
-            }
-        }
-    }
-
-    public Float score(final Map<String, Double> features, Map<String, Double> featuresScore) {
-        Float result = 0f;
-
-        boolean[] featureIsExists = new boolean[featureCount];
-        Float[] featureValues = new Float[featureCount];
-        for (Map.Entry<String, Double> entry : features.entrySet()) {
-            int featureId = getFeatureId(entry.getKey());
-            if (featureId >= 0) {
-                featureIsExists[featureId] = true;
-                featureValues[featureId] = entry.getValue().floatValue();
-            }
-        }
-
-        for (Map<Integer, Node> tree : boosterModel) {
-            result += score(tree, featureIsExists, featureValues);
-        }
-
-        Float transformedResult = transform(result);
-
-        LOGGER.debug("[calc_dwelltime]features: " + Arrays.toString(features.entrySet().toArray()) + ", prediction:" + result + " , transformed:" + transformedResult);
-
-        return transformedResult;
-    }
-
-    private enum NodeFieldType {
-        BINARY, QUANTITATIVE
-    }
-
-    private enum NodeCompareType {
-        LT, LE
-    }
-
-    private class Node {
-
-        boolean isLeaf;
-        float value;
-        NodeFieldType fieldType;
-        NodeCompareType compareType;
-        int splitFeatureId;
-        Float splitCondition;
-        Integer yes, no, missing;
-    }
-}

+ 0 - 111
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/LRV2Model.java

@@ -1,111 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score.model;
-
-
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.lang.math.NumberUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class LRV2Model extends Model {
-    protected static final int MODEL_FIRST_LOAD_COUNT = 1 << 25; // 32M
-    private static final Logger LOGGER = LoggerFactory.getLogger(LRV2Model.class);
-    private Map<String, Float> lrModel;
-
-    public void putFeature(Map<String, Float> model, String featureKey, float weight) {
-        model.put(featureKey, weight);
-    }
-
-    public float getWeight(Map<String, Float> model, String featureKey) {
-        return model.getOrDefault(featureKey, 0.0f);
-    }
-
-    @Override
-    public int getModelSize() {
-        if (this.lrModel == null)
-            return 0;
-        return lrModel.size();
-    }
-
-    public void cleanModel() {
-        this.lrModel = null;
-    }
-
-    public Float score(Map<String, String> featureMap) {
-        float sum = 0.0f;
-
-        if (MapUtils.isNotEmpty(featureMap)) {
-            for (Map.Entry<String, String> e : featureMap.entrySet()) {
-                float w = getWeight(this.lrModel, e.getKey());
-                sum += w * NumberUtils.toFloat(e.getValue(), 0.0f);
-            }
-
-            float biasW = lrModel.get("bias");
-            sum += biasW;
-        }
-
-
-        return (float) (1.0f / (1 + Math.exp(-sum)));
-    }
-
-    /**
-     * 目前模型比较大,分两个阶段load模型
-     * (1). load 8M 模型, 并更新;
-     * (2). load 剩余的模型
-     * 中间提供一段时间有损的打分服务
-     *
-     * @param in
-     * @return
-     * @throws IOException
-     */
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws IOException {
-
-        Map<String, Float> model = new HashMap<>();
-        BufferedReader input = new BufferedReader(in);
-        String line = null;
-        int cnt = 0;
-
-        Integer curTime = new Long(System.currentTimeMillis() / 1000).intValue();
-        //first stage
-        while ((line = input.readLine()) != null) {
-            String[] items = line.split("\t");
-            if (items.length < 2) {
-                continue;
-            }
-
-            putFeature(model, items[0], Float.valueOf(items[1].trim()).floatValue());
-            if (cnt++ < 10) {
-                LOGGER.debug("fea: " + items[0] + ", weight: " + items[1]);
-            }
-            if (cnt > MODEL_FIRST_LOAD_COUNT) {
-                break;
-            }
-        }
-        //model update
-        this.lrModel = model;
-
-        LOGGER.info("[MODELLOAD] after first stage model load, key size: {}, current time: {}", lrModel.size(), curTime);
-        //final stage
-        while ((line = input.readLine()) != null) {
-            String[] items = line.split("\t");
-            if (items.length < 2) {
-                continue;
-            }
-            putFeature(model, items[0], Float.valueOf(items[1]).floatValue());
-        }
-        LOGGER.info("[MODELLOAD] after model load, key size: {}, current time: {}", lrModel.size(), curTime);
-
-        LOGGER.info("[MODELLOAD] model load over and size " + cnt);
-        input.close();
-        in.close();
-        return true;
-    }
-
-}

+ 0 - 90
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/ThompsonSamplingModel.java

@@ -1,90 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score.model;
-
-import com.tzld.piaoquan.recommend.server.common.base.RankItem;
-import com.tzld.piaoquan.recommend.server.common.base.VideoActionFeature;
-import org.apache.commons.math3.distribution.BetaDistribution;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.math.BigInteger;
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class ThompsonSamplingModel extends Model {
-    protected static final int MODEL_FIRST_LOAD_COUNT = 1 << 25;  // 32M
-    private static final Logger LOGGER = LoggerFactory.getLogger(ThompsonSamplingModel.class);
-
-    // key = videoid, value = < push, exp, play, realplay, share, retures >
-    private Map<Long, VideoActionFeature> thompsonSamplingModel;
-
-    private static final int alpha = 20;
-    private static final int beta_returns = 100;
-
-    public ThompsonSamplingModel() {
-        //配置不同环境的hdfs conf
-        this.thompsonSamplingModel = new HashMap<>();
-    }
-
-    public Map<Long, VideoActionFeature> getThompsonSamplingModel() {
-        return this.thompsonSamplingModel;
-    }
-
-
-
-
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws IOException {
-        Map<Long, VideoActionFeature> initModel = new HashMap<>();
-        BufferedReader input = new BufferedReader(in);
-        String line = null;
-        int cnt = 0;
-        while ((line = input.readLine()) != null) {
-            String[] items = line.split("\t");
-            if (items.length < 3) {
-                continue;
-            }
-            Long videoId = new BigInteger(items[0].trim()).longValue();
-            VideoActionFeature videoFeature = new VideoActionFeature();
-            videoFeature.setView(Double.valueOf(items[1].trim()));
-            videoFeature.setPlay(Double.valueOf(items[2].trim()));
-            videoFeature.setShare(Double.valueOf(items[3].trim()));
-            videoFeature.setReturns(Double.valueOf(items[5].trim()));
-            initModel.put(videoId, videoFeature);
-        }
-
-        this.thompsonSamplingModel = initModel;
-        LOGGER.info("[MODELLOAD] model load over and size " + cnt);
-        input.close();
-        in.close();
-        return true;
-    }
-
-    @Override
-    public int getModelSize() {
-        if (this.thompsonSamplingModel == null)
-            return 0;
-        int sum = this.thompsonSamplingModel.size();
-        return sum;
-    }
-
-    public double score(RankItem rankItem) {
-        double score = 0.0f;
-        VideoActionFeature videoActionFeature = this.thompsonSamplingModel.getOrDefault(rankItem.getVideoId(), new VideoActionFeature());
-
-        int alpha = (int) videoActionFeature.getReturns() + ThompsonSamplingModel.alpha;
-        int beta = beta_returns + (int) videoActionFeature.getView();
-        score = this.betaSampler(alpha, beta);
-        return score;
-    }
-
-    public double betaSampler(double alpha, double beta) {
-        BetaDistribution betaSample = new BetaDistribution(alpha, beta);
-        return betaSample.sample();
-    }
-
-
-}

+ 0 - 46
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/VovH24WeightModel.java

@@ -1,46 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score.model;
-
-import com.google.common.reflect.TypeToken;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.Map;
-
-public class VovH24WeightModel extends Model {
-    private static final Logger LOGGER = LoggerFactory.getLogger(VovH24WeightModel.class);
-
-    // <小时, <Key, weight>>
-    private Map<String, Map<String, Double>> model = new HashMap<>();
-
-    @Override
-    public int getModelSize() {
-        return model.size();
-    }
-
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws Exception {
-        Map<String, Map<String, Double>> initModel = new HashMap<>();
-        try (BufferedReader reader = new BufferedReader(in)) {
-            StringBuilder buffer = new StringBuilder();
-            String line;
-            while ((line = reader.readLine()) != null) {
-                buffer.append(line).append("\n");
-            }
-            initModel = JSONUtils.fromJson(buffer.toString(), new TypeToken<Map<String, Map<String, Double>>>() {
-            }, initModel);
-            this.model = initModel;
-        } catch (Exception e) {
-            LOGGER.error("read vovh24 weight file error: ", e);
-            return false;
-        }
-        return true;
-    }
-
-    public Map<String, Double> getWeight(String key) {
-        return model.get(key);
-    }
-}

+ 0 - 52
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/Model4Recall2List.java

@@ -1,52 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.model4recall;
-
-import org.apache.commons.lang3.tuple.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class Model4Recall2List extends AbstractModel {
-    private static final Logger LOGGER = LoggerFactory.getLogger(Model4Recall2List.class);
-    public List<Pair<Long, Double>> recallList;
-
-    public Model4Recall2List() {
-        //配置不同环境的hdfs conf
-        this.recallList = new ArrayList<>();
-    }
-
-
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws IOException {
-        BufferedReader input = new BufferedReader(in);
-        String line = null;
-        while ((line = input.readLine()) != null) {
-            String[] items = line.split("\t");
-            if (items.length < 2) {
-                continue;
-            }
-            for (String item : items) {
-                String[] itemArr = item.split(",");
-                if (itemArr.length != 2) {
-                    continue;
-                }
-                String id = itemArr[0].trim();
-                String score = itemArr[1].trim();
-                try {
-                    Pair<Long, Double> pair = Pair.of(Long.valueOf(id), Double.valueOf(score));
-                    this.recallList.add(pair);
-                } catch (Exception e) {
-                    LOGGER.error(String.format("something is wrong with parse pair %s %s: ", id, score), e);
-                }
-            }
-        }
-        input.close();
-        in.close();
-        return true;
-    }
-}

+ 0 - 48
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/Model4RecallList.java

@@ -1,48 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.model4recall;
-
-import org.apache.commons.lang3.tuple.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-
-
-public class Model4RecallList extends AbstractModel {
-    private static final Logger LOGGER = LoggerFactory.getLogger(Model4RecallList.class);
-    public List<Pair<Long, Double>> recallList;
-    public Model4RecallList() {
-        //配置不同环境的hdfs conf
-        this.recallList = new ArrayList<>();
-    }
-
-
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws IOException {
-        BufferedReader input = new BufferedReader(in);
-        String line = null;
-        while ((line = input.readLine()) != null) {
-            String[] items = line.split("\t");
-            if (items.length < 2) {
-                continue;
-            }
-            String id = items[0].trim();
-            String score = items[1].trim();
-            try{
-                Pair<Long, Double> pair = Pair.of(Long.valueOf(id), Double.valueOf(score));
-                this.recallList.add(pair);
-            }catch (Exception e){
-                LOGGER.error(String.format("something is wrong with parse pair %s %s: ", id, score), e);
-            }
-        }
-        this.recallList.sort(Comparator.comparingDouble(o -> -o.getRight()));
-        input.close();
-        in.close();
-        return true;
-    }
-}

+ 0 - 56
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/Model4RecallVovLongTerm.java

@@ -1,56 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.model4recall;
-
-import org.apache.commons.lang3.tuple.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class Model4RecallVovLongTerm extends AbstractModel {
-    private static final Logger LOGGER = LoggerFactory.getLogger(Model4RecallVovLongTerm.class);
-    public Map<String, List<Pair<Long, Double>>> kv;
-    public Model4RecallVovLongTerm() {
-        //配置不同环境的hdfs conf
-        this.kv = new HashMap<>();
-    }
-
-
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws IOException {
-        BufferedReader input = new BufferedReader(in);
-        String line = null;
-        while ((line = input.readLine()) != null) {
-            String[] items = line.split("\t");
-            if (items.length < 3) {
-                continue;
-            }
-            String key = items[0].trim();
-            long l1 = 0L;
-            double l2 = 0D;
-            try{
-                l1 = Long.parseLong(items[1]);
-                l2 = Double.parseDouble(items[2]);
-            }catch (Exception e){
-                LOGGER.error(String.format("something is wrong with parse pair in Model4RecallVovLongTerm %s %s: ", items[1], items[2]), e);
-                continue;
-            }
-            List<Pair<Long, Double>> list = this.kv.getOrDefault(key, new ArrayList<>());
-            list.add(Pair.of(l1, l2));
-            this.kv.put(key, list);
-        }
-        input.close();
-        in.close();
-        kv.forEach((key, value) ->
-            value.sort((p1, p2) -> Double.compare(p2.getRight(), p1.getRight()))
-        );
-        return true;
-    }
-
-
-}

+ 0 - 44
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/model4recall/VideoTagModel4RecallMap.java

@@ -1,44 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.model4recall;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-public class VideoTagModel4RecallMap extends AbstractModel {
-    private static final Logger LOGGER = LoggerFactory.getLogger(VideoTagModel4RecallMap.class);
-    public Map<String, List<Long>> map = new HashMap<>();
-
-    @Override
-    public boolean loadFromStream(InputStreamReader in) throws IOException {
-        BufferedReader input = new BufferedReader(in);
-        String line;
-        while ((line = input.readLine()) != null) {
-            String[] items = line.split("\t");
-            if (items.length < 2) {
-                continue;
-            }
-            String videoIds = items[1].trim();
-            try {
-                String[] videoIdArr = videoIds.split(",");
-                List<Long> videoIdList = new ArrayList<>();
-                for (String videoId : videoIdArr) {
-                    videoIdList.add(Long.parseLong(videoId));
-                }
-                map.put(items[0], videoIdList);
-            } catch (Exception e) {
-                LOGGER.error(String.format("VideoTagModel4RecallMap is wrong with parse %s: ", line), e);
-            }
-        }
-        input.close();
-        in.close();
-        return true;
-    }
-}

+ 0 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/BlessRecallScore.java

@@ -56,9 +56,6 @@ public class BlessRecallScore extends AbstractScorer4Recall {
 //                    if (startTimeAndEndTime == null) {
 //                        continue;
 //                    }
-                    // 节日峰值设置为结束时间的当天的7点
-//                    double weight = DynamicGaussianFunction.calculateValue(LocalDateTime.now(), startTimeAndEndTime.getLeft(),
-//                            startTimeAndEndTime.getRight(), startTimeAndEndTime.getRight().withHour(7));
                     List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(festival, new ArrayList<>());
                     if (festivalLists.isEmpty()) {
                         continue;

+ 0 - 59
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/ContentBaseRecallScore.java

@@ -1,59 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-
-public class ContentBaseRecallScore extends AbstractScorer4Recall {
-
-    public ContentBaseRecallScore(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallKeyValue.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params) {
-        Model4RecallKeyValue model = (Model4RecallKeyValue) this.getModel();
-        if (model == null || MapUtils.isEmpty(model.kv)) {
-            return Collections.emptyList();
-        }
-        String tags = params.get("tags");
-        if (StringUtils.isBlank(tags)) {
-            return Collections.emptyList();
-        }
-        List<String> tagList = Arrays.stream(tags.split(",")).collect(Collectors.toList());
-        List<Pair<Long, Double>> result = new ArrayList<>();
-        for (String tag : tagList) {
-            List<Pair<Long, Double>> videoAndScores = model.kv.get(tag);
-            if (CollectionUtils.isNotEmpty(videoAndScores)) {
-                result.addAll(videoAndScores);
-            }
-        }
-        // 结果去重
-        Set<Long> videoIdSet = new HashSet<>();
-        List<Pair<Long, Double>> distinctResult = new ArrayList<>();
-        for (Pair<Long, Double> pair : result) {
-            if (pair.getLeft() == null || pair.getRight() == null) {
-                continue;
-            }
-            if (videoIdSet.add(pair.getLeft())) {
-                distinctResult.add(pair);
-            }
-        }
-        return distinctResult;
-    }
-
-
-}

+ 0 - 43
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/DynamicGaussianFunction.java

@@ -1,43 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-
-/**
- * 动态高斯函数
- *
- * @author sunxy
- */
-public class DynamicGaussianFunction {
-    private static final double SIGMA = 24.0; // 标准差,可以根据需要调整这个值
-
-    public static double calculateValue(LocalDateTime testTime, LocalDateTime startTime, LocalDateTime endTime,
-                                        LocalDateTime peakTime) {
-        long testTimestamp = testTime.toEpochSecond(ZoneOffset.UTC) * 1000;
-        // 检查时间是否在指定范围内
-        if (testTimestamp < startTime.toEpochSecond(ZoneOffset.UTC) * 1000 ||
-                testTimestamp > endTime.toEpochSecond(ZoneOffset.UTC) * 1000) {
-            return 0;
-        }
-
-        // 计算 t_0,即从开始时间到峰值时间的小时数
-        double t_0 = (peakTime.toEpochSecond(ZoneOffset.UTC) - startTime.toEpochSecond(ZoneOffset.UTC)) / 3600.0;
-
-        // 计算时间差(以小时为单位)
-        double t = (testTimestamp / 1000.0 - startTime.toEpochSecond(ZoneOffset.UTC)) / 3600.0;
-
-        // 计算高斯函数值
-        return 100 * Math.exp(-Math.pow(t - t_0, 2) / (2 * Math.pow(SIGMA, 2)));
-    }
-
-    public static void main(String[] args) {
-        // 示例:计算2024-02-03 09:00的值
-        LocalDateTime startTime = LocalDateTime.of(2024, 1, 29, 0, 0);
-        LocalDateTime endTime = LocalDateTime.of(2024, 2, 3, 23, 59);
-        LocalDateTime peakTime = LocalDateTime.of(2024, 2, 3, 9, 0);
-        LocalDateTime testTime = LocalDateTime.of(2024, 1, 31, 22, 0);
-
-        double value = calculateValue(testTime, startTime, endTime, peakTime);
-        System.out.println("Function value at " + testTime + ": " + value);
-    }
-}

+ 0 - 175
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/FestivalRecallScore.java

@@ -1,175 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
-import com.tzld.piaoquan.recommend.server.util.ListMerger;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.*;
-
-
-public class FestivalRecallScore extends AbstractScorer4Recall {
-
-    public FestivalRecallScore(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallKeyValue.class);
-    }
-    final Set<String> NORTHERN_PROVINCES = new HashSet<>(Arrays.asList(
-            "北京" ,"天津" ,"河北" ,"山西","内蒙古"
-            ,"辽宁","吉林","黑龙江","山东","河南","陕西","甘肃","宁夏","新疆"
-    ));
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params) {
-        // 1 获取省份,判断南北 小年
-//        String key = params.getOrDefault("region_province", "中国");
-//        boolean ifNorth = NORTHERN_PROVINCES.contains(key);
-
-        // 节假日、时效性,判断
-        Model4RecallKeyValue model = (Model4RecallKeyValue) this.getModel();
-        if (model == null || model.kv == null) {
-            return new ArrayList<>();
-        }
-        LocalDateTime now = LocalDateTime.now();
-        // 节日祝福-每年
-
-        String yearlyFestivalTimeRange = params.get("yearly_festival_time_range");
-        if (StringUtils.isBlank(yearlyFestivalTimeRange)) {
-            return new ArrayList<>();
-        }
-        JSONObject jsonObject = JSONObject.parseObject(yearlyFestivalTimeRange);
-        List<List<Pair<Long, Double>>> yearResultList = new ArrayList<>();
-        for (String festival : jsonObject.keySet()) {
-            try {
-//                if (festival.contains("小年")) {
-//                    if ("北小年".contains(festival) && !ifNorth) {
-//                        continue;
-//                    } else if ("南小年".contains(festival) && ifNorth) {
-//                        continue;
-//                    }
-//                    festival = "小年";
-//                }
-                JSONArray jsonArray = jsonObject.getJSONArray(festival);
-                if (jsonArray == null) {
-                    continue;
-                }
-                List<String> timeRangeList = jsonArray.toJavaList(String.class);
-                if (isFestivalTime(now, timeRangeList)) {
-                    Pair<LocalDateTime, LocalDateTime> startTimeAndEndTime = getStartTimeAndEndTime(timeRangeList.get(0));
-                    if (startTimeAndEndTime == null) {
-                        continue;
-                    }
-                    // 节日峰值设置为结束时间的当天的7点
-//                    double weight = DynamicGaussianFunction.calculateValue(LocalDateTime.now(), startTimeAndEndTime.getLeft(),
-//                            startTimeAndEndTime.getRight(), startTimeAndEndTime.getRight().withHour(7));
-                    List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(festival, new ArrayList<>());
-                    if (festivalLists.isEmpty()) {
-                        continue;
-                    }
-                    yearResultList.add(festivalLists);
-                }
-            } catch (Exception e) {
-//                e.printStackTrace();
-            }
-        }
-        return ListMerger.mergeLists(yearResultList);
-    }
-
-    public Pair<LocalDateTime, LocalDateTime> getStartTimeAndEndTime(String timeRangeList) {
-        if (timeRangeList == null || timeRangeList.isEmpty()) {
-            return null;
-        }
-        // 时间格式 2024-12-20 00:00~2024-12-25 08:00
-        if (StringUtils.startsWith(timeRangeList, "daily")) {
-            // 判断是否是 daily 开头
-            return null;
-        } else {
-            String[] split = StringUtils.split(timeRangeList, "~");
-            if (split.length != 2) {
-                return null;
-            }
-            String startTime = split[0];
-            String endTime = split[1];
-            // 解析 startTime endTime
-            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
-            LocalDateTime startLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
-            LocalDateTime endLocalDateTime = LocalDateTime.parse(endTime, dateTimeFormatter);
-            return Pair.of(startLocalDateTime, endLocalDateTime);
-        }
-    }
-
-    public boolean isFestivalTime(LocalDateTime now, List<String> timeRangeList) {
-        if (timeRangeList == null || timeRangeList.isEmpty()) {
-            return false;
-        }
-        for (String timeRange : timeRangeList) {
-            // 判断是否是 daily 开头
-            if (StringUtils.startsWith(timeRange, "daily")) {
-                // 判断是否是 daily 开头
-                String dailyTimeRange = StringUtils.substring(timeRange, 6);
-                String[] split = StringUtils.split(dailyTimeRange, "-");
-                if (split.length != 2) {
-                    continue;
-                }
-                String startTime = split[0];
-                String endTime = split[1];
-                // 获取当前时间的小时和分钟
-                int hour = now.getHour();
-                int minute = now.getMinute();
-                // startTime: 21:00 endTime: 23:00
-                String[] startSplit = StringUtils.split(startTime, ":");
-                String[] endSplit = StringUtils.split(endTime, ":");
-                if (startSplit.length != 2 || endSplit.length != 2) {
-                    continue;
-                }
-                int startHour = Integer.parseInt(startSplit[0]);
-                int startMinute = Integer.parseInt(startSplit[1]);
-                int endHour = Integer.parseInt(endSplit[0]);
-                int endMinute = Integer.parseInt(endSplit[1]);
-                if (hour > startHour && hour < endHour) {
-                    return true;
-                } else if (hour == startHour && hour == endHour) {
-                    if (minute >= startMinute && minute <= endMinute) {
-                        return true;
-                    }
-                } else if (hour == startHour) {
-                    if (minute >= startMinute) {
-                        return true;
-                    }
-                } else if (hour == endHour) {
-                    if (minute <= endMinute) {
-                        return true;
-                    }
-                }
-                continue;
-            }
-            // 时间格式 2024-12-20 00:00~2024-12-25 08:00
-            String[] split = StringUtils.split(timeRange, "~");
-            if (split.length != 2) {
-                continue;
-            }
-            String startTime = split[0];
-            String endTime = split[1];
-            // 解析 startTime endTime
-            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
-            LocalDateTime startLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
-            LocalDateTime endLocalDateTime = LocalDateTime.parse(endTime, dateTimeFormatter);
-            if (now.isAfter(startLocalDateTime) && now.isBefore(endLocalDateTime)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-
-}

+ 0 - 36
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV2.java

@@ -1,36 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallList;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-
-public class RegionRecallScorerV2 extends AbstractScorer4Recall {
-
-    public RegionRecallScorerV2(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallList.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params){
-        // todo zhangbo 这里要写实现功能
-        Model4RecallList model = (Model4RecallList) this.getModel();
-        List<Pair<Long, Double>> lists = model.recallList;
-        String sort = params.getOrDefault("sort", "");
-        if ("1".equals(sort)){
-            lists.sort(Comparator.comparingDouble(o -> -o.getRight()));
-        }
-        return lists.subList(0, Math.min(160, lists.size()));
-    }
-
-
-}

+ 0 - 41
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV3.java

@@ -1,41 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-
-public class RegionRecallScorerV3 extends AbstractScorer4Recall {
-
-    public RegionRecallScorerV3(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallKeyValue.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params){
-        // todo zhangbo 这里要写实现功能
-        Model4RecallKeyValue model = (Model4RecallKeyValue) this.getModel();
-        String key = params.getOrDefault("region_province", "中国");
-        List<Pair<Long, Double>> lists = model.kv.getOrDefault(key, new ArrayList<>());
-        if (lists.isEmpty()){
-            lists = model.kv.getOrDefault("中国", new ArrayList<>());
-        }
-        String sort = params.getOrDefault("sort", "");
-        if ("1".equals(sort)){
-            lists.sort(Comparator.comparingDouble(o -> -o.getRight()));
-        }
-        return lists.subList(0, Math.min(160, lists.size()));
-    }
-
-
-}

+ 0 - 33
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV4.java

@@ -1,33 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallList;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-
-public class RegionRecallScorerV4 extends AbstractScorer4Recall {
-
-    public RegionRecallScorerV4(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallList.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params){
-        // todo zhangbo 这里要写实现功能
-        Model4RecallList model = (Model4RecallList) this.getModel();
-        List<Pair<Long, Double>> lists = model.recallList;
-        lists.sort(Comparator.comparingDouble(o -> -o.getRight()));
-        return lists.subList(0, Math.min(400, lists.size()));
-    }
-
-
-}

+ 0 - 34
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV5HighValue.java

@@ -1,34 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallList;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-
-public class RegionRecallScorerV5HighValue extends AbstractScorer4Recall {
-
-    public RegionRecallScorerV5HighValue(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallList.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params){
-        // todo zhangbo 这里要写实现功能
-        Model4RecallList model = (Model4RecallList) this.getModel();
-        List<Pair<Long, Double>> lists = model.recallList;
-        lists.sort(Comparator.comparingDouble(o -> -o.getRight()));
-        return lists.subList(0, Math.min(100, lists.size()));
-    }
-
-
-}

+ 0 - 38
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV5RootRov.java

@@ -1,38 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-
-public class RegionRecallScorerV5RootRov extends AbstractScorer4Recall {
-
-    public RegionRecallScorerV5RootRov(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallKeyValue.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params){
-        // todo zhangbo 这里要写实现功能
-        Model4RecallKeyValue model = (Model4RecallKeyValue) this.getModel();
-        String key = params.getOrDefault("region_province", "中国");
-        List<Pair<Long, Double>> lists = model.kv.getOrDefault(key, new ArrayList<>());
-        if (lists.isEmpty()){
-            lists = model.kv.getOrDefault("中国", new ArrayList<>());
-        }
-        lists.sort(Comparator.comparingDouble(o -> -o.getRight()));
-        return lists.subList(0, Math.min(200, lists.size()));
-    }
-
-
-}

+ 0 - 70
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/RegionRecallScorerV7VovLongTerm.java

@@ -1,70 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallVovLongTerm;
-import org.apache.commons.lang3.tuple.Pair;
-import java.util.*;
-
-public class RegionRecallScorerV7VovLongTerm extends AbstractScorer4Recall {
-
-    public RegionRecallScorerV7VovLongTerm(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4RecallVovLongTerm.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params){
-        Model4RecallVovLongTerm model = (Model4RecallVovLongTerm) this.getModel();
-        Map<String, List<Pair<Long, Double>>> kv = model.kv;
-        List<Pair<Long, Double>> result = new ArrayList<>();
-        for (Map.Entry<String, String> entry : params.entrySet()) {
-            String key = entry.getKey();
-            int count = Integer.parseInt(entry.getValue());
-            if (kv.containsKey(key)) {
-                List<Pair<Long, Double>> copy = new ArrayList<>(kv.get(key));
-                // 先随机,再截断。
-                List<Pair<Long, Double>> selected = getWeightedRandomElements(copy, count);
-                result.addAll(selected);
-            }
-        }
-        return result;
-    }
-
-    public static List<Pair<Long, Double>> getWeightedRandomElements(List<Pair<Long, Double>> list, int count) {
-        if (list == null || list.isEmpty()) {
-            return new ArrayList<>(0);
-        }
-        if (count >= list.size()) {
-            return new ArrayList<>(list);
-        }
-
-        // 计算权重总和
-        double totalWeight = list.stream().mapToDouble(Pair::getRight).sum();
-
-        // 使用加权随机选择
-        List<Pair<Long, Double>> result = new ArrayList<>();
-        Random random = new Random();
-
-        for (int i = 0; i < count; i++) {
-            double rand = random.nextDouble() * totalWeight; // 生成一个0到totalWeight之间的随机数
-            double cumulativeWeight = 0.0;
-
-            for (Pair<Long, Double> pair : list) {
-                cumulativeWeight += pair.getRight(); // 累加权重
-                if (rand <= cumulativeWeight) {
-                    result.add(pair); // 选择当前元素
-                    totalWeight -= pair.getRight(); // 更新总权重
-                    list.remove(pair); // 防止重复选择
-                    break;
-                }
-            }
-        }
-
-        return result;
-    }
-
-}

+ 0 - 39
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/ShareDeepRecallScore.java

@@ -1,39 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4Recall2List;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-
-public class ShareDeepRecallScore extends AbstractScorer4Recall {
-
-    public ShareDeepRecallScore(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4Recall2List.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params) {
-        if (params == null || params.isEmpty()) {
-            return new ArrayList<>();
-        }
-        Model4Recall2List model = (Model4Recall2List) this.getModel();
-        if (model == null || model.recallList == null) {
-            return new ArrayList<>();
-        }
-        int limit = Integer.parseInt(params.getOrDefault("limit", "500"));
-        return model.recallList.stream().limit(limit).collect(Collectors.toList());
-    }
-
-
-}

+ 0 - 39
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score4recall/strategy/ShareWidthRecallScore.java

@@ -1,39 +0,0 @@
-package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
-
-import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
-import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4Recall2List;
-import org.apache.commons.lang3.tuple.Pair;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-
-public class ShareWidthRecallScore extends AbstractScorer4Recall {
-
-    public ShareWidthRecallScore(ScorerConfigInfo configInfo) {
-        super(configInfo);
-    }
-
-    @Override
-    public void loadModel() {
-        doLoadModel(Model4Recall2List.class);
-    }
-
-    @Override
-    public List<Pair<Long, Double>> recall(Map<String, String> params) {
-        if (params == null || params.isEmpty()) {
-            return new ArrayList<>();
-        }
-        Model4Recall2List model = (Model4Recall2List) this.getModel();
-        if (model == null || model.recallList == null) {
-            return new ArrayList<>();
-        }
-        int limit = Integer.parseInt(params.getOrDefault("limit", "500"));
-        return model.recallList.stream().limit(limit).collect(Collectors.toList());
-    }
-
-
-}