|
@@ -1,6 +1,7 @@
|
|
|
package com.tzld.piaoquan.ad.engine.service.predict.param;
|
|
|
|
|
|
import com.tzld.piaoquan.ad.engine.commons.redis.AdOwnRedisHelper;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
|
|
|
import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
@@ -14,7 +15,7 @@ import java.util.*;
|
|
|
public class RuleParamHelper {
|
|
|
|
|
|
@Autowired
|
|
|
- private AdOwnRedisHelper redisHelper;
|
|
|
+ private AlgorithmRedisHelper redisHelper;
|
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
|
|
//避免空指异常及重复创建过多Obj
|
|
@@ -45,6 +46,56 @@ public class RuleParamHelper {
|
|
|
}
|
|
|
return groupShareRate;
|
|
|
}
|
|
|
+ public Double getGroupShareRateForBasic( Map<String, Object> abTestParam,Date nowDate,String midGroup){
|
|
|
+ String nowDt = dateFormat.format(nowDate);
|
|
|
+ String shareUserDataKey = (String) ((Map<String,Object>) abTestParam
|
|
|
+ .getOrDefault("user",defaultMap)).get("data");
|
|
|
+ String shareUserRuleKey = (String)
|
|
|
+ ((Map<String,Object>)abTestParam.getOrDefault("user",defaultMap)).get("rule");
|
|
|
+ String groupShareRateKey = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_GROUP + shareUserDataKey + ":" + shareUserRuleKey + ":" + nowDt;
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(shareUserDataKey)||StringUtils.isEmpty(shareUserRuleKey)|| !redisHelper.contantinsKey(groupShareRateKey)) {
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(nowDate);
|
|
|
+ cal.add(Calendar.DATE, -1);
|
|
|
+ Date yesterday = cal.getTime();
|
|
|
+ String redisDt = dateFormat.format(yesterday);
|
|
|
+ groupShareRateKey = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_GROUP + shareUserDataKey + ":" + shareUserRuleKey + ":" + redisDt;
|
|
|
+ }
|
|
|
+
|
|
|
+ Double groupShareRate = redisHelper.zScore(groupShareRateKey, midGroup);
|
|
|
+ if(Objects.isNull(groupShareRate)){
|
|
|
+ groupShareRate=zeroDefaultValue;
|
|
|
+ }
|
|
|
+ return groupShareRate;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Double getVideoShareRateForBasic( Map<String, Object> abTestParam,Date nowDate,Long videoId){
|
|
|
+ String nowDt = dateFormat.format(nowDate);
|
|
|
+ String shareVideoDataKey = (String)
|
|
|
+ ((Map<String,Object>)abTestParam
|
|
|
+ .getOrDefault("video",defaultMap)).get("data");
|
|
|
+ String videoShareRateKey = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_VIDEO + shareVideoDataKey + ":" + nowDt;
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(shareVideoDataKey)||!redisHelper.contantinsKey(videoShareRateKey)) {
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(nowDate);
|
|
|
+ cal.add(Calendar.DATE, -1);
|
|
|
+ Date yesterday = cal.getTime();
|
|
|
+ String redisDt = dateFormat.format(yesterday);
|
|
|
+ videoShareRateKey = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_VIDEO + shareVideoDataKey + ":" + redisDt;
|
|
|
+ }
|
|
|
+
|
|
|
+ Double videoShareRate = redisHelper.zScore(videoShareRateKey, videoId.toString());
|
|
|
+ if (videoShareRate == null) {
|
|
|
+ videoShareRate = redisHelper.zScore(videoShareRateKey, -1+"");
|
|
|
+ }
|
|
|
+ if(Objects.isNull(videoShareRate)){
|
|
|
+ videoShareRate=zeroDefaultValue;
|
|
|
+ }
|
|
|
+ return videoShareRate;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public Double getVideoShareRate( Map<String, Object> abTestParam,Date nowDate,Long videoId){
|
|
|
String nowDt = dateFormat.format(nowDate);
|