|
@@ -23,6 +23,7 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
import static com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils.BREAK_CONFIG;
|
|
|
import static com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils.SHARE0_CONFIG;
|
|
@@ -33,7 +34,9 @@ public class NoShareUserThresholdPredictModel extends ThresholdPredictModel {
|
|
|
@Autowired
|
|
|
private FeatureRemoteService featureRemoteService;
|
|
|
|
|
|
- @Value("${ad.predict.threshold.share0:1}")
|
|
|
+ Random random;
|
|
|
+
|
|
|
+ @Value("${ad.predict.threshold.share0:0.4}")
|
|
|
private double threshold;
|
|
|
@Value("${ad.model.pid.type.share0:-1}")
|
|
|
private double pidType;
|
|
@@ -46,85 +49,88 @@ public class NoShareUserThresholdPredictModel extends ThresholdPredictModel {
|
|
|
@Override
|
|
|
public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
|
|
|
|
|
|
- UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(modelParam.getMid());
|
|
|
- if (userAdFeature == null) {
|
|
|
- userAdFeature = new UserAdFeature();
|
|
|
- }
|
|
|
- List<AdRankItem> rankItems = featureRemoteService.getAllAdFeatureList(CommonCollectionUtils.toList(AdConfig.getAdIds(), id -> id.toString()));
|
|
|
-
|
|
|
- // scoreParam
|
|
|
- AdRequestContext context = new AdRequestContext();
|
|
|
- context.setApptype(modelParam.getAppType().toString());
|
|
|
- context.setMachineinfoBrand(modelParam.getMachineInfo().getBrand());
|
|
|
- context.setMachineinfoModel(modelParam.getMachineInfo().getModel());
|
|
|
- context.setMachineinfoSdkversion(modelParam.getMachineInfo().getSdkVersion());
|
|
|
- context.setMachineinfoWchatversion(modelParam.getMachineInfo().getWeChatVersion());
|
|
|
- LocalDateTime date = LocalDateTime.now();
|
|
|
- context.setHour(date.getHour() + "");
|
|
|
- context.setDay(date.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
|
|
- context.setWeek(date.getDayOfWeek().getValue() + "");
|
|
|
-
|
|
|
- ScoreParam scoreParam = new ScoreParam();
|
|
|
- scoreParam.setRequestContext(context);
|
|
|
- scoreParam.getRequestContext().setRegion(modelParam.getRegion().replace("省", ""));
|
|
|
- scoreParam.getRequestContext().setCity(modelParam.getCity().replace("市", ""));
|
|
|
- scoreParam.setVideoId(modelParam.getVideoId());
|
|
|
- scoreParam.setMid(modelParam.getMid());
|
|
|
- scoreParam.setUid("");
|
|
|
- scoreParam.setProvince(modelParam.getRegion());
|
|
|
- scoreParam.setCity(modelParam.getCity());
|
|
|
- scoreParam.setExtraParam(modelParam.getExtraParam());
|
|
|
-
|
|
|
- List<AdRankItem> scoreResult = ScorerUtils
|
|
|
- .getScorerPipeline(SHARE0_CONFIG)
|
|
|
- .scoring(scoreParam, userAdFeature, rankItems);
|
|
|
-
|
|
|
- // 找出ctr*cvr最大的
|
|
|
-// double max = -1;
|
|
|
- AdRankItem maxItem = scoreResult.get(0);
|
|
|
-// for (int i = 0; i < scoreResult.size(); i++) {
|
|
|
-// AdRankItem item = scoreResult.get(i);
|
|
|
-// double ctrCvr = item.getCtr() * item.getCvr();
|
|
|
-// if (ctrCvr > max) {
|
|
|
-// max = ctrCvr;
|
|
|
-// maxItem = item;
|
|
|
-// }
|
|
|
+// UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(modelParam.getMid());
|
|
|
+// if (userAdFeature == null) {
|
|
|
+// userAdFeature = new UserAdFeature();
|
|
|
// }
|
|
|
- double realThreshold=Double.parseDouble(
|
|
|
- scoreParam.getExtraParam().getOrDefault("Share0Predict_"+modelParam.getAppType(),threshold).toString()
|
|
|
- );
|
|
|
- int adPredict;
|
|
|
- //加入pid逻辑
|
|
|
- if(pidType>1){
|
|
|
- realThreshold=realThreshold+ PredictPidContainer.getPidLambda(
|
|
|
- scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType());
|
|
|
- }else if(pidType>=0){
|
|
|
- realThreshold=PredictPidContainer.getLatestThreshold(
|
|
|
- scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (maxItem != null && maxItem.getScore() < realThreshold) {
|
|
|
- // If final score is below threshold, do not show the ad
|
|
|
- adPredict = 1;
|
|
|
- } else {
|
|
|
- // Otherwise, show the ad
|
|
|
- adPredict = 2;
|
|
|
- }
|
|
|
- if(maxItem != null){
|
|
|
- //删除多余打印
|
|
|
- maxItem.setItemFeature(null);
|
|
|
- maxItem.setLrSampleString(null);
|
|
|
- maxItem.setLrSampleStringOrgin(null);
|
|
|
- log.info("svc=Share0ThresholdPredictModel_predict modelName=ScoreV2ThresholdPredictModel maxItem={} extraParam={} app_type={} realThreshold={}",
|
|
|
- JSONObject.toJSONString(maxItem), JSONObject.toJSONString(scoreParam.getExtraParam()),modelParam.getAppType(),realThreshold);
|
|
|
- }
|
|
|
+// List<AdRankItem> rankItems = featureRemoteService.getAllAdFeatureList(CommonCollectionUtils.toList(AdConfig.getAdIds(), id -> id.toString()));
|
|
|
+//
|
|
|
+// // scoreParam
|
|
|
+// AdRequestContext context = new AdRequestContext();
|
|
|
+// context.setApptype(modelParam.getAppType().toString());
|
|
|
+// context.setMachineinfoBrand(modelParam.getMachineInfo().getBrand());
|
|
|
+// context.setMachineinfoModel(modelParam.getMachineInfo().getModel());
|
|
|
+// context.setMachineinfoSdkversion(modelParam.getMachineInfo().getSdkVersion());
|
|
|
+// context.setMachineinfoWchatversion(modelParam.getMachineInfo().getWeChatVersion());
|
|
|
+// LocalDateTime date = LocalDateTime.now();
|
|
|
+// context.setHour(date.getHour() + "");
|
|
|
+// context.setDay(date.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
|
|
+// context.setWeek(date.getDayOfWeek().getValue() + "");
|
|
|
+//
|
|
|
+// ScoreParam scoreParam = new ScoreParam();
|
|
|
+// scoreParam.setRequestContext(context);
|
|
|
+// scoreParam.getRequestContext().setRegion(modelParam.getRegion().replace("省", ""));
|
|
|
+// scoreParam.getRequestContext().setCity(modelParam.getCity().replace("市", ""));
|
|
|
+// scoreParam.setVideoId(modelParam.getVideoId());
|
|
|
+// scoreParam.setMid(modelParam.getMid());
|
|
|
+// scoreParam.setUid("");
|
|
|
+// scoreParam.setProvince(modelParam.getRegion());
|
|
|
+// scoreParam.setCity(modelParam.getCity());
|
|
|
+// scoreParam.setExtraParam(modelParam.getExtraParam());
|
|
|
+//
|
|
|
+// List<AdRankItem> scoreResult = ScorerUtils
|
|
|
+// .getScorerPipeline(SHARE0_CONFIG)
|
|
|
+// .scoring(scoreParam, userAdFeature, rankItems);
|
|
|
+//
|
|
|
+// // 找出ctr*cvr最大的
|
|
|
+//// double max = -1;
|
|
|
+// AdRankItem maxItem = scoreResult.get(0);
|
|
|
+//// for (int i = 0; i < scoreResult.size(); i++) {
|
|
|
+//// AdRankItem item = scoreResult.get(i);
|
|
|
+//// double ctrCvr = item.getCtr() * item.getCvr();
|
|
|
+//// if (ctrCvr > max) {
|
|
|
+//// max = ctrCvr;
|
|
|
+//// maxItem = item;
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+// double realThreshold=Double.parseDouble(
|
|
|
+// scoreParam.getExtraParam().getOrDefault("Share0Predict_"+modelParam.getAppType(),threshold).toString()
|
|
|
+// );
|
|
|
+// int adPredict;
|
|
|
+// //加入pid逻辑
|
|
|
+// if(pidType>1){
|
|
|
+// realThreshold=realThreshold+ PredictPidContainer.getPidLambda(
|
|
|
+// scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType());
|
|
|
+// }else if(pidType>=0){
|
|
|
+// realThreshold=PredictPidContainer.getLatestThreshold(
|
|
|
+// scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType());
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// if (maxItem != null && maxItem.getScore() < realThreshold) {
|
|
|
+// // If final score is below threshold, do not show the ad
|
|
|
+// adPredict = 1;
|
|
|
+// } else {
|
|
|
+// // Otherwise, show the ad
|
|
|
+// adPredict = 2;
|
|
|
+// }
|
|
|
+// if(maxItem != null){
|
|
|
+// //删除多余打印
|
|
|
+// maxItem.setItemFeature(null);
|
|
|
+// maxItem.setLrSampleString(null);
|
|
|
+// maxItem.setLrSampleStringOrgin(null);
|
|
|
+// log.info("svc=Share0ThresholdPredictModel_predict modelName=ScoreV2ThresholdPredictModel maxItem={} extraParam={} app_type={} realThreshold={}",
|
|
|
+// JSONObject.toJSONString(maxItem), JSONObject.toJSONString(scoreParam.getExtraParam()),modelParam.getAppType(),realThreshold);
|
|
|
+// }
|
|
|
+ double score=random.nextDouble();
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("threshold", realThreshold);
|
|
|
- result.put("score", maxItem == null ? -1 : maxItem.getScore());
|
|
|
- result.put("ad_predict", adPredict);
|
|
|
+// result.put("threshold", realThreshold);
|
|
|
+// result.put("score", maxItem == null ? -1 : maxItem.getScore());
|
|
|
+ result.put("ad_predict", score>threshold?2:1);
|
|
|
+ result.put("score", score);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
}
|