瀏覽代碼

适配新实验系统

gufengshou1 1 年之前
父節點
當前提交
b081fd4c60

+ 157 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/helper/NewExpInfoHelper.java

@@ -0,0 +1,157 @@
+package com.tzld.piaoquan.ad.engine.service.predict.helper;
+
+import com.google.common.reflect.TypeToken;
+import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
+import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
+
+@Component
+public class NewExpInfoHelper {
+
+    public static Map<String,Set<String>> appExpIdCache=new HashMap<>();
+    public static Map<String,Exp> expIdAndRangeCache=new HashMap<>();
+
+    @Value("${new.exp,config.v2:[]}")
+    private void setNewExpInfo(String str){
+        List<ExpConfig> expConfigs= JSONUtils.fromJson(str, new TypeToken<List<ExpConfig>>() {
+        }, Collections.emptyList());
+        for (ExpConfig expConfig : expConfigs) {
+            String appId=expConfig.getAppType();
+            for (Layer layer : expConfig.layers) {
+                if (layer.layerId.equals("ad-server")){
+                    Set<String> expIdSet=new HashSet<>();
+                    for (Exp exp : layer.getExps()) {
+                        expIdSet.add(exp.getExpId());
+                        expIdAndRangeCache.put(exp.getExpId(),exp);
+                    }
+                    appExpIdCache.put(appId,expIdSet);
+                }
+            }
+        }
+    }
+
+    public static int getNewExpGroup(HttpServletRequest httpServletRequest){
+        try {
+            Map<String, String> expMap = JSONUtils.fromJson(httpServletRequest.getHeader("newGroupInfo"), new TypeToken<Map<String, String>>() {
+            }, Collections.emptyMap());
+            String groupStr=expMap.get("group");
+            Map<String, String> groupMap = JSONUtils.fromJson(groupStr, new TypeToken<Map<String, String>>() {
+            }, Collections.emptyMap());
+            return Integer.parseInt(groupMap.getOrDefault("ad-server","-1"));
+        }catch (Exception e){
+            return -1;
+        }
+    }
+
+    public static boolean checkInNewExpGroupAndSetParamIfIn(String appId, int groupNumber, String expId, ThresholdPredictModelParam modelParam){
+        try {
+            if(appExpIdCache.get(appId)==null||!appExpIdCache.get(appId).contains(expId)){
+                return false;
+            }
+            if(expIdAndRangeCache.get(expId).getRange()[0]<=groupNumber&&expIdAndRangeCache.get(expId).getRange()[1]>=groupNumber){
+                for(Map.Entry<String,Object> entry:expIdAndRangeCache.get(expId).getParam().entrySet()){
+                    modelParam.getExtraParam().put(entry.getKey(),entry.getValue());
+                }
+                return true;
+            }
+
+            return false;
+        }catch (Exception e){
+            return false;
+        }
+    }
+    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;
+
+        private Map<String,Object> param;
+
+        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;
+        }
+
+        public Map<String, Object> getParam() {
+            return param;
+        }
+
+        public void setParam(Map<String, Object> param) {
+            this.param = param;
+        }
+    }
+}

+ 7 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/impl/PredictModelServiceImpl.java

@@ -13,6 +13,7 @@ import com.tzld.piaoquan.ad.engine.service.predict.config.AbConfig;
 import com.tzld.piaoquan.ad.engine.service.predict.container.AbTestConfigContainer;
 import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer;
 import com.tzld.piaoquan.ad.engine.service.predict.container.TopOneVideoContainer;
+import com.tzld.piaoquan.ad.engine.service.predict.helper.NewExpInfoHelper;
 import com.tzld.piaoquan.ad.engine.service.predict.param.RoiThresholdPredictModelParam;
 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam;
 import com.tzld.piaoquan.ad.engine.service.predict.param.request.RoiPredictModelRequestParam;
@@ -197,7 +198,10 @@ public class PredictModelServiceImpl implements PredictModelService {
             result = ThresholdModelContainer.
                     getThresholdPredictModel("random")
                     .predict(modelParam);
-        }else if(inExpList(expCodes,adPredictImmersionExpCode)){
+        }else if(inExpList(expCodes,adPredictImmersionExpCode)
+                  ||
+                  NewExpInfoHelper.checkInNewExpGroupAndSetParamIfIn(
+                          requestParam.getAppType().toString(),requestParam.getNewExpGroup(),"607",modelParam)){
 //        if(randomModelExpCode!=null){
 //            modelParam.addUserExtraFuture("randomModelKey",ExpCodeEnum.valueOfExpCode(randomModelExpCode).getRandomModelKey());
             result = ThresholdModelContainer.
@@ -263,6 +267,8 @@ public class PredictModelServiceImpl implements PredictModelService {
                 }
             }
         }
+
+
     }
 
 

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

@@ -20,7 +20,7 @@ public class ThresholdPredictModelRequestParam {
     String abTestCode;
     JSONObject abExpInfo;
     Long careModelStatus;
-
+    Integer newExpGroup;
     String region = "-1";
     //市-中文
     String city = "-1";

+ 1 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/param/RecommendRequestParam.java

@@ -13,4 +13,5 @@ public class RecommendRequestParam {
     String region = "-1";
     //市-中文
     String city = "-1";
+    Integer newExpGroup;
 }