|
@@ -10,13 +10,15 @@ import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
|
|
|
import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
|
|
|
import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
|
|
|
import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
|
+import com.tzld.piaoquan.recommend.server.util.DateUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.math3.util.Pair;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.Future;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -28,12 +30,17 @@ public class RankStrategy4RegionMergeModelV536 extends RankStrategy4RegionMergeM
|
|
|
@ApolloJsonValue("${rank.score.merge.weightv536:}")
|
|
|
private Map<String, Double> mergeWeight;
|
|
|
|
|
|
+ @ApolloJsonValue("${rank.score.reduce.config.v536:}")
|
|
|
+ private Map<String, List<Map<String, String>>> reduceConfigMap;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FeatureService featureService;
|
|
|
|
|
|
@Override
|
|
|
public List<Video> mergeAndRankRovRecall(RankParam param) {
|
|
|
Map<String, Double> mergeWeight = this.mergeWeight != null ? this.mergeWeight : new HashMap<>(0);
|
|
|
+ Map<String, List<Map<String, String>>> reduceConfigMap = this.reduceConfigMap != null ? this.reduceConfigMap : new HashMap<>(0);
|
|
|
+
|
|
|
//-------------------融-------------------
|
|
|
//-------------------合-------------------
|
|
|
//-------------------逻-------------------
|
|
@@ -66,6 +73,18 @@ public class RankStrategy4RegionMergeModelV536 extends RankStrategy4RegionMergeM
|
|
|
v1 = v1.subList(0, Math.min(mergeWeight.getOrDefault("v1", 5.0).intValue(), v1.size()));
|
|
|
rovRecallRank.addAll(v1);
|
|
|
setVideo.addAll(v1.stream().map(Video::getVideoId).collect(Collectors.toSet()));
|
|
|
+ //-------------------scene cf rovn------------------
|
|
|
+ List<Video> sceneCFRovn = extractAndSort(param, SceneCFRovnRecallStrategy.PUSH_FORM);
|
|
|
+ sceneCFRovn = sceneCFRovn.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
|
|
|
+ sceneCFRovn = sceneCFRovn.subList(0, Math.min(mergeWeight.getOrDefault("sceneCFRovn", 5.0).intValue(), sceneCFRovn.size()));
|
|
|
+ rovRecallRank.addAll(sceneCFRovn);
|
|
|
+ setVideo.addAll(sceneCFRovn.stream().map(Video::getVideoId).collect(Collectors.toSet()));
|
|
|
+ //-------------------scene cf rosn------------------
|
|
|
+ List<Video> sceneCFRosn = extractAndSort(param, SceneCFRosnRecallStrategy.PUSH_FORM);
|
|
|
+ sceneCFRosn = sceneCFRosn.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
|
|
|
+ sceneCFRosn = sceneCFRosn.subList(0, Math.min(mergeWeight.getOrDefault("sceneCFRosn", 5.0).intValue(), sceneCFRosn.size()));
|
|
|
+ rovRecallRank.addAll(sceneCFRosn);
|
|
|
+ setVideo.addAll(sceneCFRosn.stream().map(Video::getVideoId).collect(Collectors.toSet()));
|
|
|
|
|
|
//-------------------排-------------------
|
|
|
//-------------------序-------------------
|
|
@@ -313,16 +332,25 @@ public class RankStrategy4RegionMergeModelV536 extends RankStrategy4RegionMergeM
|
|
|
item.getScoresMap().put("fmRovOrigin", fmRovOrigin);
|
|
|
double fmRov = restoreScore(fmRovOrigin);
|
|
|
item.getScoresMap().put("fmRov", fmRov);
|
|
|
+
|
|
|
double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("rov", "0"));
|
|
|
item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
|
|
|
+
|
|
|
double vor = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>()).getOrDefault("vor", "0"));
|
|
|
item.getScoresMap().put("vor", vor);
|
|
|
- score = fmRov * (0.1 + hasReturnRovScore) * (0.1 + vor);
|
|
|
+
|
|
|
+ String vidStr = String.valueOf(item.getVideo().getVideoId());
|
|
|
+ String mergeCate2 = this.parseMergeCate2(vidStr, featureOriginVideo);
|
|
|
+ double reduceCoefficient = this.parseReduceCoefficient(mergeCate2, reduceConfigMap);
|
|
|
+ item.getScoresMap().put("reduceCoefficient", reduceCoefficient);
|
|
|
+
|
|
|
+ score = fmRov * (0.1 + hasReturnRovScore) * (0.1 + vor) * reduceCoefficient;
|
|
|
Video video = item.getVideo();
|
|
|
video.setScore(score);
|
|
|
video.setSortScore(score);
|
|
|
video.setScoresMap(item.getScoresMap());
|
|
|
video.setAllFeatureMap(item.getAllFeatureMap());
|
|
|
+ video.getMergeCateList().add(mergeCate2);
|
|
|
if (MapUtils.isNotEmpty(feature.getVideoFeature()) && MapUtils.isNotEmpty(feature.getVideoFeature().get(item.getVideoId() + ""))) {
|
|
|
video.getMetaFeatureMap().putAll(feature.getVideoFeature().get(item.getVideoId() + ""));
|
|
|
}
|
|
@@ -334,4 +362,82 @@ public class RankStrategy4RegionMergeModelV536 extends RankStrategy4RegionMergeM
|
|
|
result.sort(Comparator.comparingDouble(o -> -o.getSortScore()));
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public double parseReduceCoefficient(String mergeCate2, Map<String, List<Map<String, String>>> reduceConfigMap) {
|
|
|
+ if (StringUtils.isBlank(mergeCate2) || MapUtils.isEmpty(reduceConfigMap)) {
|
|
|
+ return 1d;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, String>> configMaps = reduceConfigMap.getOrDefault(mergeCate2, new ArrayList<>());
|
|
|
+ for (Map<String, String> configMap : configMaps) {
|
|
|
+ boolean currentHourIsNeedReduce = currentHourIsNeedReduce(configMap);
|
|
|
+ boolean currentDateIsNeedReduce = currentDateIsNeedReduce(configMap);
|
|
|
+ if (currentHourIsNeedReduce || currentDateIsNeedReduce) {
|
|
|
+ return Double.parseDouble(configMap.getOrDefault("reduce_coefficient", "1"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1d;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前小时是否需要降权
|
|
|
+ */
|
|
|
+ private boolean currentHourIsNeedReduce(Map<String, String> configMap) {
|
|
|
+ if (!configMap.containsKey("reduce_hour")) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+
|
|
|
+ int currentHour = LocalDateTime.now().getHour();
|
|
|
+ String[] reduceHours = configMap.get("reduce_hour").split(",");
|
|
|
+ for (String hourRange : reduceHours) {
|
|
|
+ String[] split = hourRange.split("-");
|
|
|
+ int h1 = Integer.parseInt(split[0]);
|
|
|
+ int h2 = (split.length == 2) ? Integer.parseInt(split[1]) : h1;
|
|
|
+
|
|
|
+ if (currentHour >= h1 && currentHour <= h2) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("536 error parse reduce hour config error. config content: {}, \n", configMap, e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前时间段是否需要降权
|
|
|
+ */
|
|
|
+ private boolean currentDateIsNeedReduce(Map<String, String> configMap) {
|
|
|
+ if (!configMap.containsKey("reduce_date")) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] reduceDates = configMap.get("reduce_date").split(",");
|
|
|
+ for (String s : reduceDates) {
|
|
|
+ if (DateUtils.ifTimeRangeInNow(s)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String parseMergeCate2(String vidStr, Map<String, Map<String, Map<String, String>>> featureMap) {
|
|
|
+ if (!featureMap.containsKey(vidStr)) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Map<String, String>> vidFeature = featureMap.get(vidStr);
|
|
|
+ if (!vidFeature.containsKey("alg_vid_feature_basic_info")) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> basicInfoMap = vidFeature.get("alg_vid_feature_basic_info");
|
|
|
+ return basicInfoMap.getOrDefault("merge_second_level_cate", "");
|
|
|
+ }
|
|
|
}
|