|  | @@ -7,6 +7,7 @@ import com.tzld.piaoquan.ad.engine.service.score.dto.AdPlatformCreativeDTO;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
 | 
	
		
			
				|  |  |  import org.apache.commons.math3.distribution.BetaDistribution;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Component;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
	
		
			
				|  | @@ -20,25 +21,39 @@ public class VideoAdThompsonScorerV2 {
 | 
	
		
			
				|  |  |      private String redisCreativeStatisticsPrefix="redis:cid_aciton:";
 | 
	
		
			
				|  |  |      //redis:vid_cid_aciton:{$vid}_{$cid}
 | 
	
		
			
				|  |  |      private String redisVideoCreativeStatisticsPrefix="redis:vid_cid_aciton:";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private Map<String,Double> exp663Param=new HashMap<>();
 | 
	
		
			
				|  |  | +    private Map<String,Double> exp664Param=new HashMap<>();
 | 
	
		
			
				|  |  | +    private Map<String,Double> exp665Param=new HashMap<>();
 | 
	
		
			
				|  |  | +    private Map<String,Double> exp666Param=new HashMap<>();
 | 
	
		
			
				|  |  |      Random random=new Random();
 | 
	
		
			
				|  |  |      Gson gson=new Gson();
 | 
	
		
			
				|  |  | -    public List<AdRankItem> thompsonScorerByExp1(ScoreParam param, List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  | +    public List<AdRankItem> thompsonScorerByExp663(ScoreParam param, List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  |          List<AdRankItem> result=new LinkedList<>();
 | 
	
		
			
				|  |  |          String jsonStr;
 | 
	
		
			
				|  |  |          CreativeStatistic statistic;
 | 
	
		
			
				|  |  | +        List<String> redisKey=new LinkedList<>();
 | 
	
		
			
				|  |  | +        adIdList.forEach(creativeDTO -> {
 | 
	
		
			
				|  |  | +            redisKey.add(redisCreativeStatisticsPrefix+creativeDTO.getCreativeId());
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        List<String> values=redisHelper.getValues(redisKey);
 | 
	
		
			
				|  |  |          double score=0d;
 | 
	
		
			
				|  |  | +        int i=0;
 | 
	
		
			
				|  |  |          for(AdPlatformCreativeDTO dto:adIdList){
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  |                  AdRankItem item=new AdRankItem();
 | 
	
		
			
				|  |  |                  item.setVideoId(param.getVideoId());
 | 
	
		
			
				|  |  |                  item.setCpa(dto.getCpa());
 | 
	
		
			
				|  |  |                  item.setAdId(dto.getCreativeId());
 | 
	
		
			
				|  |  | -                jsonStr=redisHelper.getString(redisCreativeStatisticsPrefix+dto.getCreativeId());
 | 
	
		
			
				|  |  | +                jsonStr=values.get(i++);
 | 
	
		
			
				|  |  |                  if(jsonStr==null){
 | 
	
		
			
				|  |  | -                    score = 0.000001 + (random.nextDouble() * (0.00001 - 0.000001));
 | 
	
		
			
				|  |  | +                    score = exp663Param.getOrDefault("randomMin",0.000001)
 | 
	
		
			
				|  |  | +                            + (random.nextDouble() *
 | 
	
		
			
				|  |  | +                            (exp663Param.getOrDefault("randomMax",0.00001 ) - exp663Param.getOrDefault("randomMin",0.000001 )));
 | 
	
		
			
				|  |  |                  }else {
 | 
	
		
			
				|  |  |                      statistic =gson.fromJson(jsonStr,CreativeStatistic.class);
 | 
	
		
			
				|  |  | -                    score = (1d+Long.parseLong(statistic.getOrder())) / (10000d+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  | +                    score = (exp663Param.getOrDefault("alpha",1d)+Long.parseLong(statistic.getOrder()))
 | 
	
		
			
				|  |  | +                            / (exp663Param.getOrDefault("beta",10000d)+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  item.setScore(score);
 | 
	
		
			
				|  |  |                  result.add(item);
 | 
	
	
		
			
				|  | @@ -48,10 +63,16 @@ public class VideoAdThompsonScorerV2 {
 | 
	
		
			
				|  |  |          Collections.sort(result);
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    public List<AdRankItem> thompsonScorerByExp2(ScoreParam param,List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  | +    public List<AdRankItem> thompsonScorerByExp664(ScoreParam param,List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  |          List<AdRankItem> result=new LinkedList<>();
 | 
	
		
			
				|  |  |          String jsonStr;
 | 
	
		
			
				|  |  |          CreativeStatistic statistic;
 | 
	
		
			
				|  |  | +        List<String> redisKey=new LinkedList<>();
 | 
	
		
			
				|  |  | +        adIdList.forEach(creativeDTO -> {
 | 
	
		
			
				|  |  | +            redisKey.add(redisVideoCreativeStatisticsPrefix+param.getVideoId()+"_"+creativeDTO.getCreativeId());
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        List<String> values=redisHelper.getValues(redisKey);
 | 
	
		
			
				|  |  | +        int i=0;
 | 
	
		
			
				|  |  |          double score=0d;
 | 
	
		
			
				|  |  |          for(AdPlatformCreativeDTO dto:adIdList){
 | 
	
		
			
				|  |  |              try {
 | 
	
	
		
			
				|  | @@ -59,12 +80,15 @@ public class VideoAdThompsonScorerV2 {
 | 
	
		
			
				|  |  |                  item.setVideoId(param.getVideoId());
 | 
	
		
			
				|  |  |                  item.setCpa(dto.getCpa());
 | 
	
		
			
				|  |  |                  item.setAdId(dto.getCreativeId());
 | 
	
		
			
				|  |  | -                jsonStr=redisHelper.getString(redisVideoCreativeStatisticsPrefix+param.getVideoId()+"_"+dto.getCreativeId());
 | 
	
		
			
				|  |  | +                jsonStr=values.get(i++);
 | 
	
		
			
				|  |  |                  if(jsonStr==null){
 | 
	
		
			
				|  |  | -                    score = 0.000001 + (random.nextDouble() * (0.00001 - 0.000001));
 | 
	
		
			
				|  |  | +                    score = exp664Param.getOrDefault("randomMin",0.000001)
 | 
	
		
			
				|  |  | +                            + (random.nextDouble() *
 | 
	
		
			
				|  |  | +                            (exp664Param.getOrDefault("randomMax",0.00001 ) - exp664Param.getOrDefault("randomMin",0.000001 )));
 | 
	
		
			
				|  |  |                  }else {
 | 
	
		
			
				|  |  |                      statistic =gson.fromJson(jsonStr,CreativeStatistic.class);
 | 
	
		
			
				|  |  | -                    score = (1d+Long.parseLong(statistic.getOrder())) / (10000d+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  | +                    score = (exp664Param.getOrDefault("alpha",1d)+Long.parseLong(statistic.getOrder()))
 | 
	
		
			
				|  |  | +                            / (exp664Param.getOrDefault("beta",10000d)+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  item.setScore(score);
 | 
	
		
			
				|  |  |                  result.add(item);
 | 
	
	
		
			
				|  | @@ -74,10 +98,16 @@ public class VideoAdThompsonScorerV2 {
 | 
	
		
			
				|  |  |          Collections.sort(result);
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    public List<AdRankItem> thompsonScorerByExp3(ScoreParam param,List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  | +    public List<AdRankItem> thompsonScorerByExp665(ScoreParam param,List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  |          List<AdRankItem> result=new LinkedList<>();
 | 
	
		
			
				|  |  |          String jsonStr;
 | 
	
		
			
				|  |  |          CreativeStatistic statistic;
 | 
	
		
			
				|  |  | +        List<String> redisKey=new LinkedList<>();
 | 
	
		
			
				|  |  | +        adIdList.forEach(creativeDTO -> {
 | 
	
		
			
				|  |  | +            redisKey.add(redisCreativeStatisticsPrefix+creativeDTO.getCreativeId());
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        List<String> values=redisHelper.getValues(redisKey);
 | 
	
		
			
				|  |  | +        int i=0;
 | 
	
		
			
				|  |  |          double score=0d;
 | 
	
		
			
				|  |  |          for(AdPlatformCreativeDTO dto:adIdList){
 | 
	
		
			
				|  |  |              try {
 | 
	
	
		
			
				|  | @@ -85,12 +115,13 @@ public class VideoAdThompsonScorerV2 {
 | 
	
		
			
				|  |  |                  item.setVideoId(param.getVideoId());
 | 
	
		
			
				|  |  |                  item.setCpa(dto.getCpa());
 | 
	
		
			
				|  |  |                  item.setAdId(dto.getCreativeId());
 | 
	
		
			
				|  |  | -                jsonStr=redisHelper.getString(redisCreativeStatisticsPrefix+dto.getCreativeId());
 | 
	
		
			
				|  |  | +                jsonStr=values.get(i++);
 | 
	
		
			
				|  |  |                  if(jsonStr==null){
 | 
	
		
			
				|  |  | -                    score = betaSampler(1d,100000d);
 | 
	
		
			
				|  |  | +                    score = betaSampler(exp665Param.getOrDefault("alpha",1d),exp665Param.getOrDefault("beta",100000d));
 | 
	
		
			
				|  |  |                  }else {
 | 
	
		
			
				|  |  |                      statistic =gson.fromJson(jsonStr,CreativeStatistic.class);
 | 
	
		
			
				|  |  | -                    score = betaSampler(1d+Long.parseLong(statistic.getOrder()) , 10000d+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  | +                    score = betaSampler(exp665Param.getOrDefault("alpha",1d)+Long.parseLong(statistic.getOrder()) ,
 | 
	
		
			
				|  |  | +                            exp665Param.getOrDefault("beta",100000d)+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  item.setScore(score);
 | 
	
		
			
				|  |  |                  result.add(item);
 | 
	
	
		
			
				|  | @@ -100,15 +131,57 @@ public class VideoAdThompsonScorerV2 {
 | 
	
		
			
				|  |  |          Collections.sort(result);
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    public List<AdRankItem> thompsonScorerByExp4(ScoreParam param,List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  | +    public List<AdRankItem> thompsonScorerByExp666(ScoreParam param,List<AdPlatformCreativeDTO> adIdList){
 | 
	
		
			
				|  |  |          List<AdRankItem> result=new LinkedList<>();
 | 
	
		
			
				|  |  | +        String jsonStr;
 | 
	
		
			
				|  |  | +        CreativeStatistic statistic;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<String> redisKey=new LinkedList<>();
 | 
	
		
			
				|  |  | +        adIdList.forEach(creativeDTO -> {
 | 
	
		
			
				|  |  | +            redisKey.add(redisCreativeStatisticsPrefix+creativeDTO.getCreativeId());
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        List<String> values=redisHelper.getValues(redisKey);
 | 
	
		
			
				|  |  | +        List<String> combineKeys=new LinkedList<>();
 | 
	
		
			
				|  |  | +        adIdList.forEach(creativeDTO -> {
 | 
	
		
			
				|  |  | +            combineKeys.add(redisVideoCreativeStatisticsPrefix+param.getVideoId()+"_"+creativeDTO.getCreativeId());
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        List<String> combineValues=redisHelper.getValues(combineKeys);
 | 
	
		
			
				|  |  | +        int i=0;
 | 
	
		
			
				|  |  | +        double score=0d;
 | 
	
		
			
				|  |  |          for(AdPlatformCreativeDTO dto:adIdList){
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +                AdRankItem item=new AdRankItem();
 | 
	
		
			
				|  |  | +                item.setVideoId(param.getVideoId());
 | 
	
		
			
				|  |  | +                item.setCpa(dto.getCpa());
 | 
	
		
			
				|  |  | +                item.setAdId(dto.getCreativeId());
 | 
	
		
			
				|  |  | +                jsonStr=combineValues.get(i);
 | 
	
		
			
				|  |  | +                if(jsonStr==null){
 | 
	
		
			
				|  |  | +                    jsonStr=values.get(i);
 | 
	
		
			
				|  |  | +                    if(jsonStr==null){
 | 
	
		
			
				|  |  | +                        score = betaSampler(exp666Param.getOrDefault("alpha",1d),exp666Param.getOrDefault("beta",100000d));
 | 
	
		
			
				|  |  | +                    }else {
 | 
	
		
			
				|  |  | +                        statistic =gson.fromJson(jsonStr,CreativeStatistic.class);
 | 
	
		
			
				|  |  | +                        score = betaSampler(exp666Param.getOrDefault("alpha",1d)+Long.parseLong(statistic.getOrder()) , exp666Param.getOrDefault("beta",100000d)+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }else {
 | 
	
		
			
				|  |  | +                    statistic =gson.fromJson(jsonStr,CreativeStatistic.class);
 | 
	
		
			
				|  |  | +                    if(Double.parseDouble(statistic.getExp())>exp666Param.getOrDefault("viewThreshold",500d)){
 | 
	
		
			
				|  |  | +                        score = betaSampler(1d+Long.parseLong(statistic.getOrder()) , exp666Param.getOrDefault("beta",100000d)+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  | +                    } else if( values.get(i)!=null) {
 | 
	
		
			
				|  |  | +                        statistic =gson.fromJson(values.get(i),CreativeStatistic.class);
 | 
	
		
			
				|  |  | +                        score = betaSampler(exp666Param.getOrDefault("alpha",1d)+Long.parseLong(statistic.getOrder()) , exp666Param.getOrDefault("beta",100000d)+Long.parseLong(statistic.getExp())) *dto.getCpa();
 | 
	
		
			
				|  |  | +                    }else {
 | 
	
		
			
				|  |  | +                        score = betaSampler(exp666Param.getOrDefault("alpha",1d),exp666Param.getOrDefault("beta",100000d));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                item.setScore(score);
 | 
	
		
			
				|  |  | +                result.add(item);
 | 
	
		
			
				|  |  |              }catch (Exception e){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        Collections.sort(result);
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      class CreativeStatistic{
 | 
	
	
		
			
				|  | @@ -156,4 +229,20 @@ public class VideoAdThompsonScorerV2 {
 | 
	
		
			
				|  |  |          BetaDistribution betaSample = new BetaDistribution(alpha, beta);
 | 
	
		
			
				|  |  |          return betaSample.sample();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    @Value("${ad.engine.new.thompson.V2.663:{}}")
 | 
	
		
			
				|  |  | +    public void setExp663Param(String str){
 | 
	
		
			
				|  |  | +       this.exp663Param=gson.fromJson(str,Map.class);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    @Value("${ad.engine.new.thompson.V2.664:{}}")
 | 
	
		
			
				|  |  | +    public void setExp664Param(String str){
 | 
	
		
			
				|  |  | +        this.exp663Param=gson.fromJson(str,Map.class);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    @Value("${ad.engine.new.thompson.V2.665:{}}")
 | 
	
		
			
				|  |  | +    public void setExp665Param(String str){
 | 
	
		
			
				|  |  | +        this.exp663Param=gson.fromJson(str,Map.class);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    @Value("${ad.engine.new.thompson.V2.666:{}}")
 | 
	
		
			
				|  |  | +    public void setExp666Param(String str){
 | 
	
		
			
				|  |  | +        this.exp663Param=gson.fromJson(str,Map.class);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |