Browse Source

Merge branch 'test'

gufengshou1 1 năm trước cách đây
mục cha
commit
9fb85765e0

+ 2 - 1
ad-engine-server/src/main/resources/application-dev.yml

@@ -43,7 +43,8 @@ spring:
     password: Wqsd@2019
     timeout: 1000
   redis-algorithm:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+#    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+    hostName: r-bp1fogs2mflr1ybfot.redis.rds.aliyuncs.com
     port: 6379
     password: Wqsd@2019
     timeout: 1000

+ 2 - 1
ad-engine-server/src/main/resources/application-test.yml

@@ -41,7 +41,8 @@ spring:
     password: Wqsd@2019
     timeout: 1000
   redis-algorithm:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+#    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+    hostName: r-bp1fogs2mflr1ybfot.redis.rds.aliyuncs.com
     port: 6379
     password: Wqsd@2019
     timeout: 1000

+ 4 - 2
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/BasicThresholdPredictModel.java

@@ -33,8 +33,10 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
     }
 
     public Map<String, Object> predictWithRateProcess(ThresholdPredictModelParam modelParam,String midGroup){
-        Double groupShareRate=paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(),midGroup);
-        Double videoShareRate=paramHelper.getVideoShareRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getVideoId());
+//        Double groupShareRate=paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(),midGroup);
+        Double groupShareRate=paramHelper.getGroupShareRateForBasic(modelParam.getAbtestParam(),modelParam.getDate(),midGroup);
+//        Double videoShareRate=paramHelper.getVideoShareRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getVideoId());
+        Double videoShareRate=paramHelper.getVideoShareRateForBasic(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getVideoId());
         double threshold = paramHelper.getThreshold(
                 modelParam.getAbtestId(),
                 modelParam.getAbTestConfigTag(),

+ 50 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/param/RuleParamHelper.java

@@ -46,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);