Selaa lähdekoodia

Merge branch 'test' into dev_v1.0

# Conflicts:
#	ad-engine-server/src/main/java/com/tzld/piaoquan/ad/engine/server/Application.java
gufengshou1 1 vuosi sitten
vanhempi
commit
51fdc54182

+ 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

+ 3 - 0
ad-engine-server/src/main/resources/application.yml

@@ -76,6 +76,7 @@ mybatis:
     log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
 
 datalog: /datalog
+#datalog: /Users/gufengshou/Documents/yiqi_project
 
 logging:
   file:
@@ -90,6 +91,8 @@ aliyun:
       request: request-log
       info: info-log
       error: error-log
+      landingTypeFilter: landingpagetype-filter-error-log
+      adPackageData: ad-package-data
     topic:
     threadpool:
       corePoolSize: 100

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

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 
 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.calculator.ThresholdPredictCalculator;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.param.RuleParamHelper;
@@ -20,7 +21,7 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
     RuleParamHelper paramHelper;
 
     @Autowired
-    AdOwnRedisHelper redisHelper;
+    AlgorithmRedisHelper redisHelper;
 
     /**
      * setModelName

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

@@ -3,6 +3,7 @@ package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 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.calculator.ThresholdPredictCalculator;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.param.RuleParamHelper;
@@ -20,7 +21,7 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
     RuleParamHelper paramHelper;
 
     @Autowired
-    AdOwnRedisHelper redisHelper;
+    AlgorithmRedisHelper redisHelper;
     @Override
     String initName() {
         return "basic";
@@ -32,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(),

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

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 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.calculator.ThresholdPredictCalculator;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.param.RuleParamHelper;
@@ -19,7 +20,7 @@ public class MultiplyThresholdPredictModel  extends ThresholdPredictModel{
     RuleParamHelper paramHelper;
 
     @Autowired
-    AdOwnRedisHelper redisHelper;
+    AlgorithmRedisHelper redisHelper;
     /**
      * setModelName
      */

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

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 import com.tzld.piaoquan.ad.engine.commons.enums.AppTypeEnum;
 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.config.RoiModelConfig;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.containner.RoiPredictParamContainer;
@@ -23,7 +24,7 @@ public class RoiThresholdPredictModel extends ThresholdPredictModel{
     RuleParamHelper paramHelper;
 
     @Autowired
-    AdOwnRedisHelper redisHelper;
+    AlgorithmRedisHelper redisHelper;
 
     @Override
     String initName() {

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

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 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.config.AdOutV1OnlineWeightConfig;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.containner.ThresholdModelContainer;
@@ -17,7 +18,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
     RuleParamHelper paramHelper;
 
     @Autowired
-    AdOwnRedisHelper redisHelper;
+    AlgorithmRedisHelper redisHelper;
 
     @Override
     String initName() {

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

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