Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. storage.client
  2.         .add('reserv')
  3.         .map(function(v, keydata, args){
  4.             if( v.values ){
  5.                 var ret = [];
  6.                 var o = Riak.mapValuesJson(v)[0];
  7.                 if(o.DateCreated){
  8.                     ret.push(o);   
  9.                 }
  10.                 return ret;
  11.             }
  12.  
  13.             return [];
  14.         })
  15.         .reduce(function(v, args){
  16.             var statistics = {
  17.                 OrderCount: 0,
  18.                 PNRCount: 0,
  19.                 SegmentsCount: 0,
  20.                 PNRToSegments: { },
  21.                 PNRToPlatingCarriers: { },
  22.                 StartPoints: { },
  23.                 EndPoints: { },
  24.                 Status: { },
  25.                 TotalFareAndTaxes: 0,
  26.                 TotalAmount: 0,
  27.                 ProfitsByRoles: { }
  28.             }
  29.            
  30.             function rise(hash, field, value){
  31.                 if(!field){
  32.                     return;
  33.                 }
  34.            
  35.                 if(!hash[field]){
  36.                     hash[field] = 0;
  37.                 }
  38.                
  39.                 if( value ){
  40.                     hash[field] += value;                  
  41.                 }
  42.                 else{
  43.                     ++hash[field]; 
  44.                 }
  45.             }
  46.            
  47.             var v = result;
  48.            
  49.             for(var i = 0; i < v.length; i++){
  50.                 var curInfo = v[i];
  51.                
  52.                 if( curInfo.Trips == undefined ){
  53.                     continue;
  54.                 }
  55.                
  56.                 var firstTrip = curInfo.Trips[0];
  57.                 var lastTrip = curInfo.Trips[curInfo.Trips.length - 1];
  58.                
  59.                 statistics.PNRCount++;
  60.                 statistics.SegmentsCount += curInfo.Trips.length;
  61.                
  62.                 rise(statistics.PNRToSegments, curInfo.Trips.length);
  63.                 rise(statistics.PNRToPlatingCarriers, firstTrip.AirCompany);
  64.                 rise(statistics.StartPoints, firstTrip.From);
  65.                 rise(statistics.EndPoints, lastTrip.To);
  66.                 rise(statistics.Status, curInfo.Status);
  67.                
  68.                 if(curInfo.PriceInfo != undefined && curInfo.PriceInfo.ProfitParts != undefined){
  69.                     statistics.TotalFareAndTaxes += curInfo.PriceInfo.ADTBase
  70.                         + curInfo.PriceInfo.CNNBase + curInfo.INFBase
  71.                         + curInfo.PriceInfo.ADTTaxes + curInfo.CNNTaxes
  72.                         + curInfo.PriceInfo.INFTaxes;
  73.                        
  74.                     log.i(curInfo.PriceInfo);
  75.                    
  76.                     statistics.TotalAmount += parseFloat(curInfo.PriceInfo.Amount);
  77.                
  78.                     for(var j = 0; j < curInfo.PriceInfo.ProfitParts.length; j++){
  79.                         var curPart = curInfo.PriceInfo.ProfitParts[j];
  80.                         rise(statistics.ProfitsByRoles, curPart.Role, curPart.AbsAmt);
  81.                     }
  82.                 }
  83.  
  84.             }
  85.            
  86.             return [statistics];
  87.         })
  88.         .run(function(err, result){
  89.             log.i(result);
  90.         });;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement