Authored by 张帅

自动点赞

@@ -382,20 +382,31 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ @@ -382,20 +382,31 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{
382 logger.warn("doVirtualPraise config is empty,praiseType ={},commonConfig={},specialConfig={},timeConfig={},",praiseType,commonConfig,specialConfig,timeConfig); 382 logger.warn("doVirtualPraise config is empty,praiseType ={},commonConfig={},specialConfig={},timeConfig={},",praiseType,commonConfig,specialConfig,timeConfig);
383 return; 383 return;
384 } 384 }
  385 +
385 String[] commonStrategy = StringUtils.split(commonConfig, ","); 386 String[] commonStrategy = StringUtils.split(commonConfig, ",");
386 String [] specialStrategy = StringUtils.split(specialConfig, ","); 387 String [] specialStrategy = StringUtils.split(specialConfig, ",");
387 //普通用户的点赞策略(线性函数) 388 //普通用户的点赞策略(线性函数)
388 - int start = Integer.valueOf(commonStrategy[0]);//起始(0,start)  
389 - int end = Integer.valueOf(commonStrategy[1]);//终结(timeConfig,end) 389 + int min = Integer.valueOf(commonStrategy[0]);//起始(0,start)
  390 + int max = Integer.valueOf(commonStrategy[1]);//终结(timeConfig,end)
390 //重点用户的点赞策略(线性函数) 391 //重点用户的点赞策略(线性函数)
391 - int startSpecial = Integer.valueOf(specialStrategy[0]);//起始点(0,startSpecial)  
392 - int endSpecial = Integer.valueOf(specialStrategy[1]);//终结(timeConfig,endSpecial)  
393 - //两个坐标点 --线性函数 y=kx + b  
394 -// double k = ((end - start)*1d) / (timeConfig * 1d); 392 + int specialMin = Integer.valueOf(specialStrategy[0]);//起始点(0,startSpecial)
  393 + int specialMax = Integer.valueOf(specialStrategy[1]);//终结(timeConfig,endSpecial)
  394 +
  395 + //根据当前批次需要点赞的文章数量, 取合适的点赞区间 如 min = 10 max = 50 list.size =70 则 区间取 10 - 35
  396 + int articleNum = articleList.size() / 2;
  397 + if(articleNum < max && articleNum> min){
  398 + max = articleNum;
  399 + }else if(articleNum <= min ){
  400 + max = min+ articleNum;
  401 + }
  402 +
  403 + if(articleNum < specialMax && articleNum> specialMin){
  404 + specialMax = articleNum;
  405 + }else if(articleNum <= min ){
  406 + specialMax = specialMin+ articleNum;
  407 + }
  408 +
395 double k = timeConfig; 409 double k = timeConfig;
396 - double b = start;  
397 - double kSpecial = timeConfig;  
398 - double bSpecial = startSpecial;  
399 410
400 //3)基础数据--原有的点赞(正常的点赞--排除; 取消的点赞--不要发站内信) 411 //3)基础数据--原有的点赞(正常的点赞--排除; 取消的点赞--不要发站内信)
401 Map<Integer,List<Integer>> articlePraiseMap = new HashMap<>(); 412 Map<Integer,List<Integer>> articlePraiseMap = new HashMap<>();
@@ -436,9 +447,9 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ @@ -436,9 +447,9 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{
436 } 447 }
437 Set<Integer> randomUidList; 448 Set<Integer> randomUidList;
438 if(authorType == GrassUserTypeEnum.COMMON.getValue() && specialAuthors.contains(authorUid)){//有货的用户,并且是重点用户,采用的线性函数有所不同 449 if(authorType == GrassUserTypeEnum.COMMON.getValue() && specialAuthors.contains(authorUid)){//有货的用户,并且是重点用户,采用的线性函数有所不同
439 - randomUidList = getPraiseUids(tempList, kSpecial, bSpecial, time, end); 450 + randomUidList = getPraiseUids(tempList,k, specialMin, specialMax, time);
440 }else{ 451 }else{
441 - randomUidList = getPraiseUids(tempList, k, b, time, end); 452 + randomUidList = getPraiseUids(tempList, k, min, max, time);
442 } 453 }
443 if(CollectionUtils.isEmpty(randomUidList)){ 454 if(CollectionUtils.isEmpty(randomUidList)){
444 article.setPraiseCount(0);//新增加的点赞数是0 455 article.setPraiseCount(0);//新增加的点赞数是0
@@ -490,18 +501,17 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ @@ -490,18 +501,17 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{
490 501
491 //随着时间的推移,增加的点赞数 逐步减少--》y= kx + b 502 //随着时间的推移,增加的点赞数 逐步减少--》y= kx + b
492 //x 是距离当前的时间(分钟为单位,比小时更精确) 503 //x 是距离当前的时间(分钟为单位,比小时更精确)
493 - private Set<Integer> getPraiseUids(List<Integer> virtualList,double timeConfig,double start, double x , int end ) { 504 + private Set<Integer> getPraiseUids(List<Integer> virtualList,double timeConfig,int min, int max, double x) {
494 if(virtualList.isEmpty()){//没有可选的马甲粉丝 505 if(virtualList.isEmpty()){//没有可选的马甲粉丝
495 return new HashSet<>(); 506 return new HashSet<>();
496 } 507 }
497 - //数量--随着时间的推移,线性的  
498 -// double numDouble = k * x + b + new Random().nextInt(5);  
499 //使用对数函数模型 508 //使用对数函数模型
500 double y = x==0? 1/timeConfig : x/timeConfig; 509 double y = x==0? 1/timeConfig : x/timeConfig;
501 //需要随机可以加随机数 510 //需要随机可以加随机数
502 - double numDouble= start + new Random().nextInt(5); 511 + int bound = max-min == 0 ? 1 : max-min;
  512 + double numDouble= new Random().nextInt(bound) + min;
503 double m = log(y,1/timeConfig) * numDouble ; 513 double m = log(y,1/timeConfig) * numDouble ;
504 - double num = Math.ceil(m) > end ? Math.ceil(m) : end; 514 + double num = Math.ceil(m);
505 515
506 int addnum = new Double(num).intValue();//需要增加的点 516 int addnum = new Double(num).intValue();//需要增加的点
507 int totalVitual = virtualList.size(); 517 int totalVitual = virtualList.size();