| 
														
															@@ -54,7 +54,7 @@ public class PidLambdaV2Container { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     Double minLambda = 0d; 
														 | 
														
														 | 
														
															     Double minLambda = 0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     OSS client; 
														 | 
														
														 | 
														
															     OSS client; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    private static ConcurrentHashMap<Long,Double>  lambdaCache=new ConcurrentHashMap<>(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    private static ConcurrentHashMap<Long,CacheItem>  lambdaCache=new ConcurrentHashMap<>(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     private Date cacheDate; 
														 | 
														
														 | 
														
															     private Date cacheDate; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     @PostConstruct 
														 | 
														
														 | 
														
															     @PostConstruct 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -92,22 +92,27 @@ public class PidLambdaV2Container { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             InputStreamReader isr=new InputStreamReader(is); 
														 | 
														
														 | 
														
															             InputStreamReader isr=new InputStreamReader(is); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             BufferedReader bufferedReader = new BufferedReader(isr); 
														 | 
														
														 | 
														
															             BufferedReader bufferedReader = new BufferedReader(isr); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             String line = null; 
														 | 
														
														 | 
														
															             String line = null; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            ConcurrentHashMap<Long,Double>  temp=new ConcurrentHashMap<>(); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            ConcurrentHashMap<Long,CacheItem>  temp=new ConcurrentHashMap<>(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            Double conversion=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            Double cpa=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            Double realCost=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            Double yesterdayConv=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            Double yesterdayCpa=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            Double yesterdayRealCost=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            Double latestRealCPA=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             while ((line = bufferedReader.readLine()) != null){ 
														 | 
														
														 | 
														
															             while ((line = bufferedReader.readLine()) != null){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 try { 
														 | 
														
														 | 
														
															                 try { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     String[] cols=line.split(","); 
														 | 
														
														 | 
														
															                     String[] cols=line.split(","); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     Long creativeId=Long.parseLong(cols[0]); 
														 | 
														
														 | 
														
															                     Long creativeId=Long.parseLong(cols[0]); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    Double conversion=Double.parseDouble(cols[1]); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    Double cpa=Double.parseDouble(cols[2]); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    Double realCost=Double.parseDouble(cols[3]); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    Double yesterdayConv=Double.parseDouble(cols[4]); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    Double yesterdayCpa=Double.parseDouble(cols[5]); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    Double yesterdayRealCost=Double.parseDouble(cols[6]); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    CacheItem cacheItem=lambdaCache.getOrDefault(creativeId,new CacheItem(creativeId)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    conversion=Double.parseDouble(cols[1]); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    cpa=Double.parseDouble(cols[2]); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    realCost=Double.parseDouble(cols[3]); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    yesterdayConv=Double.parseDouble(cols[4]); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    yesterdayCpa=Double.parseDouble(cols[5]); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    yesterdayRealCost=Double.parseDouble(cols[6]); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     Double lambdaNew=1d; 
														 | 
														
														 | 
														
															                     Double lambdaNew=1d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     if((conversion+yesterdayConv)!=0){ 
														 | 
														
														 | 
														
															                     if((conversion+yesterdayConv)!=0){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-//                        if(cpa*conversion!=0&&!realCost.equals(0d)){ 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-//                        lambdaNew=(cpa*conversion)/realCost; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-//                        } 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                         if((realCost*yesterdayRealCost)!=0){ 
														 | 
														
														 | 
														
															                         if((realCost*yesterdayRealCost)!=0){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                             double yesterdayW=yesterdayConv/(yesterdayConv+2*conversion); 
														 | 
														
														 | 
														
															                             double yesterdayW=yesterdayConv/(yesterdayConv+2*conversion); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                             lambdaNew=(yesterdayW*yesterdayConv*yesterdayCpa)/yesterdayRealCost 
														 | 
														
														 | 
														
															                             lambdaNew=(yesterdayW*yesterdayConv*yesterdayCpa)/yesterdayRealCost 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -117,7 +122,16 @@ public class PidLambdaV2Container { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                         }else if(yesterdayRealCost!=0){ 
														 | 
														
														 | 
														
															                         }else if(yesterdayRealCost!=0){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                             lambdaNew=(yesterdayConv*yesterdayCpa)/yesterdayRealCost; 
														 | 
														
														 | 
														
															                             lambdaNew=(yesterdayConv*yesterdayCpa)/yesterdayRealCost; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                         } 
														 | 
														
														 | 
														
															                         } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															- 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    if(conversion!=0){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                        latestRealCPA=realCost/conversion; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                        if(Math.abs(latestRealCPA-cpa)-Math.abs(cacheItem.latestRealCpa-cpa)>0){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                            cacheItem.pow=2d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                        }else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                            cacheItem.pow=1.2; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                        } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                        lambdaNew=Math.pow(lambdaNew,cacheItem.pow); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                        cacheItem.latestRealCpa=latestRealCPA; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     } 
														 | 
														
														 | 
														
															                     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -126,7 +140,9 @@ public class PidLambdaV2Container { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     }else if(lambdaNew<minLambda){ 
														 | 
														
														 | 
														
															                     }else if(lambdaNew<minLambda){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                         lambdaNew=minLambda; 
														 | 
														
														 | 
														
															                         lambdaNew=minLambda; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     } 
														 | 
														
														 | 
														
															                     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-                    temp.put(creativeId,lambdaNew); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    cacheItem.lambda=lambdaNew; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    cacheItem.latestConv=conversion; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                    temp.put(creativeId,cacheItem); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															                     log.info("svc=calNewLambdaV2 creativeId={} lambdaNew={}", creativeId,lambdaNew); 
														 | 
														
														 | 
														
															                     log.info("svc=calNewLambdaV2 creativeId={} lambdaNew={}", creativeId,lambdaNew); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 }catch (Exception e){ 
														 | 
														
														 | 
														
															                 }catch (Exception e){ 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -168,7 +184,7 @@ public class PidLambdaV2Container { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             while ((line=bufferedReader.readLine())!=null){ 
														 | 
														
														 | 
														
															             while ((line=bufferedReader.readLine())!=null){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 builder.append(line); 
														 | 
														
														 | 
														
															                 builder.append(line); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             } 
														 | 
														
														 | 
														
															             } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            lambdaCache=JSONObject.parseObject(builder.toString(),new TypeReference<ConcurrentHashMap<Long,Double>>(){}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            lambdaCache=JSONObject.parseObject(builder.toString(),new TypeReference<ConcurrentHashMap<Long,CacheItem>>(){}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             this.cacheDate=object.getObjectMetadata().getLastModified(); 
														 | 
														
														 | 
														
															             this.cacheDate=object.getObjectMetadata().getLastModified(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }catch (Exception e){ 
														 | 
														
														 | 
														
															         }catch (Exception e){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             log.error("svc=loadLambdaV2File status=failed error={}", Arrays.toString(e.getStackTrace())); 
														 | 
														
														 | 
														
															             log.error("svc=loadLambdaV2File status=failed error={}", Arrays.toString(e.getStackTrace())); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -178,10 +194,31 @@ public class PidLambdaV2Container { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															     public static Double getPidLambda(Long creativeId){ 
														 | 
														
														 | 
														
															     public static Double getPidLambda(Long creativeId){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         try { 
														 | 
														
														 | 
														
															         try { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            return lambdaCache.getOrDefault(creativeId,1d); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            return lambdaCache.getOrDefault(creativeId,new CacheItem(creativeId)).lambda; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         }catch (Exception e){ 
														 | 
														
														 | 
														
															         }catch (Exception e){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             return 1d; 
														 | 
														
														 | 
														
															             return 1d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         } 
														 | 
														
														 | 
														
															         } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    public static class CacheItem{ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public CacheItem(){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public CacheItem(Long creativeId){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            this.creativeId=creativeId; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public Long creativeId; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public double lambda=1d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public double latestConv=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public double pow=1d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public double latestRealCpa=0d; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 |