Переглянути джерело

Merge branch 'feature_gufengshou_20240220_predict_no_share' into pre-master

gufengshou1 1 рік тому
батько
коміт
4a2d922553

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

@@ -244,7 +244,7 @@ public class PredictModelServiceImpl implements PredictModelService {
                     getThresholdPredictModel(thresholdMixFunc.toString())
                     .predict(modelParam);
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         return result;
     }
 

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

@@ -31,20 +31,18 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
     }
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
-        long startTime=System.currentTimeMillis();
-        String methodName=initName();
-        int step=1;
+
         Map<String, Object> result = new HashMap<>();
         // Get group and video share rates
         Double groupShareRate = paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(), modelParam.getMidGroup());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         Double videoShareRate = paramHelper.getVideoShareRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // Get group and video out rates
         Double groupOutRate = paramHelper.getGroupOutRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getMidGroup());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         Double videoOutRate = paramHelper.getVideoOutRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
 
         // Calculate mid-video prediction result
         if (groupShareRate == null || videoShareRate == null || groupOutRate == null || videoOutRate == null) {
@@ -59,7 +57,7 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
                 .videoShareRate(videoShareRate)
                 .shareWeight(shareWeight).outWeight(outWeight).build();
         double midVideoPredictRes = ThresholdPredictCalculator.addWeightCalculate(calculateParam);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
 
         // Get the threshold
         double threshold = paramHelper.getThreshold(
@@ -70,7 +68,7 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
                 modelParam.getCareModelStatus(),
                 modelParam.getAbtestParam()
         );
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // Threshold check
         int adPredict=midVideoPredictRes > threshold?2:1;
         result.put("mid_group", modelParam.getMidGroup());
@@ -84,7 +82,7 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
         result.put("mid_video_predict_res", midVideoPredictRes);
         result.put("threshold", threshold);
         result.put("ad_predict", adPredict);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         return result;
     }
 }

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

@@ -31,16 +31,14 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
 
     public Map<String, Object> predictWithRateProcess(ThresholdPredictModelParam modelParam,String midGroup){
 
-        long startTime=System.currentTimeMillis();
-        String methodName=initName();
-        int step=1;
+
 
 //        Double groupShareRate=paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(),midGroup);
         Double groupShareRate=paramHelper.getGroupShareRateForBasic(modelParam.getAbtestParam(),modelParam.getDate(),midGroup);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
 //        Double videoShareRate=paramHelper.getVideoShareRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getVideoId());
         Double videoShareRate=paramHelper.getVideoShareRateForBasic(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getVideoId());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         double threshold = paramHelper.getThreshold(
                 modelParam.getAbtestId(),
                 modelParam.getAbTestConfigTag(),
@@ -49,13 +47,13 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
                 modelParam.getCareModelStatus(),
                 modelParam.getAbtestParam()
         );
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         ThresholdCalculateParam calculateParam=ThresholdCalculateParam.builder()
                 .groupShareRate(groupShareRate)
                 .videoShareRate(videoShareRate).build();
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         Double midVideoPredictRes=ThresholdPredictCalculator.basicCalculate(calculateParam);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         int adPredict=midVideoPredictRes > threshold?2:1;
         Map<String, Object> result=new HashMap<>();
         result.put("mid_group", midGroup);
@@ -64,7 +62,7 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
         result.put("mid_video_predict_res", midVideoPredictRes);
         result.put("threshold", threshold);
         result.put("ad_predict", adPredict);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         return result;
     }
 }

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

@@ -30,21 +30,19 @@ public class MultiplyThresholdPredictModel  extends ThresholdPredictModel{
 
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
-        long startTime=System.currentTimeMillis();
-        String methodName=initName();
-        int step=1;
+
         Map<String, Object> result = new HashMap<>();
 
         // Get group and video share rates
         Double groupShareRate = paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getMidGroup());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         Double videoShareRate = paramHelper.getVideoShareRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // Get group and video out rates
         Double groupOutRate = paramHelper.getGroupOutRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getMidGroup());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         Double videoOutRate = paramHelper.getVideoOutRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // Calculate mid-video prediction result
         if (groupShareRate == null || videoShareRate == null || groupOutRate == null || videoOutRate == null) {
             return null;
@@ -65,7 +63,7 @@ public class MultiplyThresholdPredictModel  extends ThresholdPredictModel{
                 modelParam.getCareModelStatus(),
                 modelParam.getAbtestParam()
         );
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // Threshold check
         int adPredict=midVideoPredictRes > threshold?2:1;
 //            if (midVideoPredictRes > threshold) {

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

@@ -37,9 +37,7 @@ public class RoiThresholdPredictModel extends ThresholdPredictModel{
     RoiModelConfig roiModelConfig;
     @Override
     public <T extends ThresholdPredictModelParam> Map<String, Object> predict(T param) {
-        long startTime=System.currentTimeMillis();
-        String methodName=initName();
-        int step=1;
+
         RoiThresholdPredictModelParam modelParam=(RoiThresholdPredictModelParam)param;
         Date previousDate = new Date(modelParam.getDate().getTime() - (24 * 60 * 60 * 1000)); // Subtract one day
         String nowDt = new SimpleDateFormat("yyyyMMdd").format(modelParam.getDate());

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

@@ -31,17 +31,15 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
         Map<String, Object> result;
-        long startTime=System.currentTimeMillis();
-        String methodName=initName();
-        int step=1;
+
         String modelKey = (String) modelParam.getAbtestParam().getOrDefault("model_key", "ad_out_v1");
         String userKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_USER + modelKey + ":" + modelParam.getMid();
         String itemKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_ITEM + modelKey + ":" + modelParam.getVideoId();
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         String userScore = redisHelper.get(userKeyName);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         String itemScore = redisHelper.get(itemKeyName);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
 
         //加载配置数据
         String configKeyNamePrefix = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG
@@ -50,7 +48,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
                 + modelParam.getAbtestParam().get("abtest_config_tag");
         String configKey = configKeyNamePrefix + ":config";
         String configStr = redisHelper.get(configKey);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         Map<String, Object> configMap = new HashMap<>();
         String hitStrategy="model";
         if (configStr != null) {
@@ -71,7 +69,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
 
         boolean useBackup = Boolean.valueOf((String)configMap.getOrDefault("use_backup_key","false"));
 
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         //有数据为空且开启兜底策略
         if (
                 (StringUtils.isBlank(userScore) || StringUtils.isBlank(itemScore))
@@ -85,7 +83,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
             result.put("hit_strategy",hitStrategy);
             return result;
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         double offlineScore ;
         //处理空值逻辑
         double threshold=(double)configMap.getOrDefault("threshold",0);
@@ -103,7 +101,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
                     (double)configMap.getOrDefault("user_threshold", 0);
             hitStrategy=isUserScoreBlank?"item":"user";
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         //获取计算参数
         SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
         SimpleDateFormat weekDayFormat = new SimpleDateFormat("u");
@@ -121,7 +119,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
                 rankScore = Double.parseDouble(rankScoreStr);
             }
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore);
         double onlineScore=getOlineScore(onlineFeatures);
         double rankScoreBias = (double)configMap.getOrDefault("rank_score_bias", 0.0);
@@ -130,7 +128,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
         double rankScoreW = (double)configMap.getOrDefault("rank_score_w", 1.0);
         double finalScoreW = (double)configMap.getOrDefault("final_score_w", 1.0);
         double mergeScore = finalScoreW * finalScore + rankScoreW * (rankScore + rankScoreBias);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         int adPredict;
         if (mergeScore < threshold) {
             // If final score is below threshold, show the ad
@@ -139,7 +137,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
             // Otherwise, do not show the ad
             adPredict = 1;
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         result=new HashMap<>();
         result.put("user_score", userScore);
         result.put("item_score", itemScore);

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

@@ -47,15 +47,13 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
 
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
-        long startTime=System.currentTimeMillis();
-        String methodName=initName();
-        int step=1;
+
         UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(modelParam.getMid());
         if (userAdFeature == null) {
             userAdFeature = new UserAdFeature();
         }
         List<AdRankItem> rankItems = featureRemoteService.getAllAdFeatureList(CommonCollectionUtils.toList(AdConfig.getAdIds(), id -> id.toString()));
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // scoreParam
         AdRequestContext context = new AdRequestContext();
         context.setApptype(modelParam.getAppType().toString());
@@ -82,7 +80,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
         List<AdRankItem> scoreResult = ScorerUtils
                 .getScorerPipeline(BREAK_CONFIG)
                 .scoring(scoreParam, userAdFeature, rankItems);
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // 找出ctr*cvr最大的
         double max = -1;
         AdRankItem maxItem = null;
@@ -94,7 +92,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
                 maxItem = item;
             }
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         double realThreshold=Double.parseDouble(
                 scoreParam.getExtraParam().getOrDefault("ScoreV2ThresholdPredict_"+modelParam.getAppType(),threshold).toString()
         );
@@ -107,7 +105,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
             realThreshold=PredictPidContainer.getLatestThreshold(
                     scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType());
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
 
         if (maxItem != null && maxItem.getScore() < realThreshold) {
             // If final score is below threshold, do not show the ad
@@ -125,7 +123,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
             log.info("svc=ScoreV2ThresholdPredictModel_predict modelName=ScoreV2ThresholdPredictModel maxItem={} extraParam={} app_type={} realThreshold={}",
                     JSONObject.toJSONString(maxItem), JSONObject.toJSONString(scoreParam.getExtraParam()),modelParam.getAppType(),realThreshold);
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         Map<String, Object> result = new HashMap<>();
         result.put("threshold", realThreshold);
         result.put("score", maxItem == null ? -1 : maxItem.getScore());