#!/usr/bin/perl use Data::Dumper; my $lookup; $lookup; ##Maharashtra to MH & Mumbai to MUM open(FH,"<",$ARGV[0]); open(AH,"<",$ARGV[1]); open(OUT,">",$ARGV[2]); open(LOG,">",$ARGV[3]); my $SubsSize= -s $ARGV[0]; my $AccuSize= -s $ARGV[1]; my $SubsCount=0; my $AccuCount=0; my $finalCount=0; my $AccUsg; my $AccUsg1; my $AccUsg2; my $AccUsg3; while() { chomp; my $line=$_; $AccuCount++; my $MobileNumber; if( $line =~ /subscriberId:(\w+)\(\"(\d+)\"\)/ ) { $MobileNumber=$2; } my $plan=$line; $plan =~s/\\//g; my @AccVolume; if ( $plan =~ /usageControlAccum:(\w+)\(\"(.*)\"\)/ ) { my $p=$2; $p=~s/:\{/ => {/g; $p=~s/:\[/ => [/g; $p=~s/\"/\'/g; $p=~s/\':/\'=>/g; $p=~s/\}n/\}/g; #print $p,"\n"; my $e=eval($p); if ( @$ ) { push (@AccVolume,"error"); } else { foreach my $value ( @{$e->{'reportingGroups'}} ) { if ( exists ( $value->{'absoluteAccumulated'}->{'counters'} ) ) { $AccUsg->{$MobileNumber}->{$value->{'subscriberGroupName'}}=$value->{'absoluteAccumulated'}->{'counters'}->[0]->{'bidirVolume'}; $AccUsg1->{$MobileNumber}->{$value->{'subscriberGroupName'}}=$value->{'absoluteAccumulated'}->{'counters'}->[0]->{'name'}; $AccUsg2->{$MobileNumber}->{$value->{'subscriberGroupName'}}=$value->{'absoluteAccumulated'}->{'expiryDate'}->{'volume'}; $AccUsg3->{$MobileNumber}->{$value->{'subscriberGroupName'}}->{'time'}=$value->{'absoluteAccumulated'}->{'previousExpiryDate'}->{'time'}; $AccUsg3->{$MobileNumber}->{$value->{'subscriberGroupName'}}->{'volume'}=$value->{'absoluteAccumulated'}->{'previousExpiryDate'}->{'volume'}; } elsif ( exists ( $value->{'absoluteAccumulated'}->{'bidirVolume'} ) ) { $AccUsg->{$MobileNumber}->{$value->{'subscriberGroupName'}}=$value->{'absoluteAccumulated'}->{'bidirVolume'}; } } } } } close(AH); print OUT "MSISDN,IMEI,Circle,DeviceType,OPTIN,PlanType,counterName,expdate,prevTime,prevVol,PACKID1;priority;startdate;enddate;AccumulateUsage|PACKID2;priority;startdate;enddate;AccumulateUsage|PACKID3;priority;startdate;enddate;AccumulateUsage|PACKID4;priority;startdate;enddate;AccumulateUsage|\n"; while() { chomp; my $line=$_; $SubsCount++; $msisdn; my $IMEI; my $Circle; my $DeviceType; my $OPTIN; my $PlanType; my $familyId; my $trafficIds; if($line=~/userId:S(\d+)\(\"(\w+)\"\)/) { $msisdn = $2; } if ( $line=~/operatorInfo:A(\d+)\[(.*?)\]/ ) { my $opcinfo=$2; if( $opcinfo =~ /ix(\d+):S(\d+)\(\"imei:(\w*)\"\)/ ) { $IMEI=$3; } if( $opcinfo =~ /ix(\d+):S(\d+)\(\"OptInState:(\w*)\"\)/ ) { $OPTIN=$3; } if( $opcinfo =~ /ix(\d+):S(\d+)\(\"CircleId:(\w*)\"\)/ ) { $Circle=$3; if( exists ( $lookup->{$Circle} ) ) { $Circle=$lookup->{$Circle}; } } if( $opcinfo =~ /ix(\d+):S(\d+)\(\"DevType:(\w*)\"\)/ ) { $DeviceType=$3; } if( $opcinfo =~ /ix(\d+):S(\d+)\(\"PlanType:(\w*)\"\)/ ) { $PlanType=$3; } } my @ValidPlan; if($line=~/groups:A(\d+)\[(.*?)\]/) { my $plans=$2; my @AllPlans = split('ix\d+:S\d+\("',$plans); foreach my $p ( @AllPlans ) { $p =~ s/\"\)//g; if ($p eq "" ) { next; } if ( $p =~ /(\w+):(\d+)[:]?(.*)/) { $planname=$1; my $priority=$2; my $expdate=$3; $expdate =~ s/,/\;/g; if( exists ( $AccUsg->{$msisdn}->{$planname} ) ) { if ( $expdate eq "") { push(@ValidPlan,"$planname;$priority;;;$AccUsg->{$msisdn}->{$planname}"); } elsif ( length($expdate) > 19 ) { push(@ValidPlan,"$planname;$priority;$expdate;$AccUsg->{$msisdn}->{$planname}"); } else { push(@ValidPlan,"$planname;$priority;$expdate;;$AccUsg->{$msisdn}->{$planname}"); } } else { if( $expdate eq "") { push(@ValidPlan,"$planname;$priority;;;"); } else { if( length($expdate) > 19 ) { push(@ValidPlan,"$planname;$priority;$expdate;"); } else { push(@ValidPlan,"$planname;$priority;$expdate;;"); } } } } } } if ( $line=~/familyId:S(\d+)\(\"(.*?)\"\)/ ) { $familyId=$2; } if ( $line=~/trafficIds:A(\d+)\[(.*?)\]/ ) { $trafficIds=$2; } my @y = sort { ($b =~ /(.*?);(\d+);(.*?)/)[1] <=> ($a =~ /(.*?);(\d+);(.*?)/)[1] } @ValidPlan; #ankur my $printPlan=join("|",@y); $finalCount++; print OUT "$msisdn,$IMEI,$Circle,$DeviceType,$OPTIN,$PlanType,$AccUsg1->{$msisdn}->{$planname},$AccUsg2->{$msisdn}->{$planname},$AccUsg3->{$msisdn}->{$planname}->{'time'},$AccUsg3->{$msisdn}->{$planname}->{'volume'},$printPlan\n"; close(FH); close(OUT);