From d37c8f2ab58656f9fa1f231d67012c79bfb322e0 Mon Sep 17 00:00:00 2001 From: mattf Date: Thu, 3 Jul 2014 03:35:34 +0000 Subject: [PATCH] Added additional phone prefix type of V to NANPA filtering code as landline (S) git-svn-id: svn://192.168.202.10@2144 3d104415-ff17-0410-8863-d5cf3c621b8a --- bin/nanpa_type_filter.pl | 7 +++-- bin/nanpa_type_populate.pl | 60 ++++++++++++++++++++----------------- bin/nanpa_type_preload.pl | 26 +++++++++++----- www/vicidial/nanpa_type.php | 28 ++++++++++++----- 4 files changed, 76 insertions(+), 45 deletions(-) diff --git a/bin/nanpa_type_filter.pl b/bin/nanpa_type_filter.pl index abac34f7..55f9c36d 100644 --- a/bin/nanpa_type_filter.pl +++ b/bin/nanpa_type_filter.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# nanpa_type_filter.pl version 2.8 +# nanpa_type_filter.pl version 2.10 # # DESCRIPTION: # This script is designed to filter the leads in a list by phone number and @@ -14,6 +14,7 @@ # 130822-1645 - first build # 131003-1725 - Added exclude filter settings # 140501-0709 - Added include filter settings +# 140702-2252 - Added prefix phone type of V as landline # $secX = time(); @@ -426,12 +427,12 @@ while ($sthArows > $rec_count) $stmtA=''; if ($result_split[0] =~ /I/) {$invalid++;} if ($result_split[0] =~ /C/) {$cellphone++;} - if ($result_split[0] =~ /S/) {$landline++;} + if ($result_split[0] =~ /S|V/) {$landline++;} if ( ($result_split[0] =~ /I/) && (length($invalid_list_id) > 1) ) {$stmtA = "UPDATE vicidial_list SET list_id=$invalid_list_id where lead_id=$lead_ids[$temp_rec];";} if ( ($result_split[0] =~ /C/) && (length($cellphone_list_id) > 1) ) {$stmtA = "UPDATE vicidial_list SET list_id=$cellphone_list_id where lead_id=$lead_ids[$temp_rec];";} - if ( ($result_split[0] =~ /S/) && (length($landline_list_id) > 1) ) + if ( ($result_split[0] =~ /S|V/) && (length($landline_list_id) > 1) ) {$stmtA = "UPDATE vicidial_list SET list_id=$landline_list_id where lead_id=$lead_ids[$temp_rec];";} if ( (length($stmtA) > 10) && ($TEST < 1) ) { diff --git a/bin/nanpa_type_populate.pl b/bin/nanpa_type_populate.pl index b3b2a6c4..0cde2c57 100644 --- a/bin/nanpa_type_populate.pl +++ b/bin/nanpa_type_populate.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# nanpa_type_populate.pl version 2.8 +# nanpa_type_populate.pl version 2.10 # # DESCRIPTION: # This script is designed to filter the leads in a list by phone number and @@ -8,11 +8,12 @@ # # It is recommended that you run this program on the local Asterisk machine # -# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2014 Matt Florell LICENSE: AGPLv2 # # CHANGES # 130915-1345 - first build # 130928-0747 - Force overwrite of unzipped files, more standard debug output +# 140702-2319 - Added additional logging to admin log --admin-log # $PATHconf = '/etc/astguiclient.conf'; @@ -102,6 +103,7 @@ $invalid_list_id=''; $invalid=0; $cellphone=0; $landline=0; +$admin_log=0; ### begin parsing run-time options ### if (length($ARGV[0])>1) @@ -121,6 +123,7 @@ if (length($ARGV[0])>1) print " [--quiet] = supress all normal output\n"; print " [--debug] = verbose debug messages\n"; print " [--debugX] = extra verbose debug messages\n"; + print " [--admin-log] = log to vicidial_admin_log\n"; print "\n"; exit; } @@ -146,6 +149,10 @@ if (length($ARGV[0])>1) { $skip_download=1; } + if ($args =~ /--admin-log/i) + { + $admin_log=1; + } } } else @@ -257,58 +264,57 @@ if ($sthNrows > 0) if ($nanpa_wireless_to_wired_count > 0) { $stmtN = "DELETE from nanpa_wireless_to_wired;"; - $affected_rows = $dbhN->do($stmtN); - if($DB){print STDERR "|$affected_rows records deleted| nanpa_wireless_to_wired\n";} + $affected_rowsWRLSWIRE = $dbhN->do($stmtN); + if($DB){print STDERR "|$affected_rowsWRLSWIRE records deleted| nanpa_wireless_to_wired\n";} } $stmtN = "LOAD DATA LOCAL INFILE '/tmp/WIRELESS-TO-WIRELINE-NORANGE.TXT' into table nanpa_wireless_to_wired LINES terminated by '\n' (phone);"; -$affected_rows = $dbhN->do($stmtN); -if($DB){print STDERR "|$affected_rows records inserted| nanpa_wireless_to_wired\n";} +$affected_rowsINwrlswire = $dbhN->do($stmtN); +if($DB){print STDERR "|$affected_rowsINwrlswire records inserted| nanpa_wireless_to_wired\n";} if ($nanpa_wired_to_wireless_count > 0) { $stmtN = "DELETE from nanpa_wired_to_wireless;"; - $affected_rows = $dbhN->do($stmtN); - if($DB){print STDERR "|$affected_rows records deleted| nanpa_wired_to_wireless\n";} + $affected_rowsWIREWRLS = $dbhN->do($stmtN); + if($DB){print STDERR "|$affected_rowsWIREWRLS records deleted| nanpa_wired_to_wireless\n";} } $stmtN = "LOAD DATA LOCAL INFILE '/tmp/WIRELINE-TO-WIRELESS-NORANGE.TXT' into table nanpa_wired_to_wireless LINES terminated by '\n' (phone);"; -$affected_rows = $dbhN->do($stmtN); -if($DB){print STDERR "|$affected_rows records inserted| nanpa_wired_to_wireless\n";} +$affected_rowsINwirewrls = $dbhN->do($stmtN); +if($DB){print STDERR "|$affected_rowsINwirewrls records inserted| nanpa_wired_to_wireless\n";} if ($nanpa_prefix_exchanges_master_count > 0) { $stmtN = "DELETE from nanpa_prefix_exchanges_master;"; - $affected_rows = $dbhN->do($stmtN); - if($DB){print STDERR "|$affected_rows records deleted| nanpa_prefix_exchanges_master\n";} + $affected_rowsPRFXMSTR = $dbhN->do($stmtN); + if($DB){print STDERR "|$affected_rowsPRFXMSTR records deleted| nanpa_prefix_exchanges_master\n";} } $stmtN = "LOAD DATA LOCAL INFILE '/tmp/PrefixMasterList.csv' into table nanpa_prefix_exchanges_master FIELDS TERMINATED BY ',' LINES terminated by '\r\n' (areacode,prefix,source,type,tier,postal_code,new_areacode,tzcode,region);"; -$affected_rows = $dbhN->do($stmtN); -if($DB){print STDERR "|$affected_rows records inserted| nanpa_prefix_exchanges_master\n";} +$affected_rowsINprfxmstr = $dbhN->do($stmtN); +if($DB){print STDERR "|$affected_rowsINprfxmstr records inserted| nanpa_prefix_exchanges_master\n";} if ($nanpa_prefix_exchanges_fast_count > 0) { $stmtN = "DELETE from nanpa_prefix_exchanges_fast;"; - $affected_rows = $dbhN->do($stmtN); - if($DB){print STDERR "|$affected_rows records deleted| nanpa_prefix_exchanges_fast\n";} + $affected_rowsPRFXFAST = $dbhN->do($stmtN); + if($DB){print STDERR "|$affected_rowsPRFXFAST records deleted| nanpa_prefix_exchanges_fast\n";} } $stmtN = "INSERT INTO nanpa_prefix_exchanges_fast (ac_prefix,type) SELECT CONCAT(areacode,prefix),type from nanpa_prefix_exchanges_master;"; -$affected_rows = $dbhN->do($stmtN); -if($DB){print STDERR "|$affected_rows records inserted| nanpa_prefix_exchanges_fast\n";} - - -if ($DB) {print "LEADS FOUND IN LIST $list_id: |$sthArows|\n";} -if ($DBX) {print "|$stmtA|\n";} - -if ($DB) {print "STARTING LOOKUP OF NANPA PHONE TYPE, ($rec_count records)\n";} -$end_time=time; -if (!$Q) {print "Pre-scrub Elapsed time: ".($end_time-$start_time)." sec\n\n\n";} - +$affected_rowsINprfxfast = $dbhN->do($stmtN); +if($DB){print STDERR "|$affected_rowsINprfxfast records inserted| nanpa_prefix_exchanges_fast\n";} $end_time=time(); + +if ($admin_log > 0) + { + $stmtA="INSERT INTO vicidial_admin_log set event_date=NOW(), user='VDAD', ip_address='1.1.1.1', event_section='SERVERS', event_type='OTHER', record_id='$server_ip', event_code='NANPA populate data', event_sql='', event_notes='WIRED2WIRELESS($nanpa_wired_to_wireless_count / $affected_rowsWIREWRLS / $affected_rowsINwirewrls) WIRELESS2WIRED($nanpa_wireless_to_wired_count / $affected_rowsWRLSWIRE / $affected_rowsINwrlswire) PREFIX($nanpa_prefix_exchanges_master_count / $nanpa_prefix_exchanges_fast_count / $affected_rowsPRFXMSTR / $affected_rowsINprfxmstr / $affected_rowsPRFXFAST / $affected_rowsINprfxfast) |$args| TOTAL Elapsed time: ".($end_time-$start_time)." sec';"; + $Iaffected_rows = $dbhN->do($stmtA); + if ($DBX) {print "Admin logged: |$Iaffected_rows|$stmtA|\n";} + } + if (!$Q) {print "TOTAL Elapsed time: ".($end_time-$start_time)." sec\n\n";} diff --git a/bin/nanpa_type_preload.pl b/bin/nanpa_type_preload.pl index b40e06d3..fb9e45f4 100644 --- a/bin/nanpa_type_preload.pl +++ b/bin/nanpa_type_preload.pl @@ -8,12 +8,13 @@ # # It is recommended that you run this program on the local Asterisk machine # -# Copyright (C) 2013 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2014 Matt Florell LICENSE: AGPLv2 # # CHANGES # 130914-1710 - first build # 131003-1743 - Added exclude filter settings # 140624-1551 - Added more options to segment leads +# 140702-2242 - Added prefix phone type of V as landline(S) # $PATHconf = '/etc/astguiclient.conf'; @@ -398,7 +399,7 @@ while ($sthArows > $rec_count) $pre7=substr($phones[$rec_count],0,7); if ($four_digit_prefix_hash{$pre4}) { - if ($four_digit_prefix_hash{$pre4} ne "S") + if ( ($four_digit_prefix_hash{$pre4} ne "S") && ($four_digit_prefix_hash{$pre4} ne "V") ) { $type="C"; Wireless_to_Wired($phones[$rec_count]); @@ -411,7 +412,7 @@ while ($sthArows > $rec_count) } elsif ($five_digit_prefix_hash{$pre5}) { - if ($five_digit_prefix_hash{$pre5} ne "S") + if ( ($five_digit_prefix_hash{$pre5} ne "S") && ($five_digit_prefix_hash{$pre5} ne "V") ) { $type="C"; Wireless_to_Wired($phones[$rec_count]); @@ -424,7 +425,7 @@ while ($sthArows > $rec_count) } elsif ($six_digit_prefix_hash{$pre6}) { - if ($six_digit_prefix_hash{$pre6} ne "S") + if ( ($six_digit_prefix_hash{$pre6} ne "S") && ($six_digit_prefix_hash{$pre6} ne "V") ) { $type="C"; Wireless_to_Wired($phones[$rec_count]); @@ -437,7 +438,7 @@ while ($sthArows > $rec_count) } elsif ($seven_digit_prefix_hash{$pre7}) { - if ($seven_digit_prefix_hash{$pre7} ne "S") + if ( ($seven_digit_prefix_hash{$pre7} ne "S") && ($seven_digit_prefix_hash{$pre7} ne "V") ) { $type="C"; Wireless_to_Wired($phones[$rec_count]); @@ -462,7 +463,7 @@ while ($sthArows > $rec_count) {$stmtA = "UPDATE vicidial_list SET list_id=$invalid_list_id where lead_id in ($type_hash{$type});";} if ( ($type =~ /C/) && (length($cellphone_list_id) > 1) ) {$stmtA = "UPDATE vicidial_list SET list_id=$cellphone_list_id where lead_id in ($type_hash{$type});";} - if ( ($type =~ /S/) && (length($landline_list_id) > 1) ) + if ( ($type =~ /S|V/) && (length($landline_list_id) > 1) ) {$stmtA = "UPDATE vicidial_list SET list_id=$landline_list_id where lead_id in ($type_hash{$type});";} if (length($stmtA)>0) { @@ -485,7 +486,11 @@ while ($sthArows > $rec_count) } ################################################## + if ($type='S') {$landline++;} + if ($type='C') {$cellphone++;} + if ($type='I') {$invalid++;} $rec_count++; + if ( ($rec_count =~ /00000$/i) && ($DB) ) {print STDERR "$rec_count / $sthArows (S:$landline | C:$cellphone | I:$invalid)\n";} } #### Update remaining leads to the appropriate type ##### @@ -501,7 +506,7 @@ foreach $type (keys %type_hash) {$stmtA = "UPDATE vicidial_list SET list_id=$invalid_list_id where lead_id in ($type_hash{$type});";} if ( ($type =~ /C/) && (length($cellphone_list_id) > 1) ) {$stmtA = "UPDATE vicidial_list SET list_id=$cellphone_list_id where lead_id in ($type_hash{$type});";} - if ( ($type =~ /S/) && (length($landline_list_id) > 1) ) + if ( ($type =~ /S|V/) && (length($landline_list_id) > 1) ) {$stmtA = "UPDATE vicidial_list SET list_id=$landline_list_id where lead_id in ($type_hash{$type});";} if (length($stmtA)>0) { @@ -526,8 +531,15 @@ foreach $type (keys %type_hash) ######################################################### $end_time=time; + +$stmtA="INSERT INTO vicidial_admin_log set event_date=NOW(), user='VDAD', ip_address='1.1.1.1', event_section='SERVERS', event_type='OTHER', record_id='$server_ip', event_code='NANPA preload filter run', event_sql='', event_notes='$rec_count / $sthArows (S:$landline | C:$cellphone | I:$invalid) TOTAL Elapsed time: ".($end_time-$start_time)." sec |$args|';"; +$Iaffected_rows = $dbhA->do($stmtA); +if ($DBX) {print "Admin logged: |$Iaffected_rows|$stmtA|\n";} + +if (!$Q) {print STDERR "$rec_count / $sthArows (S:$landline | C:$cellphone | I:$invalid)\n";} if (!$Q) {print "TOTAL Elapsed time: ".($end_time-$start_time)." sec\n\n";} + ### sub Wired_to_Wireless { $phone=$_[0]; diff --git a/www/vicidial/nanpa_type.php b/www/vicidial/nanpa_type.php index 2f500ff7..22ea228c 100644 --- a/www/vicidial/nanpa_type.php +++ b/www/vicidial/nanpa_type.php @@ -1,7 +1,7 @@ LICENSE: AGPLv2 +# Copyright (C) 2014 Matt Florell LICENSE: AGPLv2 # # This script is designed to work with the NANPA exchange(NPA-NXX-X) data and # the wireless-to-wired and wired-to-wireless number portability data from @@ -28,10 +28,11 @@ # # CHANGELOG: # 130822-1433 - First build of script +# 140702-2251 - Added prefix phone type of V as landline # -$version = '2.8-1'; -$build = '130822-1433'; +$version = '2.10-2'; +$build = '140702-2251'; $startMS = microtime(); @@ -205,26 +206,37 @@ else { $row=mysqli_fetch_row($rslt); $type = $row[0]; + if ($type == 'V') + { + $type='S'; + if ($DB>0) {echo "DEBUG: prefix match type V changing to type S landline |$numbers[$i]| - $stmt\n";} + } if ($type != 'S') { - $type='C'; $stmt="SELECT count(*) from nanpa_wireless_to_wired where phone='$numbers[$i]';"; - if ($DB>0) {echo "DEBUG: wireless_to_wired lookup query |$numbers[$i]| - $stmt\n";} + if ($DB>0) {echo "DEBUG: wireless_to_wired lookup query |$numbers[$i]|$type| - $stmt\n";} $rslt=mysqli_query($link, $stmt); $row=mysqli_fetch_row($rslt); + $type='C'; if ($row[0] > 0) - {$type='S';} + { + $type='S'; + if ($DB>0) {echo "DEBUG: wireless_to_wired lookup match |$numbers[$i]|$type| - $stmt\n";} + } } else { $stmt="SELECT count(*) from nanpa_wired_to_wireless where phone='$numbers[$i]';"; - if ($DB>0) {echo "DEBUG: wired_to_wireless lookup query |$numbers[$i]| - $stmt\n";} + if ($DB>0) {echo "DEBUG: wired_to_wireless lookup query |$numbers[$i]|$type| - $stmt\n";} $rslt=mysqli_query($link, $stmt); $row=mysqli_fetch_row($rslt); if ($row[0] > 0) - {$type='C';} + { + $type='C'; + if ($DB>0) {echo "DEBUG: wired_to_wireless lookup match |$numbers[$i]|$type| - $stmt\n";} + } } } else