|
@@ -3,6 +3,7 @@ package com.tzld.piaoquan.ad.engine.service.score.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.tzld.piaoquan.ad.engine.service.score.container.AdCreativeFeatureContainer;
|
|
import com.tzld.piaoquan.ad.engine.service.score.container.AdCreativeFeatureContainer;
|
|
import com.tzld.piaoquan.ad.engine.service.score.container.PidLambdaContainer;
|
|
import com.tzld.piaoquan.ad.engine.service.score.container.PidLambdaContainer;
|
|
|
|
+import com.tzld.piaoquan.ad.engine.service.score.container.PidLambdaV2Container;
|
|
import com.tzld.piaoquan.ad.engine.service.score.dto.AdPlatformBidCreativeDTO;
|
|
import com.tzld.piaoquan.ad.engine.service.score.dto.AdPlatformBidCreativeDTO;
|
|
import com.tzld.piaoquan.ad.engine.service.score.param.BidRankRecommendRequestParam;
|
|
import com.tzld.piaoquan.ad.engine.service.score.param.BidRankRecommendRequestParam;
|
|
import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdItemFeature;
|
|
import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdItemFeature;
|
|
@@ -200,14 +201,114 @@ public class RankServiceImpl implements RankService {
|
|
object.put("pcvr",topItem.getCvr());
|
|
object.put("pcvr",topItem.getCvr());
|
|
object.put("lrsamples",topItem.getLrSampleString());
|
|
object.put("lrsamples",topItem.getLrSampleString());
|
|
object.put("pidLambda",topItem.getPidLambda());
|
|
object.put("pidLambda",topItem.getPidLambda());
|
|
|
|
+ //临时加入供pid v2使用
|
|
|
|
+ object.put("realECpm",realECpm);
|
|
|
|
+ object.put("creativeId",result.getCreativeId());
|
|
|
|
+ object.put("cpa",topItem.getCpa());
|
|
object.put("dataTime",currentTime.format(timeFormatter));
|
|
object.put("dataTime",currentTime.format(timeFormatter));
|
|
log.info("svc=adBidRank {}", JSONObject.toJSONString(object));
|
|
log.info("svc=adBidRank {}", JSONObject.toJSONString(object));
|
|
object.remove("lrsamples");
|
|
object.remove("lrsamples");
|
|
log.info("svc=pid_log obj={}", JSONObject.toJSONString(object));
|
|
log.info("svc=pid_log obj={}", JSONObject.toJSONString(object));
|
|
|
|
+ log.info("svc=pid_v2_log obj={}", JSONObject.toJSONString(object));
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public AdPlatformBidCreativeDTO adBidRankNewPid(BidRankRecommendRequestParam request) {
|
|
|
|
+
|
|
|
|
+ ScoreParam param= RequestConvert.requestConvert(request);
|
|
|
|
+ LocalDateTime currentTime = LocalDateTime.now();
|
|
|
|
+ int currentHour = currentTime.getHour();
|
|
|
|
+ int dayOfWeek = currentTime.getDayOfWeek().getValue();
|
|
|
|
+ param.getRequestContext().setHour(currentHour+"");
|
|
|
|
+ param.getRequestContext().setWeek(dayOfWeek+"");
|
|
|
|
+ param.getRequestContext().setRegion(request.getRegion().replace("省",""));
|
|
|
|
+ param.getRequestContext().setCity(request.getCity().replace("市",""));
|
|
|
|
+ param.getRequestContext().setDay(currentTime.format(dateFormatter));
|
|
|
|
+
|
|
|
|
+ UserAdFeature userAdFeature=featureRemoteService.getUserAdFeature(request.getMid());
|
|
|
|
+ if(userAdFeature==null){
|
|
|
|
+ userAdFeature=new UserAdFeature();
|
|
|
|
+ }
|
|
|
|
+ Map<String,List<AdPlatformBidCreativeDTO>> groupMap=request
|
|
|
|
+ .getCreativeList()
|
|
|
|
+ .stream()
|
|
|
|
+ .collect(Collectors.groupingBy(creativeDTO -> creativeDTO.getCreativeId()+""));
|
|
|
|
|
|
|
|
+ List<AdRankItem> rankItems=featureRemoteService.
|
|
|
|
+ getAllAdFeatureList(
|
|
|
|
+ new ArrayList<>(groupMap.keySet())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ for(AdRankItem item:rankItems){
|
|
|
|
+ try {
|
|
|
|
+ AdPlatformBidCreativeDTO dto=groupMap.get(item.getAdId()+"").get(0);
|
|
|
|
+ item.setBid1(dto.getBid1());
|
|
|
|
+ item.setBid2(dto.getBid2());
|
|
|
|
+ item.setCpa(dto.getCpa());
|
|
|
|
+ item.setPidLambda(PidLambdaV2Container.getPidLambda(item.getAdId()));
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<AdRankItem> rankResult;
|
|
|
|
+ if(rankItems==null|| rankItems.size()==0){
|
|
|
|
+ rankItems=new LinkedList<>();
|
|
|
|
+ for(AdPlatformBidCreativeDTO dto:request.getCreativeList()){
|
|
|
|
+ AdRankItem item=new AdRankItem();
|
|
|
|
+ item.setBid1(dto.getBid1());
|
|
|
|
+ item.setBid2(dto.getBid2());
|
|
|
|
+ item.setCpa(dto.getCpa());
|
|
|
|
+ item.setAdId(dto.getCreativeId());
|
|
|
|
+ item.setItemFeature(new AdItemFeature());
|
|
|
|
+ item.setPidLambda(PidLambdaV2Container.getPidLambda(item.getAdId()));
|
|
|
|
+ rankItems.add(item);
|
|
|
|
+ }
|
|
|
|
+ rankResult=rankServiceThompson.rank(param, userAdFeature, rankItems,null);
|
|
|
|
+ }else {
|
|
|
|
+ rankResult=rank(param, userAdFeature, rankItems,ScorerUtils.BASE_CONF);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ AdRankItem topItem=rankResult.get(0);
|
|
|
|
+
|
|
|
|
+ AdPlatformBidCreativeDTO result=AdPlatformBidCreativeDTO
|
|
|
|
+ .builder()
|
|
|
|
+ .build();
|
|
|
|
+ BeanUtils.copyProperties(topItem,result);
|
|
|
|
+ result.setCreativeId(topItem.getAdId());
|
|
|
|
+ result.setPctr(topItem.getCtr());
|
|
|
|
+ result.setPcvr(topItem.getCvr());
|
|
|
|
+ result.setCreativeCode(groupMap.get(topItem.getAdId()+"").get(0).getCreativeCode());
|
|
|
|
+ double realECpm=0d;
|
|
|
|
+ //经验值 待定
|
|
|
|
+ realECpm=topItem.getEcpm1();
|
|
|
|
+
|
|
|
|
+ if(realECpm>cpmMax/1000d){
|
|
|
|
+ realECpm=cpmMax/1000d;
|
|
|
|
+ }
|
|
|
|
+ if(realECpm<cpmMin/1000d){
|
|
|
|
+ realECpm=cpmMin/1000d;
|
|
|
|
+ }
|
|
|
|
+ result.setEcpm2(realECpm);
|
|
|
|
+ JSONObject object=new JSONObject();
|
|
|
|
+ object.put("mid",request.getMid());
|
|
|
|
+ object.put("adid",result.getCreativeId());
|
|
|
|
+ object.put("creativeCode",result.getCreativeCode());
|
|
|
|
+ object.put("type",topItem.getScore_type());
|
|
|
|
+ object.put("pctr",topItem.getCtr());
|
|
|
|
+ object.put("pcvr",topItem.getCvr());
|
|
|
|
+ object.put("lrsamples",topItem.getLrSampleString());
|
|
|
|
+ object.put("pidLambda",topItem.getPidLambda());
|
|
|
|
+ //临时加入供pid v2使用
|
|
|
|
+ object.put("realECpm",realECpm);
|
|
|
|
+ object.put("creativeId",result.getCreativeId());
|
|
|
|
+ object.put("cpa",topItem.getCpa());
|
|
|
|
+ object.put("dataTime",currentTime.format(timeFormatter));
|
|
|
|
+ log.info("svc=adBidRankNewPid {}", JSONObject.toJSONString(object));
|
|
|
|
+ object.remove("lrsamples");
|
|
|
|
+ log.info("svc=pid_v2_log obj={}", JSONObject.toJSONString(object));
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
|
|
public List<AdRankItem> rank (ScoreParam param, UserAdFeature userAdFeature, List<AdRankItem> rankItems,String configFile){
|
|
public List<AdRankItem> rank (ScoreParam param, UserAdFeature userAdFeature, List<AdRankItem> rankItems,String configFile){
|
|
List<AdRankItem> rankResult = ScorerUtils
|
|
List<AdRankItem> rankResult = ScorerUtils
|