|  | @@ -18,6 +18,8 @@ import org.springframework.stereotype.Component;
 | 
											
												
													
														|  |  import java.util.*;
 |  |  import java.util.*;
 | 
											
												
													
														|  |  import java.util.stream.Collectors;
 |  |  import java.util.stream.Collectors;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +import static com.tzld.piaoquan.ad.engine.commons.score.model.ThompsonSamplingModel.alpha;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  @Component
 |  |  @Component
 | 
											
												
													
														|  |  public class VideoAdThompsonScorerV2 {
 |  |  public class VideoAdThompsonScorerV2 {
 | 
											
												
													
														|  |      Logger log = LoggerFactory.getLogger(VideoAdThompsonScorerV2.class);
 |  |      Logger log = LoggerFactory.getLogger(VideoAdThompsonScorerV2.class);
 | 
											
										
											
												
													
														|  | @@ -29,8 +31,8 @@ public class VideoAdThompsonScorerV2 {
 | 
											
												
													
														|  |      // redis:vid_cid_action:{$vid}_{$cid}
 |  |      // redis:vid_cid_action:{$vid}_{$cid}
 | 
											
												
													
														|  |      private String redisVideoCreativeStatisticsPrefix = "redis:vid_cid_action:";
 |  |      private String redisVideoCreativeStatisticsPrefix = "redis:vid_cid_action:";
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    private String rediCidActionKeyV1 = "redis:cid_action_v1:";
 |  | 
 | 
											
												
													
														|  | -    private String rediCidVidActionKeyV1 = "redis:vid_cid_action_v1:";
 |  | 
 | 
											
												
													
														|  | 
 |  | +    private final String redisCidActionKeyV1 = "redis:cid_action_v1:";
 | 
											
												
													
														|  | 
 |  | +    private final String redisCidVidActionKeyV1 = "redis:vid_cid_action_v1:";
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      private Map<String, Double> exp663Param = new HashMap<>();
 |  |      private Map<String, Double> exp663Param = new HashMap<>();
 | 
											
												
													
														|  |      private Map<String, Double> exp664Param = new HashMap<>();
 |  |      private Map<String, Double> exp664Param = new HashMap<>();
 | 
											
										
											
												
													
														|  | @@ -38,7 +40,7 @@ public class VideoAdThompsonScorerV2 {
 | 
											
												
													
														|  |      private Map<String, Double> exp666Param = new HashMap<>();
 |  |      private Map<String, Double> exp666Param = new HashMap<>();
 | 
											
												
													
														|  |      private Map<String, Double> exp669Param = new HashMap<>();
 |  |      private Map<String, Double> exp669Param = new HashMap<>();
 | 
											
												
													
														|  |      private Map<String, Double> exp670Param = new HashMap<>();
 |  |      private Map<String, Double> exp670Param = new HashMap<>();
 | 
											
												
													
														|  | -    private Map<String, Double> exp672Param = new HashMap<>();
 |  | 
 | 
											
												
													
														|  | 
 |  | +    private Map<String, String> exp672Param = new HashMap<>();
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      Random random = new Random();
 |  |      Random random = new Random();
 | 
											
												
													
														|  |      Gson gson = new Gson();
 |  |      Gson gson = new Gson();
 | 
											
										
											
												
													
														|  | @@ -390,8 +392,8 @@ public class VideoAdThompsonScorerV2 {
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      public List<AdRankItem> thompsonScorerByExp669(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
 |  |      public List<AdRankItem> thompsonScorerByExp669(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
 | 
											
												
													
														|  | -        Map<Long, CreativeStatistic> creativeStatisticsMap = this.batchFindCreativeRedisCache(rediCidActionKeyV1, adIdList);
 |  | 
 | 
											
												
													
														|  | -        Map<Long, CreativeStatistic> videoCreativeStatisticsMap = this.batchFindCreativeRedisCache(rediCidVidActionKeyV1 + param.getVideoId() + "_", adIdList);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> creativeStatisticsMap = this.batchFindCreativeRedisCache(redisCidActionKeyV1, adIdList);
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> videoCreativeStatisticsMap = this.batchFindCreativeRedisCache(redisCidVidActionKeyV1 + param.getVideoId() + "_", adIdList);
 | 
											
												
													
														|  |          Double creativeExpSum = this.sumCreativeStatisticExp(creativeStatisticsMap.values());
 |  |          Double creativeExpSum = this.sumCreativeStatisticExp(creativeStatisticsMap.values());
 | 
											
												
													
														|  |          Double videoCreativeExpSum = this.sumCreativeStatisticExp(videoCreativeStatisticsMap.values());
 |  |          Double videoCreativeExpSum = this.sumCreativeStatisticExp(videoCreativeStatisticsMap.values());
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -411,8 +413,8 @@ public class VideoAdThompsonScorerV2 {
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      public List<AdRankItem> thompsonScorerByExp670(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
 |  |      public List<AdRankItem> thompsonScorerByExp670(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
 | 
											
												
													
														|  | -        Map<Long, CreativeStatistic> creativeStatisticsMap = this.batchFindCreativeRedisCache(rediCidActionKeyV1, adIdList);
 |  | 
 | 
											
												
													
														|  | -        Map<Long, CreativeStatistic> videoCreativeStatisticsMap = this.batchFindCreativeRedisCache(rediCidVidActionKeyV1 + param.getVideoId() + "_", adIdList);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> creativeStatisticsMap = this.batchFindCreativeRedisCache(redisCidActionKeyV1, adIdList);
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> videoCreativeStatisticsMap = this.batchFindCreativeRedisCache(redisCidVidActionKeyV1 + param.getVideoId() + "_", adIdList);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          List<AdRankItem> result = new ArrayList<>(adIdList.size());
 |  |          List<AdRankItem> result = new ArrayList<>(adIdList.size());
 | 
											
												
													
														|  |          this.calcScore(result, adIdList, 0.0, 0.0, 0.0, creativeStatisticsMap, videoCreativeStatisticsMap, exp670Param);
 |  |          this.calcScore(result, adIdList, 0.0, 0.0, 0.0, creativeStatisticsMap, videoCreativeStatisticsMap, exp670Param);
 | 
											
										
											
												
													
														|  | @@ -557,10 +559,74 @@ public class VideoAdThompsonScorerV2 {
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      public List<AdRankItem> thompsonScorerByExp672(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
 |  |      public List<AdRankItem> thompsonScorerByExp672(ScoreParam param, List<AdPlatformCreativeDTO> adIdList) {
 | 
											
												
													
														|  | 
 |  | +        String cidRedisKey = exp672Param.getOrDefault("cidActionRedisKey", redisCidActionKeyV1);
 | 
											
												
													
														|  | 
 |  | +        String vidCidRedisKey = exp672Param.getOrDefault("vidCidActionRedisKey", redisCidVidActionKeyV1);
 | 
											
												
													
														|  | 
 |  | +        double viewThreshold = Double.parseDouble(exp672Param.getOrDefault("viewThreshold", "7000"));
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> paramCidRedisCache = this.batchFindCreativeRedisCache(cidRedisKey, adIdList);
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> paramVidCidRedisCache = this.batchFindCreativeRedisCache(vidCidRedisKey, adIdList);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> defaultCidCache = this.batchFindCreativeRedisCache(redisCidActionKeyV1, adIdList);
 | 
											
												
													
														|  | 
 |  | +        Map<Long, CreativeStatistic> defaultVidCidCache = this.batchFindCreativeRedisCache(redisCidVidActionKeyV1, adIdList);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        for (AdPlatformCreativeDTO dto : adIdList) {
 | 
											
												
													
														|  | 
 |  | +            Long cid = dto.getCreativeId();
 | 
											
												
													
														|  | 
 |  | +            paramCidRedisCache.putIfAbsent(cid, defaultCidCache.getOrDefault(cid, new CreativeStatistic()));
 | 
											
												
													
														|  | 
 |  | +            paramVidCidRedisCache.putIfAbsent(cid, defaultVidCidCache.getOrDefault(cid, new CreativeStatistic()));
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        List<AdRankItem> result = new ArrayList<>(adIdList.size());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        for (AdPlatformCreativeDTO dto : adIdList) {
 | 
											
												
													
														|  | 
 |  | +            Map<String, Object> ext = new HashMap<>();
 | 
											
												
													
														|  | 
 |  | +            double score = 0.0;
 | 
											
												
													
														|  | 
 |  | +            double cpa = dto.getCpa();
 | 
											
												
													
														|  | 
 |  | +            Long cid = dto.getCreativeId();
 | 
											
												
													
														|  | 
 |  | +            try {
 | 
											
												
													
														|  | 
 |  | +                String pairOrSingle = "pair";
 | 
											
												
													
														|  | 
 |  | +                CreativeStatistic vidCidStatistic = paramVidCidRedisCache.get(cid);
 | 
											
												
													
														|  | 
 |  | +                CreativeStatistic cidStatistic = paramCidRedisCache.get(cid);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                double order = vidCidStatistic.parseOrderToDouble();
 | 
											
												
													
														|  | 
 |  | +                double exp = vidCidStatistic.parseExpToDouble();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                if (exp < viewThreshold) {
 | 
											
												
													
														|  | 
 |  | +                    pairOrSingle = "single";
 | 
											
												
													
														|  | 
 |  | +                    order = cidStatistic.parseOrderToDouble();
 | 
											
												
													
														|  | 
 |  | +                    exp = cidStatistic.parseExpToDouble();
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +                if (exp > 0 && order > 0 && cpa > 0) {
 | 
											
												
													
														|  | 
 |  | +                    score = (order / exp) * cpa;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                ext.put("order", order);
 | 
											
												
													
														|  | 
 |  | +                ext.put("exp", exp);
 | 
											
												
													
														|  | 
 |  | +                ext.put("viewThreshold", viewThreshold);
 | 
											
												
													
														|  | 
 |  | +                ext.put("pairOrSingle", pairOrSingle);
 | 
											
												
													
														|  | 
 |  | +                ext.put("cidStatistic", JSON.toJSONString(cidStatistic));
 | 
											
												
													
														|  | 
 |  | +                ext.put("vidCidStatistic", JSON.toJSONString(vidCidStatistic));
 | 
											
												
													
														|  | 
 |  | +                ext.put("cpa", cpa);
 | 
											
												
													
														|  | 
 |  | +                ext.put("abCode", 672);
 | 
											
												
													
														|  | 
 |  | +            } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +                log.error("svc=666exp, error: ", e);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +            AdRankItem item = new AdRankItem();
 | 
											
												
													
														|  | 
 |  | +            item.setCpa(cpa);
 | 
											
												
													
														|  | 
 |  | +            item.setAdId(dto.getCreativeId());
 | 
											
												
													
														|  | 
 |  | +            item.setScore(score);
 | 
											
												
													
														|  | 
 |  | +            item.setExt(ext);
 | 
											
												
													
														|  | 
 |  | +            item.setVideoId(param.getVideoId());
 | 
											
												
													
														|  | 
 |  | +            item.setScore_type(672);
 | 
											
												
													
														|  | 
 |  | +            item.setWeight(dto.getWeight());
 | 
											
												
													
														|  | 
 |  | +            item.setCreativeCode(dto.getCreativeCode());
 | 
											
												
													
														|  | 
 |  | +            result.add(item);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        return null;
 |  | 
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        result.sort(equalsRandomComparator());
 | 
											
												
													
														|  | 
 |  | +        return result;
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      class CreativeStatistic {
 |  |      class CreativeStatistic {
 |