Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- storage.client
- .add('reserv')
- .map(function(v, keydata, args){
- if( v.values ){
- var ret = [];
- var o = Riak.mapValuesJson(v)[0];
- if(o.DateCreated){
- ret.push(o);
- }
- return ret;
- }
- return [];
- })
- .reduce(function(v, args){
- var statistics = {
- OrderCount: 0,
- PNRCount: 0,
- SegmentsCount: 0,
- PNRToSegments: { },
- PNRToPlatingCarriers: { },
- StartPoints: { },
- EndPoints: { },
- Status: { },
- TotalFareAndTaxes: 0,
- TotalAmount: 0,
- ProfitsByRoles: { }
- }
- function rise(hash, field, value){
- if(!field){
- return;
- }
- if(!hash[field]){
- hash[field] = 0;
- }
- if( value ){
- hash[field] += value;
- }
- else{
- ++hash[field];
- }
- }
- var v = result;
- for(var i = 0; i < v.length; i++){
- var curInfo = v[i];
- if( curInfo.Trips == undefined ){
- continue;
- }
- var firstTrip = curInfo.Trips[0];
- var lastTrip = curInfo.Trips[curInfo.Trips.length - 1];
- statistics.PNRCount++;
- statistics.SegmentsCount += curInfo.Trips.length;
- rise(statistics.PNRToSegments, curInfo.Trips.length);
- rise(statistics.PNRToPlatingCarriers, firstTrip.AirCompany);
- rise(statistics.StartPoints, firstTrip.From);
- rise(statistics.EndPoints, lastTrip.To);
- rise(statistics.Status, curInfo.Status);
- if(curInfo.PriceInfo != undefined && curInfo.PriceInfo.ProfitParts != undefined){
- statistics.TotalFareAndTaxes += curInfo.PriceInfo.ADTBase
- + curInfo.PriceInfo.CNNBase + curInfo.INFBase
- + curInfo.PriceInfo.ADTTaxes + curInfo.CNNTaxes
- + curInfo.PriceInfo.INFTaxes;
- log.i(curInfo.PriceInfo);
- statistics.TotalAmount += parseFloat(curInfo.PriceInfo.Amount);
- for(var j = 0; j < curInfo.PriceInfo.ProfitParts.length; j++){
- var curPart = curInfo.PriceInfo.ProfitParts[j];
- rise(statistics.ProfitsByRoles, curPart.Role, curPart.AbsAmt);
- }
- }
- }
- return [statistics];
- })
- .run(function(err, result){
- log.i(result);
- });;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement