|
@@ -3,14 +3,15 @@ package com.tzld.piaoquan.recommend.server.service;
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
import com.google.common.base.Stopwatch;
|
|
import com.google.common.base.Stopwatch;
|
|
import com.google.common.base.Strings;
|
|
import com.google.common.base.Strings;
|
|
-import com.google.common.reflect.TypeToken;
|
|
|
|
-import com.tzld.piaoquan.recommend.server.common.base.Constant;
|
|
|
|
|
|
+import com.google.common.cache.CacheBuilder;
|
|
|
|
+import com.google.common.cache.CacheLoader;
|
|
|
|
+import com.google.common.cache.LoadingCache;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.common.RedisKeyConstants;
|
|
import com.tzld.piaoquan.recommend.server.gen.common.Result;
|
|
import com.tzld.piaoquan.recommend.server.gen.common.Result;
|
|
import com.tzld.piaoquan.recommend.server.gen.recommend.*;
|
|
import com.tzld.piaoquan.recommend.server.gen.recommend.*;
|
|
import com.tzld.piaoquan.recommend.server.model.MachineInfo;
|
|
import com.tzld.piaoquan.recommend.server.model.MachineInfo;
|
|
import com.tzld.piaoquan.recommend.server.model.RecommendParam;
|
|
import com.tzld.piaoquan.recommend.server.model.RecommendParam;
|
|
import com.tzld.piaoquan.recommend.server.model.Video;
|
|
import com.tzld.piaoquan.recommend.server.model.Video;
|
|
-import com.tzld.piaoquan.recommend.server.remote.ABTestRemoteService;
|
|
|
|
import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConfigService;
|
|
import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConfigService;
|
|
import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
|
|
import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
|
|
import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolService;
|
|
import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolService;
|
|
@@ -23,7 +24,6 @@ import com.tzld.piaoquan.recommend.server.service.recall.RecallService;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
|
|
import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
-import com.tzld.piaoquan.recommend.server.util.ParserUtils;
|
|
|
|
import com.tzld.piaoquan.recommend.server.util.TraceUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.TraceUtils;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -53,31 +53,8 @@ public class RecommendService {
|
|
@Qualifier("redisTemplate")
|
|
@Qualifier("redisTemplate")
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
-
|
|
|
|
- private final Map<Integer, String> ab_initial_config_map = new HashMap<>();
|
|
|
|
-
|
|
|
|
- @ApolloJsonValue("${ab_exp_code:{}}")
|
|
|
|
- private Map<String, Map<String, String>> abExpCodeMap;
|
|
|
|
-
|
|
|
|
- @ApolloJsonValue("${app_ab_code:{}}")
|
|
|
|
- private Map<String, Map<String, Map<String, String>>> appAbCodeMap;
|
|
|
|
-
|
|
|
|
- @ApolloJsonValue("${flow.pool.ids:[7, 8, 9, 10, 11, 12, 13, 14, 15, 16]}")
|
|
|
|
- private List<Integer> flowPoolIds;
|
|
|
|
@ApolloJsonValue("${city_code:[]}")
|
|
@ApolloJsonValue("${city_code:[]}")
|
|
private Set<String> cityCodes;
|
|
private Set<String> cityCodes;
|
|
-
|
|
|
|
- @ApolloJsonValue("${new.exp.list:[6]}")
|
|
|
|
- private Set<Integer> newExpList;
|
|
|
|
-
|
|
|
|
- @ApolloJsonValue("${new.exp,config.v2:[]}")
|
|
|
|
- private List<ExpConfig> expConfigs;
|
|
|
|
-
|
|
|
|
- @Value("${new.exp.abtest.service.switch:true}")
|
|
|
|
- private boolean newExpABTestServiceSwitch;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private FlowPoolConfigService flowPoolConfigService;
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RecallService recallService;
|
|
private RecallService recallService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -91,13 +68,34 @@ public class RecommendService {
|
|
@Autowired
|
|
@Autowired
|
|
private TimerLogService timerLogService;
|
|
private TimerLogService timerLogService;
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private ABTestRemoteService abTestRemoteService;
|
|
|
|
-
|
|
|
|
private ThreadLocal<Map<String, Object>> timerLogMapTL = ThreadLocal.withInitial(HashMap::new);
|
|
private ThreadLocal<Map<String, Object>> timerLogMapTL = ThreadLocal.withInitial(HashMap::new);
|
|
|
|
|
|
|
|
+ @Value("${risk.video.filter.switch:true}")
|
|
|
|
+ private boolean riskVideoFilterSwitch;
|
|
|
|
+ @ApolloJsonValue("${risk.scene:[]}")
|
|
|
|
+ private Set<Long> riskScenes;
|
|
|
|
+
|
|
|
|
+ private LoadingCache<String, Set<String>> riskUserCache = CacheBuilder.newBuilder()
|
|
|
|
+ .maximumSize(5)
|
|
|
|
+ .refreshAfterWrite(300, TimeUnit.SECONDS)
|
|
|
|
+ .expireAfterWrite(300, TimeUnit.SECONDS)
|
|
|
|
+ .expireAfterAccess(300, TimeUnit.SECONDS)
|
|
|
|
+ .build(new CacheLoader<String, Set<String>>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Set<String> load(String key) {
|
|
|
|
+ Set<String> result = redisTemplate.opsForSet().members(key);
|
|
|
|
+ if (CollectionUtils.isEmpty(result)) {
|
|
|
|
+ return Collections.emptySet();
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
@PostConstruct
|
|
@PostConstruct
|
|
public void init() {
|
|
public void init() {
|
|
|
|
+ Set<String> data1 = riskUserCache.getUnchecked(RedisKeyConstants.Recommend.riskUserUid);
|
|
|
|
+ Set<String> data2 = riskUserCache.getUnchecked(RedisKeyConstants.Recommend.riskUserMid);
|
|
|
|
+ log.info("riskUserCache uid size {} mid size {}", data1.size(), data2.size());
|
|
}
|
|
}
|
|
|
|
|
|
public RecommendResponse homepageRecommend(RecommendRequest request) {
|
|
public RecommendResponse homepageRecommend(RecommendRequest request) {
|
|
@@ -158,7 +156,6 @@ public class RecommendService {
|
|
vps.add(VideoProto.newBuilder()
|
|
vps.add(VideoProto.newBuilder()
|
|
.setPosition(i + 1)
|
|
.setPosition(i + 1)
|
|
.setPushFrom(Strings.nullToEmpty(videos.get(i).getPushFrom()))
|
|
.setPushFrom(Strings.nullToEmpty(videos.get(i).getPushFrom()))
|
|
- .setAbCode(Strings.nullToEmpty(videos.get(i).getAbCode()))
|
|
|
|
.setVideoId(videos.get(i).getVideoId())
|
|
.setVideoId(videos.get(i).getVideoId())
|
|
.setRovScore(videos.get(i).getRovScore())
|
|
.setRovScore(videos.get(i).getRovScore())
|
|
.setSortScore(videos.get(i).getSortScore())
|
|
.setSortScore(videos.get(i).getSortScore())
|
|
@@ -213,7 +210,6 @@ public class RecommendService {
|
|
|
|
|
|
map.put("flowPool", String.valueOf(v.getFlowPool()));
|
|
map.put("flowPool", String.valueOf(v.getFlowPool()));
|
|
map.put("level", String.valueOf(v.getLevel()));
|
|
map.put("level", String.valueOf(v.getLevel()));
|
|
- map.put("flowPoolAbtestGroup", String.valueOf(v.getFlowPoolAbtestGroup()));
|
|
|
|
map.put("inFlowPool", String.valueOf(v.isInFlowPool()));
|
|
map.put("inFlowPool", String.valueOf(v.isInFlowPool()));
|
|
|
|
|
|
map.put("scoreRos", String.valueOf(v.getScoreRos()));
|
|
map.put("scoreRos", String.valueOf(v.getScoreRos()));
|
|
@@ -283,7 +279,6 @@ public class RecommendService {
|
|
.setResult(Result.newBuilder().setCode(1).setMessage("success"))
|
|
.setResult(Result.newBuilder().setCode(1).setMessage("success"))
|
|
.addAllVideo(CommonCollectionUtils.toList(videos, v -> VideoProto.newBuilder()
|
|
.addAllVideo(CommonCollectionUtils.toList(videos, v -> VideoProto.newBuilder()
|
|
.setPushFrom(Strings.nullToEmpty(v.getPushFrom()))
|
|
.setPushFrom(Strings.nullToEmpty(v.getPushFrom()))
|
|
- .setAbCode(Strings.nullToEmpty(v.getAbCode()))
|
|
|
|
.setVideoId(v.getVideoId())
|
|
.setVideoId(v.getVideoId())
|
|
.setRovScore(v.getRovScore())
|
|
.setRovScore(v.getRovScore())
|
|
.build()))
|
|
.build()))
|
|
@@ -305,11 +300,8 @@ public class RecommendService {
|
|
param.setCity(request.getCity());
|
|
param.setCity(request.getCity());
|
|
|
|
|
|
|
|
|
|
- String abInitialConfig = ab_initial_config_map.getOrDefault(request.getAppType(), "095-1");
|
|
|
|
- Map<String, String> abExpCode = abExpCodeMap.getOrDefault(abInitialConfig, Collections.emptyMap());
|
|
|
|
- param.setAbCode(abExpCode.get("ab_code"));
|
|
|
|
- param.setRuleKey(abExpCode.get("rule_key"));
|
|
|
|
- param.setDataKey(abExpCode.get("data_key"));
|
|
|
|
|
|
+ param.setRuleKey("rule66");
|
|
|
|
+ param.setDataKey("data66");
|
|
param.setRankKeyPrefix("rank:score1:");
|
|
param.setRankKeyPrefix("rank:score1:");
|
|
|
|
|
|
// 实验配置
|
|
// 实验配置
|
|
@@ -330,111 +322,16 @@ public class RecommendService {
|
|
} else if (abExpCodes.contains("339")) {
|
|
} else if (abExpCodes.contains("339")) {
|
|
param.setFlowPoolP(0);
|
|
param.setFlowPoolP(0);
|
|
}
|
|
}
|
|
-
|
|
|
|
- for (Map.Entry<String, Map<String, String>> entry : abExpCodeMap.entrySet()) {
|
|
|
|
- if (abExpCodes.contains(entry.getKey())) {
|
|
|
|
- param.setAbCode(entry.getValue().get("ab_code"));
|
|
|
|
- param.setRuleKey(entry.getValue().get("rule_key"));
|
|
|
|
- param.setDataKey(entry.getValue().get("data_key"));
|
|
|
|
-
|
|
|
|
- param.setHDataKey(entry.getValue().get("h_data_key"));
|
|
|
|
- param.setHRuleKey(entry.getValue().get("h_rule_key"));
|
|
|
|
-
|
|
|
|
- param.setRankKeyPrefix(StringUtils.isNotBlank(entry.getValue().get("rank_key_prefix"))
|
|
|
|
- ? entry.getValue().get("rank_key_prefix")
|
|
|
|
- : "rank:score1:");
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // app实验组
|
|
|
|
- if (request.getEventIdCount() > 0) {
|
|
|
|
- if (recommendType == 0) {
|
|
|
|
- String eventId = request.getEventIdMap().get("10003");
|
|
|
|
- Map<String, Map<String, String>> appAbCode = appAbCodeMap.get("10003");
|
|
|
|
- if (StringUtils.isNotBlank(eventId)
|
|
|
|
- && appAbCode != null
|
|
|
|
- && appAbCode.containsKey(eventId)) {
|
|
|
|
- param.setAbCode(appAbCode.get(eventId).get("ab_code"));
|
|
|
|
- param.setRuleKey(appAbCode.get(eventId).get("rule_key"));
|
|
|
|
- param.setDataKey(appAbCode.get(eventId).get("data_key"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- // 流量池分发实验组划分
|
|
|
|
- int flowPoolIdChoice = flowPoolIds.get(RandomUtils.nextInt(0, flowPoolIds.size()));
|
|
|
|
- Map<String, List<Integer>> flowPoolConfig = flowPoolConfigService.getFlowPoolConfig();
|
|
|
|
- Set<String> abExpCodes = param.getAbExpCodes();
|
|
|
|
- if (Objects.nonNull(abExpCodes) && abExpCodes.contains(Constant.SUPPLY_AB_CODE_ID)) {
|
|
|
|
-// if (Objects.equals(Constant.SUPPLY_AB_CODE, param.getAbCode())) {
|
|
|
|
- List<Integer> supplyFlowPoolIdList = flowPoolConfig.get(FlowPoolConstants.SUPPLY_FLOW_SET_LEVEL);
|
|
|
|
- if (Objects.nonNull(supplyFlowPoolIdList) && !supplyFlowPoolIdList.isEmpty()) {
|
|
|
|
- flowPoolIdChoice = supplyFlowPoolIdList.get(0);
|
|
|
|
- param.setFlowPoolId(flowPoolIdChoice);
|
|
|
|
- param.setFlowPoolAbtestGroup(FlowPoolConstants.SUPPLY_FLOW_SET_LEVEL);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- param.setFlowPoolId(flowPoolIdChoice);
|
|
|
|
- param.setFlowPoolAbtestGroup("control_group");
|
|
|
|
- for (Map.Entry<String, List<Integer>> entry : flowPoolConfig.entrySet()) {
|
|
|
|
- if (entry.getValue().contains(flowPoolIdChoice)) {
|
|
|
|
- param.setFlowPoolAbtestGroup(entry.getKey());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // @desc 新的流量池分发实验组划分,每个尾号不同策略分组。 @time 20240318 @author 张博
|
|
|
|
- int lastDigit = RandomUtils.nextInt(0, 10);
|
|
|
|
- param.setLastDigit(lastDigit);
|
|
|
|
-
|
|
|
|
// 风险过滤
|
|
// 风险过滤
|
|
- List<String> keysRisk = new ArrayList<>();
|
|
|
|
- keysRisk.add("RISK_SHIELD_FILTER_RULE_V1_JSON");
|
|
|
|
- keysRisk.add("RISK_SHIELD_FILTER_VIDEO_V1_STR");
|
|
|
|
- keysRisk.add("RISK_SHIELD_FILTER_EXPANSION_FACTOR_INT");
|
|
|
|
- keysRisk.add("RISK_SHIELD_FILTER_FLAG_BOOL");
|
|
|
|
- List<String> valuesRisk = redisTemplate.opsForValue().multiGet(keysRisk);
|
|
|
|
- String RISK_SHIELD_FILTER_RULE_V1_JSON = "";
|
|
|
|
- String RISK_SHIELD_FILTER_VIDEO_V1_STR = "";
|
|
|
|
- String RISK_SHIELD_FILTER_EXPANSION_FACTOR_INT = "";
|
|
|
|
- String RISK_SHIELD_FILTER_FLAG_BOOL = "";
|
|
|
|
- if (valuesRisk != null && valuesRisk.size() == 4) {
|
|
|
|
- RISK_SHIELD_FILTER_RULE_V1_JSON = valuesRisk.get(0);
|
|
|
|
- RISK_SHIELD_FILTER_VIDEO_V1_STR = valuesRisk.get(1);
|
|
|
|
- RISK_SHIELD_FILTER_EXPANSION_FACTOR_INT = valuesRisk.get(2);
|
|
|
|
- RISK_SHIELD_FILTER_FLAG_BOOL = valuesRisk.get(3);
|
|
|
|
- } else {
|
|
|
|
- log.error("risk rule read redis is wrong");
|
|
|
|
- }
|
|
|
|
- Map<Integer, List<String>> appRegionFiltered = ParserUtils.parseJsonForRiskRule(RISK_SHIELD_FILTER_RULE_V1_JSON);
|
|
|
|
- List<Long> videosWithRisk = ParserUtils.parseJsonForRiskVideos(RISK_SHIELD_FILTER_VIDEO_V1_STR);
|
|
|
|
- int expansionFactor = 5;
|
|
|
|
- if (RISK_SHIELD_FILTER_EXPANSION_FACTOR_INT != null) {
|
|
|
|
- try {
|
|
|
|
- expansionFactor = Integer.parseInt(RISK_SHIELD_FILTER_EXPANSION_FACTOR_INT);
|
|
|
|
- } catch (NumberFormatException e) {
|
|
|
|
- expansionFactor = 5;
|
|
|
|
- }
|
|
|
|
|
|
+ if (riskVideoFilterSwitch) {
|
|
|
|
+ boolean riskUser = riskScenes.contains(request.getHotSceneType())
|
|
|
|
+ || riskUserCache.getUnchecked(RedisKeyConstants.Recommend.riskUserUid).contains(param.getUid())
|
|
|
|
+ || riskUserCache.getUnchecked(RedisKeyConstants.Recommend.riskUserMid).contains(param.getMid());
|
|
|
|
+ param.setRiskUser(riskUser);
|
|
}
|
|
}
|
|
- // 容灾
|
|
|
|
- if (expansionFactor < 5) {
|
|
|
|
- expansionFactor = 5;
|
|
|
|
- } else if (expansionFactor > 25) {
|
|
|
|
- expansionFactor = 25;
|
|
|
|
- }
|
|
|
|
- Boolean riskFilterFlag = false;
|
|
|
|
- if (RISK_SHIELD_FILTER_FLAG_BOOL != null) {
|
|
|
|
- try {
|
|
|
|
- riskFilterFlag = Boolean.parseBoolean(RISK_SHIELD_FILTER_FLAG_BOOL.toLowerCase());
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- riskFilterFlag = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- param.setAppRegionFiltered(appRegionFiltered);
|
|
|
|
- param.setVideosWithRisk(videosWithRisk);
|
|
|
|
- param.setExpansionFactor(expansionFactor);
|
|
|
|
- param.setRiskFilterFlag(riskFilterFlag);
|
|
|
|
|
|
+
|
|
|
|
|
|
if (request.hasMachineInfo()) {
|
|
if (request.hasMachineInfo()) {
|
|
MachineInfoProto machineInfoProto = request.getMachineInfo();
|
|
MachineInfoProto machineInfoProto = request.getMachineInfo();
|
|
@@ -448,40 +345,6 @@ public class RecommendService {
|
|
param.setMachineInfo(machineInfo);
|
|
param.setMachineInfo(machineInfo);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- // TODO:hard code 为了快速做AB验证,应该由AB系统支持
|
|
|
|
- if (newExpList.contains(param.getAppType())) {
|
|
|
|
- if (newExpABTestServiceSwitch) {
|
|
|
|
- param.setExpIdMap(abTestRemoteService.getExp(param.getMid(), param.getUid(), param.getAppType(),
|
|
|
|
- request.getNewExpGroup()));
|
|
|
|
- } else {
|
|
|
|
- Map<String, List<Layer>> layerMap = CommonCollectionUtils.toMap(expConfigs, c -> c.getAppType(),
|
|
|
|
- c -> c.getLayers());
|
|
|
|
- if (MapUtils.isNotEmpty(layerMap)) {
|
|
|
|
- Map<String, Integer> bucketMap = JSONUtils.fromJson(request.getNewExpGroup(),
|
|
|
|
- new TypeToken<Map<String, Integer>>() {
|
|
|
|
- }, Collections.emptyMap());
|
|
|
|
- if (MapUtils.isNotEmpty(bucketMap)) {
|
|
|
|
- List<Layer> layers = layerMap.get(param.getAppType() + "");
|
|
|
|
-
|
|
|
|
- if (CollectionUtils.isNotEmpty(layers)) {
|
|
|
|
- Map<String, String> expIdMap = new HashMap<>();
|
|
|
|
- for (Layer layer : layers) {
|
|
|
|
- for (Exp exp : layer.getExps()) {
|
|
|
|
- if (bucketMap.containsKey(layer.getLayerId())
|
|
|
|
- && exp.getRange().length == 2
|
|
|
|
- && exp.getRange()[0] <= bucketMap.get(layer.getLayerId())
|
|
|
|
- && exp.getRange()[1] >= bucketMap.get(layer.getLayerId())) {
|
|
|
|
- expIdMap.put(layer.getLayerId(), exp.getExpId());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- param.setExpIdMap(expIdMap);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
if (StringUtils.isNotBlank(request.getCategoryId()) && StringUtils.isNumeric(request.getCategoryId())) {
|
|
if (StringUtils.isNotBlank(request.getCategoryId()) && StringUtils.isNumeric(request.getCategoryId())) {
|
|
param.setCategoryId(Integer.parseInt(request.getCategoryId()));
|
|
param.setCategoryId(Integer.parseInt(request.getCategoryId()));
|
|
}
|
|
}
|
|
@@ -495,17 +358,17 @@ public class RecommendService {
|
|
private List<Video> videoRecommend(RecommendParam param) {
|
|
private List<Video> videoRecommend(RecommendParam param) {
|
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
|
RecallResult recallResult = recallService.recall(convertToRecallParam(param));
|
|
RecallResult recallResult = recallService.recall(convertToRecallParam(param));
|
|
-
|
|
|
|
|
|
+
|
|
long recallTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
|
|
long recallTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
|
|
timerLogMapTL.get().put("recallTime", recallTime);
|
|
timerLogMapTL.get().put("recallTime", recallTime);
|
|
- log.info("recallResult={}, videoRecommend recallResult cost={}", recallResult, recallTime);
|
|
|
|
|
|
+ //log.info("recallResult={}, videoRecommend recallResult cost={}", recallResult, recallTime);
|
|
stopwatch.reset().start();
|
|
stopwatch.reset().start();
|
|
|
|
|
|
RankResult rankResult = rankRouter.rank(convertToRankParam(param, recallResult));
|
|
RankResult rankResult = rankRouter.rank(convertToRankParam(param, recallResult));
|
|
|
|
|
|
long rankTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
|
|
long rankTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
|
|
timerLogMapTL.get().put("rankTime", rankTime);
|
|
timerLogMapTL.get().put("rankTime", rankTime);
|
|
- log.info("rankResult={}, videoRecommend rank cost={}", rankResult, rankTime);
|
|
|
|
|
|
+ //log.info("rankResult={}, videoRecommend rank cost={}", rankResult, rankTime);
|
|
|
|
|
|
|
|
|
|
if (rankResult == null || CollectionUtils.isEmpty(rankResult.getVideos())) {
|
|
if (rankResult == null || CollectionUtils.isEmpty(rankResult.getVideos())) {
|
|
@@ -517,14 +380,6 @@ public class RecommendService {
|
|
if (param.getSize() < rankResult.getVideos().size()) {
|
|
if (param.getSize() < rankResult.getVideos().size()) {
|
|
videos = rankResult.getVideos().subList(0, param.getSize());
|
|
videos = rankResult.getVideos().subList(0, param.getSize());
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- // mark video in flow pool
|
|
|
|
- // TODO 业务上有什么用处
|
|
|
|
- // 需要被标记的视频满足什么条件
|
|
|
|
- // 逻辑已经废弃
|
|
|
|
- // markFlowPoolVideo(param, videos);
|
|
|
|
-
|
|
|
|
return videos;
|
|
return videos;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -533,28 +388,10 @@ public class RecommendService {
|
|
recallParam.setAppType(param.getAppType());
|
|
recallParam.setAppType(param.getAppType());
|
|
// hard code 算法实验配置化之前,复用abcode做AB验证
|
|
// hard code 算法实验配置化之前,复用abcode做AB验证
|
|
// note 避免非实验产品被覆盖
|
|
// note 避免非实验产品被覆盖
|
|
- recallParam.setAbCode(param.getAbCode());
|
|
|
|
recallParam.setRuleKey(param.getRuleKey());
|
|
recallParam.setRuleKey(param.getRuleKey());
|
|
recallParam.setDataKey(param.getDataKey());
|
|
recallParam.setDataKey(param.getDataKey());
|
|
- recallParam.setHRuleKey(param.getHRuleKey());
|
|
|
|
- recallParam.setHDataKey(param.getHDataKey());
|
|
|
|
- if (newExpList.contains(param.getAppType())) {
|
|
|
|
- recallParam.setAbCode("");
|
|
|
|
- if (MapUtils.isNotEmpty(param.getExpIdMap()) && param.getExpIdMap().containsKey("recall")) {
|
|
|
|
- String expId = param.getExpIdMap().get("recall");
|
|
|
|
- if (abExpCodeMap.containsKey(expId)) {
|
|
|
|
- recallParam.setAbCode(abExpCodeMap.get(expId).get("ab_code"));
|
|
|
|
- recallParam.setRuleKey(abExpCodeMap.get(expId).get("rule_key"));
|
|
|
|
- recallParam.setDataKey(abExpCodeMap.get(expId).get("data_key"));
|
|
|
|
- recallParam.setHDataKey(abExpCodeMap.get(expId).get("h_data_key"));
|
|
|
|
- recallParam.setHRuleKey(abExpCodeMap.get(expId).get("h_rule_key"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
recallParam.setVideoId(param.getVideoId());
|
|
recallParam.setVideoId(param.getVideoId());
|
|
- recallParam.setFlowPoolAbtestGroup(param.getFlowPoolAbtestGroup());
|
|
|
|
- recallParam.setLastDigit(param.getLastDigit());
|
|
|
|
|
|
|
|
String provinceCode = StringUtils.isNotBlank(param.getProvinceCode())
|
|
String provinceCode = StringUtils.isNotBlank(param.getProvinceCode())
|
|
? param.getProvinceCode()
|
|
? param.getProvinceCode()
|
|
@@ -567,18 +404,13 @@ public class RecommendService {
|
|
recallParam.setSize(param.getSize());
|
|
recallParam.setSize(param.getSize());
|
|
recallParam.setUid(param.getUid());
|
|
recallParam.setUid(param.getUid());
|
|
//风险过滤
|
|
//风险过滤
|
|
- recallParam.setExpansionFactor(param.getExpansionFactor());
|
|
|
|
- recallParam.setRiskFilterFlag(param.getRiskFilterFlag());
|
|
|
|
- recallParam.setVideosWithRisk(param.getVideosWithRisk());
|
|
|
|
- recallParam.setAppRegionFiltered(param.getAppRegionFiltered());
|
|
|
|
|
|
+ recallParam.setRiskUser(param.isRiskUser());
|
|
recallParam.setAbExpCodes(param.getAbExpCodes());
|
|
recallParam.setAbExpCodes(param.getAbExpCodes());
|
|
|
|
|
|
recallParam.setProvince(param.getProvince());
|
|
recallParam.setProvince(param.getProvince());
|
|
- recallParam.setExpIdMap(param.getExpIdMap());
|
|
|
|
recallParam.setCategoryId(param.getCategoryId());
|
|
recallParam.setCategoryId(param.getCategoryId());
|
|
|
|
|
|
recallParam.setCityCode(param.getCityCode());
|
|
recallParam.setCityCode(param.getCityCode());
|
|
- // recallParam.setAbCode(param.getAbCode());
|
|
|
|
|
|
|
|
recallParam.setHotSceneType(param.getHotSceneType());
|
|
recallParam.setHotSceneType(param.getHotSceneType());
|
|
recallParam.setClientIp(param.getClientIp());
|
|
recallParam.setClientIp(param.getClientIp());
|
|
@@ -590,27 +422,7 @@ public class RecommendService {
|
|
public RankParam convertToRankParam(RecommendParam param, RecallResult recallResult) {
|
|
public RankParam convertToRankParam(RecommendParam param, RecallResult recallResult) {
|
|
RankParam rankParam = new RankParam();
|
|
RankParam rankParam = new RankParam();
|
|
rankParam.setRecallResult(recallResult);
|
|
rankParam.setRecallResult(recallResult);
|
|
- // hard code 算法实验配置化之前,复用abcode做AB验证
|
|
|
|
- // note 避免非实验产品被覆盖
|
|
|
|
- rankParam.setAbCode(param.getAbCode());
|
|
|
|
rankParam.setRankKeyPrefix(param.getRankKeyPrefix());
|
|
rankParam.setRankKeyPrefix(param.getRankKeyPrefix());
|
|
- if (newExpList.contains(param.getAppType())) {
|
|
|
|
- rankParam.setAbCode("");
|
|
|
|
-// if (MapUtils.isNotEmpty(param.getExpIdMap())
|
|
|
|
-// && param.getExpIdMap().containsKey("rank")) {
|
|
|
|
-// String expId = param.getExpIdMap().get("rank");
|
|
|
|
- // TODO hard code MVP版本 为了快速验证,对rank强制染色,不做实验编排
|
|
|
|
- if (MapUtils.isNotEmpty(param.getExpIdMap())
|
|
|
|
- && param.getExpIdMap().containsKey("recall")) {
|
|
|
|
- String expId = param.getExpIdMap().get("recall");
|
|
|
|
- if (abExpCodeMap.containsKey(expId)) {
|
|
|
|
- rankParam.setAbCode(abExpCodeMap.get(expId).get("ab_code"));
|
|
|
|
- rankParam.setRankKeyPrefix(StringUtils.isNotBlank(abExpCodeMap.get(expId).get("rank_key_prefix"))
|
|
|
|
- ? abExpCodeMap.get(expId).get("rank_key_prefix")
|
|
|
|
- : "rank:score1:");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
rankParam.setSize(param.getSize());
|
|
rankParam.setSize(param.getSize());
|
|
rankParam.setFlowPoolP(param.getFlowPoolP());
|
|
rankParam.setFlowPoolP(param.getFlowPoolP());
|
|
@@ -621,41 +433,12 @@ public class RecommendService {
|
|
rankParam.setCity(param.getCity());
|
|
rankParam.setCity(param.getCity());
|
|
rankParam.setMachineInfo(param.getMachineInfo());
|
|
rankParam.setMachineInfo(param.getMachineInfo());
|
|
rankParam.setAbExpCodes(param.getAbExpCodes());
|
|
rankParam.setAbExpCodes(param.getAbExpCodes());
|
|
- rankParam.setExpIdMap(param.getExpIdMap());
|
|
|
|
rankParam.setCategoryId(param.getCategoryId());
|
|
rankParam.setCategoryId(param.getCategoryId());
|
|
rankParam.setHeadVid(param.getVideoId());
|
|
rankParam.setHeadVid(param.getVideoId());
|
|
|
|
+ rankParam.setHotSceneType(param.getHotSceneType());
|
|
return rankParam;
|
|
return rankParam;
|
|
}
|
|
}
|
|
|
|
|
|
- @Deprecated
|
|
|
|
- private void markFlowPoolVideo(RecommendParam param, List<Video> videos) {
|
|
|
|
- // TODO
|
|
|
|
- for (Video data : videos) {
|
|
|
|
- try {
|
|
|
|
- Long videoId = data.getVideoId();
|
|
|
|
- String quick_flow_pool_isin_flow_pool_key =
|
|
|
|
- String.format("flow:pool:quick:video:ids:%s:3", param.getAppType());
|
|
|
|
- String quick_flow_pool_flow_pool_key =
|
|
|
|
- String.format("flow:pool:quick:video:%s:3:%s", param.getAppType(), videoId);
|
|
|
|
- if (redisTemplate.opsForSet().isMember(quick_flow_pool_isin_flow_pool_key, String.valueOf(videoId))) {
|
|
|
|
- data.setFlowPool(redisTemplate.opsForSet().randomMember(quick_flow_pool_flow_pool_key));
|
|
|
|
- data.setInFlowPool(true);
|
|
|
|
- } else {
|
|
|
|
- String isIn_flow_pool_key =
|
|
|
|
- String.format("flow:pool:video:ids:%s", param.getAppType());
|
|
|
|
- String flow_pool_key =
|
|
|
|
- String.format("flow:pool:video:%s:%s", param.getAppType(), videoId);
|
|
|
|
- if (redisTemplate.opsForSet().isMember(isIn_flow_pool_key, String.valueOf(videoId))) {
|
|
|
|
- data.setFlowPool(redisTemplate.opsForSet().randomMember(flow_pool_key));
|
|
|
|
- data.setInFlowPool(true);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("markFlowPoolVideo error data={}", JSONUtils.toJson(data));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void updateCache(RecommendRequest request, RecommendParam param, List<Video> videos) {
|
|
public void updateCache(RecommendRequest request, RecommendParam param, List<Video> videos) {
|
|
if (StringUtils.isBlank(request.getMid())
|
|
if (StringUtils.isBlank(request.getMid())
|
|
|| CollectionUtils.isEmpty(videos)) {
|
|
|| CollectionUtils.isEmpty(videos)) {
|
|
@@ -685,21 +468,7 @@ public class RecommendService {
|
|
if (CollectionUtils.isEmpty(flowPoolVideos)) {
|
|
if (CollectionUtils.isEmpty(flowPoolVideos)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- switch (param.getFlowPoolAbtestGroup()) {
|
|
|
|
- case FlowPoolConstants.SUPPLY_FLOW_SET_LEVEL:
|
|
|
|
- flowPoolService.updateSupplyDistributeCountWithLevel(flowPoolVideos);
|
|
|
|
- break;
|
|
|
|
- case FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL:
|
|
|
|
- flowPoolService.updateDistributeCountWithLevel(flowPoolVideos);
|
|
|
|
- break;
|
|
|
|
- case FlowPoolConstants.EXPERIMENTAL_FLOW_SET_LEVEL_SCORE:
|
|
|
|
- flowPoolService.updateDistributeCountWithLevelScore(flowPoolVideos);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- flowPoolService.updateDistributeCountWithScore(flowPoolVideos);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ flowPoolService.updateDistributeCountWithLevel(flowPoolVideos);
|
|
}
|
|
}
|
|
|
|
|
|
private void updateLastVideoCache(List<Video> videos) {
|
|
private void updateLastVideoCache(List<Video> videos) {
|
|
@@ -723,88 +492,6 @@ public class RecommendService {
|
|
consumer.accept(Region24HRecallStrategy.PUSH_FORM);
|
|
consumer.accept(Region24HRecallStrategy.PUSH_FORM);
|
|
consumer.accept(RegionRelative24HRecallStrategy.PUSH_FORM);
|
|
consumer.accept(RegionRelative24HRecallStrategy.PUSH_FORM);
|
|
consumer.accept(RegionRelative24HDupRecallStrategy.PUSH_FORM);
|
|
consumer.accept(RegionRelative24HDupRecallStrategy.PUSH_FORM);
|
|
- consumer.accept(RegionHWithoutDupRecallStrategy.PUSH_FORM);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static class ExpConfig {
|
|
|
|
- private String appType;
|
|
|
|
- private List<Layer> layers;
|
|
|
|
-
|
|
|
|
- public String getAppType() {
|
|
|
|
- return appType;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setAppType(String appType) {
|
|
|
|
- this.appType = appType;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List<Layer> getLayers() {
|
|
|
|
- return layers;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setLayers(List<Layer> layers) {
|
|
|
|
- this.layers = layers;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static class Layer {
|
|
|
|
- private String layerId;
|
|
|
|
- private int bucketNum;
|
|
|
|
- private List<Exp> exps;
|
|
|
|
- private Map<String, String> groupRule;
|
|
|
|
-
|
|
|
|
- public String getLayerId() {
|
|
|
|
- return layerId;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setLayerId(String layerId) {
|
|
|
|
- this.layerId = layerId;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public int getBucketNum() {
|
|
|
|
- return bucketNum;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setBucketNum(int bucketNum) {
|
|
|
|
- this.bucketNum = bucketNum;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List<Exp> getExps() {
|
|
|
|
- return exps;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setExps(List<Exp> exps) {
|
|
|
|
- this.exps = exps;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Map<String, String> getGroupRule() {
|
|
|
|
- return groupRule;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setGroupRule(Map<String, String> groupRule) {
|
|
|
|
- this.groupRule = groupRule;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static class Exp {
|
|
|
|
- private String expId;
|
|
|
|
- private int[] range;
|
|
|
|
-
|
|
|
|
- public String getExpId() {
|
|
|
|
- return expId;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setExpId(String expId) {
|
|
|
|
- this.expId = expId;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public int[] getRange() {
|
|
|
|
- return range;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setRange(int[] range) {
|
|
|
|
- this.range = range;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|