From 50dd55dcd31bafead567b9242ca07c790b4a61de Mon Sep 17 00:00:00 2001 From: mattf Date: Wed, 26 Jul 2017 13:30:36 +0000 Subject: [PATCH] Added counter variable to HTTP Agent Push events Added caching of hourly log totals for AST_VDadapt.pl script git-svn-id: svn://192.168.202.10@2797 3d104415-ff17-0410-8863-d5cf3c621b8a --- bin/ADMIN_keepalive_ALL.pl | 51 +- bin/AST_VDadapt.pl | 1147 +++++++++++++++++++++++++--- docs/AGENT_EVENTS_PUSH.txt | 6 +- extras/MySQL_AST_CREATE_tables.sql | 30 +- extras/upgrade_2.14.sql | 30 + extras/vdc_call_url_test.php | 9 +- www/agc/vicidial.php | 125 +-- www/vicidial/help.php | 2 +- 8 files changed, 1208 insertions(+), 192 deletions(-) diff --git a/bin/ADMIN_keepalive_ALL.pl b/bin/ADMIN_keepalive_ALL.pl index f28dc8ec..446d3a82 100644 --- a/bin/ADMIN_keepalive_ALL.pl +++ b/bin/ADMIN_keepalive_ALL.pl @@ -120,9 +120,10 @@ # 170513-1728 - Added alternative uptime counter in seconds # 170609-1601 - If phone entry fullname and cidnumber are empty, don't populate a callerid conf line # 170711-0824 - Fixed help documentation for delay seconds, issue #1025 +# 170725-0017 - Added vicidial_campaign_hour_counts and vicidial_carrier_hour_counts rolling # -$build = '170711-0824'; +$build = '170725-0017'; $DB=0; # Debug flag $teodDB=0; # flag to log Timeclock End of Day processes to log file @@ -147,6 +148,7 @@ if ($hour < 10) {$hour = "0$hour";} if ($min < 10) {$min = "0$min";} if ($sec < 10) {$sec = "0$sec";} $now_date = "$year-$mon-$mday $hour:$min:$sec"; +$today_start = "$year-$mon-$mday 00:00:00"; $reset_test = "$hour$min"; ### calculate the date and time for slightly less than 24 hours ago @@ -174,6 +176,7 @@ if ($RMhour < 10) {$RMhour = "0$RMhour";} if ($RMmin < 10) {$RMmin = "0$RMmin";} if ($RMsec < 10) {$RMsec = "0$RMsec";} $RMSQLdate = "$RMyear-$RMmon-$RMmday $RMhour:$RMmin:$RMsec"; +$yesterday_start = "$RMyear-$RMmon-$RMmday 00:00:00"; $RMdate = "$RMyear-$RMmon-$RMmday"; ### calculate the date and time for 7 days ago @@ -1243,6 +1246,52 @@ if ($timeclock_end_of_day_NOW > 0) if($DB){print STDERR "\n|$affected_rows Holidays set to expired|\n";} if ($teodDB) {$event_string = "Holidays set to expired($RMdate): $affected_rows"; &teod_logger;} + # roll campaign hour stats + if (!$Q) {print "\nProcessing vicidial_campaign_hour_counts table...\n";} + $stmtA = "INSERT IGNORE INTO vicidial_campaign_hour_counts_archive SELECT * from vicidial_campaign_hour_counts where date_hour < '$today_start';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into vicidial_campaign_hour_counts_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + $stmtA = "DELETE FROM vicidial_campaign_hour_counts WHERE date_hour < '$today_start';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_campaign_hour_counts table \n";} + + $stmtA = "optimize table vicidial_campaign_hour_counts;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + + # roll vicidial_carrier_hour_counts + if (!$Q) {print "\nProcessing vicidial_carrier_hour_counts table...\n";} + $stmtA = "INSERT IGNORE INTO vicidial_carrier_hour_counts_archive SELECT * from vicidial_carrier_hour_counts where date_hour < '$today_start';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into vicidial_carrier_hour_counts_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + $stmtA = "DELETE FROM vicidial_carrier_hour_counts WHERE date_hour < '$yesterday_start';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_carrier_hour_counts table \n";} + + $stmtA = "optimize table vicidial_carrier_hour_counts;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + ##### BEGIN max stats end of day process ##### # set OPEN max stats records to CLOSING for processing diff --git a/bin/AST_VDadapt.pl b/bin/AST_VDadapt.pl index bc1d483e..61f308ee 100644 --- a/bin/AST_VDadapt.pl +++ b/bin/AST_VDadapt.pl @@ -1,12 +1,12 @@ #!/usr/bin/perl # -# AST_VDadapt.pl version 2.12 +# AST_VDadapt.pl version 2.14 # # DESCRIPTION: # adjusts the auto_dial_level for vicidial adaptive-predictive campaigns. # gather call stats for campaigns and in-groups # -# Copyright (C) 2016 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2017 Matt Florell LICENSE: AGPLv2 # # CHANGELOG # 60823-1302 - First build from AST_VDhopper.pl @@ -44,6 +44,7 @@ # 151124-1235 - Added function to cache carrier log stats # 160515-2016 - Added code for new UK OFCOM drop calculations # 161102-1029 - Fixed QM partition problem +# 170724-2352 - Added option for cached hour counts for vicidial_log entries per campaign and carrier log totals # # constants @@ -51,6 +52,7 @@ $DB=0; # Debug flag, set to 0 for no debug messages, On an active system this w $US='__'; $MT[0]=''; $run_check=1; # concurrency check +$VLhour_counts=1; # use cached hour counts for vicidial_log entries per campaign ##### table definitions(used to force index usage for better performance): $vicidial_log = 'vicidial_log FORCE INDEX (call_date) '; @@ -738,7 +740,7 @@ sub get_time_now if ($sec < 10) {$sec = "0$sec";} $file_date = "$year-$mon-$mday"; $now_date = "$year-$mon-$mday $hour:$min:$sec"; - $VDL_date = "$year-$mon-$mday 00:00:01"; + $VDL_date = "$year-$mon-$mday 00:00:00"; $current_hourmin = "$hour$min"; ### get date-time of one hour ago ### @@ -1066,114 +1068,790 @@ sub calculate_drops $sthA->finish(); } - # TODAY CALL AND DROP STATS - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ########## TODAY CALL, ANSWERED, MACHINE, AGENT AND DROP STATS ########## + ### BEGIN TODAY TOTAL CALLS + + ## BEGIN CACHED HOURLY ANALYSIS: CALLS + if ($VLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $VCScalls_today[$i] = $aryA[0]; + $secH = time(); + ($HRsec,$HRmin,$HRhour,$HRmday,$HRmon,$HRyear,$HRwday,$HRyday,$HRisdst) = localtime(time); + $HRyear = ($HRyear + 1900); + $HRmon++; + $HRhour_test = $HRhour; + if ($HRmon < 10) {$HRmon = "0$HRmon";} + if ($HRmday < 10) {$HRmday = "0$HRmday";} + if ($HRhour < 10) {$HRhour = "0$HRhour";} + $VL_today = "$HRyear-$HRmon-$HRmday"; + $VL_current_hour_date = "$HRyear-$HRmon-$HRmday $HRhour:00:00"; + $VL_day_start_date = "$HRyear-$HRmon-$HRmday 00:00:00"; + $VL_current_hour_calls=0; + + ### get date-time of start of next hour ### + $VL_next_hour = ($secH + (60 * 60)); + ($NHsec,$NHmin,$NHhour,$NHmday,$NHmon,$NHyear,$NHwday,$NHyday,$NHisdst) = localtime($VL_next_hour); + $NHyear = ($NHyear + 1900); + $NHmon++; + if ($NHmon < 10) {$NHmon = "0$NHmon";} + if ($NHmday < 10) {$NHmday = "0$NHmday";} + $VL_next_hour_date = "$NHyear-$NHmon-$NHmday $NHhour:00:00"; + + if ($DBX > 1) {print "STARTING CACHED HOURLY TOTAL CALLS: |$VL_current_hour_date|$VL_next_hour_date|\n";} + + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_current_hour_date';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CURRENT HOUR CALLS: |$sthArows|$VL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_current_hour_date',type='CALLS',next_hour='$VL_next_hour_date',last_update=NOW(),calls='$VL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='CALLS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='CALLS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $VCScalls_today[$i] = ($VCHC_cache_calls + $VL_current_hour_calls); + if ($DBX) {print "VCHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($VCScalls_today[$i])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='CALLS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $VCScalls_today[$i] = ($VCScalls_today[$i] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$VCScalls_today[$i]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_today $j:00:00' and call_date < '$VL_today $j_next:00:00';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_this_hour_calls = $aryA[0]; + $VCScalls_today[$i] = ($VCScalls_today[$i] + $VL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR QUERY: |$sthArows|$VL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_today $j:00:00',type='CALLS',next_hour='$VL_today $j_next:00:00',last_update=NOW(),calls='$VL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $VCScalls_today[$i] = ($VCScalls_today[$i] + $VL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $VCScalls_today[$i] = $VL_current_hour_calls; + if ($DBX) {print "VCHC MIDNIGHT HOUR: |$VCScalls_today[$i]|\n";} + } } - $sthA->finish(); + ## END CACHED HOURLY ANALYSIS: CALLS + else + { + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VDL_date';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCScalls_today[$i] = $aryA[0]; + } + $sthA->finish(); + } + ### END TODAY TOTAL CALLS if ($VCScalls_today[$i] > 0) { # TODAY ANSWERS - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date' and status IN($camp_ANS_STAT_SQL);"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) + ## BEGIN CACHED HOURLY ANALYSIS: ANSWERS + if ($VLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $VCSanswers_today[$i] = $aryA[0]; - } - $sthA->finish(); - - # TODAY ANSWERING MACHINES CODED BY AGENTS FOR UK OFCOM CALCULATION - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date' and status IN($camp_AM_STAT_SQL) and user != 'VDAD';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $VCSam_today[$i] = $aryA[0]; - } - $sthA->finish(); - - # TODAY AGENT HANDLED ANSWERED CALLS FOR UK OFCOM CALCULATION - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date' and status IN($camp_ANS_STAT_SQL) and user != 'VDAD';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $VCSagenthandled_today[$i] = $aryA[0]; - } - $sthA->finish(); - - # TODAY DROPS - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date' and status IN('DROP','XDROP');"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - if ($DBX > 0) {print "$stmtA\n";} - $sthArows=$sthA->rows; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $VCSdrops_today[$i] = $aryA[0]; - $temp_raw_drop = $VCSdrops_today[$i]; - if ($VCSdrops_today[$i] > 0) + $VL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_current_hour_date' and status IN($camp_ANS_STAT_SQL);"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) { - if ( ($SSofcom_uk_drop_calc > 0) && ($ofcom_uk_drop_calc[$i] =~ /Y/) ) + @aryA = $sthA->fetchrow_array; + $VL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CURRENT HOUR CALLS ANSWERS: |$sthArows|$VL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_current_hour_date',type='ANSWERS',next_hour='$VL_next_hour_date',last_update=NOW(),calls='$VL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='ANSWERS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) { - $ofcom_uk_drop_calc_ANY++; + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} - $debug_camp_output .= "UK OFCOM DROP CALCULATION TRIGGERED FOR THIS CAMPAIGN: ($SSofcom_uk_drop_calc|$ofcom_uk_drop_calc[$i]|$ofcom_uk_drop_calc_ANY)\n"; - if ($DBX) {print "UK OFCOM DROP CALCULATION TRIGGERED FOR THIS CAMPAIGN: ($SSofcom_uk_drop_calc|$ofcom_uk_drop_calc[$i]|$ofcom_uk_drop_calc_ANY)\n";} - - # As of December 2015, OFCOM in the UK changed their method for calculating - # the drop(or abandon) percentage for an outbound dialing campaign. The new - # formula is to estimate the number of drops that were answering machines. - # They do this by using the agent-answered percentage of answering machines - # and subtracting that percentage from the number of drops. Then that new - # drop number is divided by the total agent-answered human-answered calls - # PLUS the number of drops. This differs in several ways from the way it had - # been done, as well as the way the drop percentage has been calculated in - # the USA and Canada. This new UK drop calculation method is activated as a - # system setting AND a campaign option. Both must be enabled for the campaign - # to use the new method. You will see code similar to the section below for - # each time period that the drop percentage is calculated. In order for agent- - # statused answering machines to be calculated properly, we have added an - # answering machine status flag that is used to gather those statuses. - - if ($VCSam_today[$i] > 0) + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='ANSWERS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) { - $temp_am_pct = ($VCSam_today[$i] / ($VCSagenthandled_today[$i] + $VCSam_today[$i]) ); - $temp_am_drops = ($VCSdrops_today[$i] * $temp_am_pct); - $VCSdrops_today[$i] = ($VCSdrops_today[$i] - $temp_am_drops); + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; } - $VCSdrops_today[$i] = sprintf("%.3f", $VCSdrops_today[$i]); - $temp_answers_today = ($VCSagenthandled_today[$i] + $VCSdrops_today[$i]); - if ($temp_answers_today < 1) {$temp_answers_today = 1;} - $VCSdrops_answers_today_pct[$i] = ( ($VCSdrops_today[$i] / $temp_answers_today) * 100 ); - $VCSdrops_answers_today_pct[$i] = sprintf("%.2f", $VCSdrops_answers_today_pct[$i]); + $sthA->finish(); + $VCSanswers_today[$i] = ($VCHC_cache_calls + $VL_current_hour_calls); + if ($DBX) {print "VCHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($VCSanswers_today[$i])|$stmtA|\n";} } else { - if ($VCSanswers_today[$i] < 1) {$VCSanswers_today[$i] = 1;} - $VCSdrops_answers_today_pct[$i] = ( ($VCSdrops_today[$i] / $VCSanswers_today[$i]) * 100 ); - $VCSdrops_answers_today_pct[$i] = sprintf("%.2f", $VCSdrops_answers_today_pct[$i]); + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='ANSWERS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $VCSanswers_today[$i] = ($VCSanswers_today[$i] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$VCSanswers_today[$i]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_today $j:00:00' and call_date < '$VL_today $j_next:00:00' and status IN($camp_ANS_STAT_SQL);"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_this_hour_calls = $aryA[0]; + $VCSanswers_today[$i] = ($VCSanswers_today[$i] + $VL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR QUERY: |$sthArows|$VL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_today $j:00:00',type='ANSWERS',next_hour='$VL_today $j_next:00:00',last_update=NOW(),calls='$VL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $VCSanswers_today[$i] = ($VCSanswers_today[$i] + $VL_current_hour_calls); } - $VCSdrops_today_pct[$i] = ( ($VCSdrops_today[$i] / $VCScalls_today[$i]) * 100 ); - $VCSdrops_today_pct[$i] = sprintf("%.2f", $VCSdrops_today_pct[$i]); + } + else + { + # midnight hour, so total is only current hour stats + $VCSanswers_today[$i] = $VL_current_hour_calls; + if ($DBX) {print "VCHC MIDNIGHT HOUR: |$VCSanswers_today[$i]|\n";} } } - $sthA->finish(); + ## END CACHED HOURLY ANALYSIS: ANSWERS + else + { + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VDL_date' and status IN($camp_ANS_STAT_SQL);"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCSanswers_today[$i] = $aryA[0]; + } + $sthA->finish(); + } + + # TODAY ANSWERING MACHINES CODED BY AGENTS FOR UK OFCOM CALCULATION + ## BEGIN CACHED HOURLY ANALYSIS: MACHINES + if ($VLhour_counts > 0) + { + $VL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_current_hour_date' and status IN($camp_AM_STAT_SQL) and user != 'VDAD';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CURRENT HOUR CALLS MACHINES: |$sthArows|$VL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_current_hour_date',type='MACHINES',next_hour='$VL_next_hour_date',last_update=NOW(),calls='$VL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='MACHINES' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='MACHINES' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $VCSam_today[$i] = ($VCHC_cache_calls + $VL_current_hour_calls); + if ($DBX) {print "VCHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($VCSam_today[$i])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='MACHINES' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $VCSam_today[$i] = ($VCSam_today[$i] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$VCSam_today[$i]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_today $j:00:00' and call_date < '$VL_today $j_next:00:00' and status IN($camp_AM_STAT_SQL) and user != 'VDAD';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_this_hour_calls = $aryA[0]; + $VCSam_today[$i] = ($VCSam_today[$i] + $VL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR QUERY: |$sthArows|$VL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_today $j:00:00',type='MACHINES',next_hour='$VL_today $j_next:00:00',last_update=NOW(),calls='$VL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $VCSam_today[$i] = ($VCSam_today[$i] + $VL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $VCSam_today[$i] = $VL_current_hour_calls; + if ($DBX) {print "VCHC MIDNIGHT HOUR: |$VCSam_today[$i]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: MACHINES + else + { + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VDL_date' and status IN($camp_AM_STAT_SQL) and user != 'VDAD';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCSam_today[$i] = $aryA[0]; + } + $sthA->finish(); + } + + # TODAY AGENT HANDLED ANSWERED CALLS FOR UK OFCOM CALCULATION + ## BEGIN CACHED HOURLY ANALYSIS: AGENTS + if ($VLhour_counts > 0) + { + $VL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_current_hour_date' and status IN($camp_ANS_STAT_SQL) and user != 'VDAD';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CURRENT HOUR CALLS AGENTS: |$sthArows|$VL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_current_hour_date',type='AGENTS',next_hour='$VL_next_hour_date',last_update=NOW(),calls='$VL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='AGENTS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='AGENTS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $VCSagenthandled_today[$i] = ($VCHC_cache_calls + $VL_current_hour_calls); + if ($DBX) {print "VCHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($VCSagenthandled_today[$i])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='AGENTS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $VCSagenthandled_today[$i] = ($VCSagenthandled_today[$i] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$VCSagenthandled_today[$i]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_today $j:00:00' and call_date < '$VL_today $j_next:00:00' and status IN($camp_ANS_STAT_SQL) and user != 'VDAD';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_this_hour_calls = $aryA[0]; + $VCSagenthandled_today[$i] = ($VCSagenthandled_today[$i] + $VL_this_hour_calls); + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR QUERY: |$sthArows|$VL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_today $j:00:00',type='AGENTS',next_hour='$VL_today $j_next:00:00',last_update=NOW(),calls='$VL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $VCSagenthandled_today[$i] = ($VCSagenthandled_today[$i] + $VL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $VCSagenthandled_today[$i] = $VL_current_hour_calls; + if ($DBX) {print "VCHC MIDNIGHT HOUR: |$VCSagenthandled_today[$i]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: AGENTS + else + { + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VDL_date' and status IN($camp_ANS_STAT_SQL) and user != 'VDAD';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCSagenthandled_today[$i] = $aryA[0]; + } + $sthA->finish(); + } + + # TODAY DROPS + ## BEGIN CACHED HOURLY ANALYSIS: DROPS + if ($VLhour_counts > 0) + { + $VL_current_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_current_hour_date' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_current_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CURRENT HOUR CALLS DROPS: |$sthArows|$VL_current_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_current_hour_date',type='DROPS',next_hour='$VL_next_hour_date',last_update=NOW(),calls='$VL_current_hour_calls',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_current_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + + if ($HRhour_test > 0) + { + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(*) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='DROPS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR CHECK: |$sthArows|$VCHC_entry_count|$stmtA|\n";} + + # if cached totals equal the number of hours, then run single query to get sums of calls, if not, go hour-by-hour + if ($VCHC_entry_count >= $HRhour_test) + { + $VCHC_cache_calls=0; + $stmtA = "SELECT sum(calls) from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='DROPS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCHC_cache_calls = $aryA[0]; + } + $sthA->finish(); + $VCSdrops_today[$i] = ($VCHC_cache_calls + $VL_current_hour_calls); + if ($DBX) {print "VCHC CACHED HOUR SINGLE QUERY: |$sthArows|$VCHC_cache_calls($VCSdrops_today[$i])|$stmtA|\n";} + } + else + { + @VCHC_hour=@MT; + @VCHC_date_hour=@MT; + @VCHC_next_hour=@MT; + @VCHC_last_update=@MT; + @VCHC_calls=@MT; + $stmtA = "SELECT hr,date_hour,next_hour,last_update,calls from vicidial_campaign_hour_counts where campaign_id='$campaign_id[$i]' and type='DROPS' and date_hour >= '$VL_day_start_date' and date_hour < '$VL_current_hour_date' and last_update > next_hour order by hr;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows_hr=$sthA->rows; + $j=0; + while ($sthArows_hr > $j) + { + @aryA = $sthA->fetchrow_array; + $VCHC_hour[$j] = $aryA[0]; + $VCHC_date_hour[$j] = $aryA[1]; + $VCHC_next_hour[$j] = $aryA[2]; + $VCHC_last_update[$j] = $aryA[3]; + $VCHC_calls[$j] = $aryA[4]; + $j++; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR LIST QUERY: |$sthArows_hr|$stmtA|\n";} + + $j=0; + while ($j < $HRhour_test) + { + $k=0; + $cache_hour_found=0; + while ($sthArows_hr > $k) + { + if ( ($VCHC_hour[$k] == $j) || ($VCHC_hour[$j] eq "$j") ) + { + $VCSdrops_today[$i] = ($VCSdrops_today[$i] + $VCHC_calls[$k]); + $cache_hour_found++; + if ($DBX) {print "VCHC CACHED HOUR FOUND: |$VCHC_hour[$k]|$j|$k|$VCSdrops_today[$i]|\n";} + } + $k++; + } + if ($cache_hour_found < 1) + { + $j_next = ($j + 1); + $VL_this_hour_calls=0; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VL_today $j:00:00' and call_date < '$VL_today $j_next:00:00' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VL_this_hour_calls = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCHC CACHED HOUR QUERY: |$sthArows|$VL_this_hour_calls|$stmtA|\n";} + + $stmtA="INSERT IGNORE INTO vicidial_campaign_hour_counts SET campaign_id='$campaign_id[$i]',date_hour='$VL_today $j:00:00',type='DROPS',next_hour='$VL_today $j_next:00:00',last_update=NOW(),calls='$VL_this_hour_calls',hr='$j' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$VL_this_hour_calls';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCHC STATS INSERT/UPDATE HOUR|$j|$affected_rows|$stmtA|\n";} + } + $j++; + } + $VCSdrops_today[$i] = ($VCSdrops_today[$i] + $VL_current_hour_calls); + } + } + else + { + # midnight hour, so total is only current hour stats + $VCSdrops_today[$i] = $VL_current_hour_calls; + if ($DBX) {print "VCHC MIDNIGHT HOUR: |$VCSdrops_today[$i]|\n";} + } + } + ## END CACHED HOURLY ANALYSIS: DROPS + else + { + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VDL_date' and status IN('DROP','XDROP');"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + if ($DBX > 0) {print "$stmtA\n";} + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCSdrops_today[$i] = $aryA[0]; + } + $sthA->finish(); + } + + if ($VCSdrops_today[$i] > 0) + { + $temp_raw_drop = $VCSdrops_today[$i]; + if ( ($SSofcom_uk_drop_calc > 0) && ($ofcom_uk_drop_calc[$i] =~ /Y/) ) + { + $ofcom_uk_drop_calc_ANY++; + + $debug_camp_output .= "UK OFCOM DROP CALCULATION TRIGGERED FOR THIS CAMPAIGN: ($SSofcom_uk_drop_calc|$ofcom_uk_drop_calc[$i]|$ofcom_uk_drop_calc_ANY)\n"; + if ($DBX) {print "UK OFCOM DROP CALCULATION TRIGGERED FOR THIS CAMPAIGN: ($SSofcom_uk_drop_calc|$ofcom_uk_drop_calc[$i]|$ofcom_uk_drop_calc_ANY)\n";} + + # As of December 2015, OFCOM in the UK changed their method for calculating + # the drop(or abandon) percentage for an outbound dialing campaign. The new + # formula is to estimate the number of drops that were answering machines. + # They do this by using the agent-answered percentage of answering machines + # and subtracting that percentage from the number of drops. Then that new + # drop number is divided by the total agent-answered human-answered calls + # PLUS the number of drops. This differs in several ways from the way it had + # been done, as well as the way the drop percentage has been calculated in + # the USA and Canada. This new UK drop calculation method is activated as a + # system setting AND a campaign option. Both must be enabled for the campaign + # to use the new method. You will see code similar to the section below for + # each time period that the drop percentage is calculated. In order for agent- + # statused answering machines to be calculated properly, we have added an + # answering machine status flag that is used to gather those statuses. + + if ($VCSam_today[$i] > 0) + { + $temp_am_pct = ($VCSam_today[$i] / ($VCSagenthandled_today[$i] + $VCSam_today[$i]) ); + $temp_am_drops = ($VCSdrops_today[$i] * $temp_am_pct); + $VCSdrops_today[$i] = ($VCSdrops_today[$i] - $temp_am_drops); + } + $VCSdrops_today[$i] = sprintf("%.3f", $VCSdrops_today[$i]); + $temp_answers_today = ($VCSagenthandled_today[$i] + $VCSdrops_today[$i]); + if ($temp_answers_today < 1) {$temp_answers_today = 1;} + $VCSdrops_answers_today_pct[$i] = ( ($VCSdrops_today[$i] / $temp_answers_today) * 100 ); + $VCSdrops_answers_today_pct[$i] = sprintf("%.2f", $VCSdrops_answers_today_pct[$i]); + } + else + { + if ($VCSanswers_today[$i] < 1) {$VCSanswers_today[$i] = 1;} + $VCSdrops_answers_today_pct[$i] = ( ($VCSdrops_today[$i] / $VCSanswers_today[$i]) * 100 ); + $VCSdrops_answers_today_pct[$i] = sprintf("%.2f", $VCSdrops_answers_today_pct[$i]); + } + $VCSdrops_today_pct[$i] = ( ($VCSdrops_today[$i] / $VCScalls_today[$i]) * 100 ); + $VCSdrops_today_pct[$i] = sprintf("%.2f", $VCSdrops_today_pct[$i]); + } $debug_camp_output .= " CALLS: $VCScalls_today[$i] ANSWERs: $VCSanswers_today[$i] AGENT-ANS: $VCSagenthandled_today[$i] AGENT-AMs: $VCSam_today[$i] DROPs: $VCSdrops_today[$i]($temp_raw_drop) DROP-TOT PCT: $VCSdrops_today_pct[$i] DROP-ANS PCT: $VCSdrops_answers_today_pct[$i]\n"; if ($DBX) {print " CALLS: $VCScalls_today[$i] ANSWERs: $VCSanswers_today[$i] AGENT-ANS: $VCSagenthandled_today[$i] AGENT-AMs: $VCSam_today[$i] DROPs: $VCSdrops_today[$i]($temp_raw_drop) DROP-TOT PCT: $VCSdrops_today_pct[$i] DROP-ANS PCT: $VCSdrops_answers_today_pct[$i]\n";} @@ -1368,7 +2046,7 @@ sub calculate_drops if (length($CATstatusesSQL) > 2) { # FIND STATUSES IN STATUS CATEGORY - $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_date' and status IN($CATstatusesSQL);"; + $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date >= '$VDL_date' and status IN($CATstatusesSQL);"; # if ($DBX) {print "|$stmtA|\n";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; @@ -1507,7 +2185,7 @@ sub calculate_drops {$update_SQL .= ",max_agents='$total_agents[$i]'";} if ($STATSmax_remote_agents < $total_remote_agents[$i]) {$update_SQL .= ",max_remote_agents='$total_remote_agents[$i]'";} - if ($STATStotal_calls < $VCScalls_today[$i]) + if ($STATStotal_calls != $VCScalls_today[$i]) {$update_SQL .= ",total_calls='$VCScalls_today[$i]'";} if (length($update_SQL) > 5) { @@ -1888,21 +2566,197 @@ sub launch_carrier_stats_gather ### END calculate times needed for queries ### $CARRIERstatsHTML=''; - $stmtA="SELECT dialstatus,count(*) from vicidial_carrier_log where call_date >= \"$timeTWENTYFOURhoursAGO\" group by dialstatus;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $ctp=0; - while ($sthArows > $ctp) + ## BEGIN CACHED HOURLY ANALYSIS: CARRIER LOG - 24 hours + if ($VLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $TFhour_status[$ctp] = $aryA[0]; - $TFhour_count[$ctp] = $aryA[1]; - $TFhour_total = ($TFhour_total + $aryA[1]); - $dialstatuses .= "'$aryA[0]',"; - $ctp++; + $secH = time(); + ($HRsec,$HRmin,$HRhour,$HRmday,$HRmon,$HRyear,$HRwday,$HRyday,$HRisdst) = localtime(time); + $HRyear = ($HRyear + 1900); + $HRmon++; + $HRhour_test = $HRhour; + if ($HRmon < 10) {$HRmon = "0$HRmon";} + if ($HRmday < 10) {$HRmday = "0$HRmday";} + if ($HRhour < 10) {$HRhour = "0$HRhour";} + $CL_today = "$HRyear-$HRmon-$HRmday"; + $CL_current_hour_date = "$HRyear-$HRmon-$HRmday $HRhour:00:00"; + $CL_current_hour_calls=0; + + ### get date-time of start of next hour ### + $CL_next_hour = ($secH + (60 * 60)); + ($NHsec,$NHmin,$NHhour,$NHmday,$NHmon,$NHyear,$NHwday,$NHyday,$NHisdst) = localtime($CL_next_hour); + $NHyear = ($NHyear + 1900); + $NHmon++; + if ($NHmon < 10) {$NHmon = "0$NHmon";} + if ($NHmday < 10) {$NHmday = "0$NHmday";} + $CL_next_hour_date = "$NHyear-$NHmon-$NHmday $NHhour:00:00"; + + if ($DBX > 1) {print "STARTING CARRIER CACHED HOURLY TOTAL CALLS: |$CL_current_hour_date|$CL_next_hour_date|\n";} + + $stmtA="SELECT dialstatus,count(*) from vicidial_carrier_log where call_date >= '$CL_current_hour_date' group by dialstatus;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $ctp=0; + while ($sthArows > $ctp) + { + @aryA = $sthA->fetchrow_array; + $cTFhour_status[$ctp] = $aryA[0]; + $cTFhour_count[$ctp] = $aryA[1]; + $cTFhour_total = ($cTFhour_total + $aryA[1]); + $ctp++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS: |$sthArows|$cTFhour_total|$ctp|$stmtA|\n";} + + $ctp=0; + while ($sthArows > $ctp) + { + $stmtA="INSERT IGNORE INTO vicidial_carrier_hour_counts SET date_hour='$CL_current_hour_date',type='$cTFhour_status[$ctp]',next_hour='$CL_next_hour_date',last_update=NOW(),calls='$cTFhour_count[$ctp]',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$cTFhour_count[$ctp]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC CURRENT HOUR INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + $ctp++; + } + if ($ctp < 1) + { + $stmtA="INSERT IGNORE INTO vicidial_carrier_hour_counts SET date_hour='$CL_current_hour_date',type='ANSWER',next_hour='$CL_next_hour_date',last_update=NOW(),calls='0',hr='$HRhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='0';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC CURRENT HOUR EMPTY INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + } + + ### get date-time of start of 24 hours ago ### + $temp_sub_sec = (24 * 3600); + $temp_24_sec = ($secH - $temp_sub_sec); + ($cSHsec,$cSHmin,$cSHhour,$cSHmday,$cSHmon,$cSHyear,$cSHwday,$cSHyday,$cSHisdst) = localtime($temp_24_sec); + $cSHyear = ($cSHyear + 1900); + $cSHmon++; + $cSHhour_test = $cSHhour; + if ($cSHmon < 10) {$cSHmon = "0$cSHmon";} + if ($cSHmday < 10) {$cSHmday = "0$cSHmday";} + $sCL_first_hour_date = "$cSHyear-$cSHmon-$cSHmday $cSHhour:00:00"; + + # check to see if cached hour totals already exist + $VCHC_entry_count=0; + $stmtA = "SELECT count(distinct hr) from vicidial_carrier_hour_counts where date_hour >= '$sCL_first_hour_date' and date_hour < '$CL_next_hour_date' and last_update > next_hour;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VCLHC_entry_count = $aryA[0]; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED HOUR CHECK: |$sthArows|$VCLHC_entry_count|$stmtA|\n";} + + # if cached not equal the number of hours, then run go hour-by-hour and generate it + if ($VCLHC_entry_count < 24) + { + $start_24_hour=24; + while ($start_24_hour > 0) + { + $temp_sub_sec = ($start_24_hour * 3600); + $temp_24_sec = ($secH - $temp_sub_sec); + $temp_24_sec_next = ($temp_24_sec + 3600); + ### get date-time of start of hour ### + ($cSHsec,$cSHmin,$cSHhour,$cSHmday,$cSHmon,$cSHyear,$cSHwday,$cSHyday,$cSHisdst) = localtime($temp_24_sec); + $cSHyear = ($cSHyear + 1900); + $cSHmon++; + $cSHhour_test = $cSHhour; + if ($cSHmon < 10) {$cSHmon = "0$cSHmon";} + if ($cSHmday < 10) {$cSHmday = "0$cSHmday";} + $sCL_start_hour_date = "$cSHyear-$cSHmon-$cSHmday $cSHhour:00:00"; + ### get date-time of start of next hour ### + ($cNHsec,$cNHmin,$cNHhour,$cNHmday,$cNHmon,$cNHyear,$cNHwday,$cNHyday,$cNHisdst) = localtime($temp_24_sec_next); + $cNHyear = ($cNHyear + 1900); + $cNHmon++; + if ($cNHmon < 10) {$cNHmon = "0$cNHmon";} + if ($cNHmday < 10) {$cNHmday = "0$cNHmday";} + $sCL_next_hour_date = "$cNHyear-$cNHmon-$cNHmday $cNHhour:00:00"; + + @cTFhour_status=@MT; + @cTFhour_count=@MT; + @cTFhour_total=0; + if ($DBX > 1) {print "STARTING CARRIER CACHED HOURLY TOTAL CALLS FOR LAST 24 HOURS: |$CL_current_hour_date|$CL_next_hour_date|\n";} + + $stmtA="SELECT dialstatus,count(*) from vicidial_carrier_log where call_date >= '$sCL_start_hour_date' and call_date < '$sCL_next_hour_date' group by dialstatus;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $ctp=0; + while ($sthArows > $ctp) + { + @aryA = $sthA->fetchrow_array; + $cTFhour_status[$ctp] = $aryA[0]; + $cTFhour_count[$ctp] = $aryA[1]; + $cTFhour_total = ($cTFhour_total + $aryA[1]); + $ctp++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CURRENT HOUR CALLS: |$sthArows|$cTFhour_total|$ctp|$start_24_hour|$stmtA|\n";} + + $ctp=0; + while ($sthArows > $ctp) + { + $stmtA="INSERT IGNORE INTO vicidial_carrier_hour_counts SET date_hour='$sCL_start_hour_date',type='$cTFhour_status[$ctp]',next_hour='$sCL_next_hour_date',last_update=NOW(),calls='$cTFhour_count[$ctp]',hr='$cSHhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='$cTFhour_count[$ctp]';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + $ctp++; + } + if ($ctp < 1) + { + $stmtA="INSERT IGNORE INTO vicidial_carrier_hour_counts SET date_hour='$sCL_start_hour_date',type='ANSWER',next_hour='$sCL_next_hour_date',last_update=NOW(),calls='0',hr='$cSHhour_test' ON DUPLICATE KEY UPDATE last_update=NOW(),calls='0';"; + $affected_rows = $dbhA->do($stmtA); + if ($DBX) {print "VCLHC STATS EMPTY INSERT/UPDATE TOTAL|$affected_rows|$stmtA|\n";} + } + $start_24_hour = ($start_24_hour - 1); + } + } + ### get date-time of start of next hour ### + $secH = time(); + $CL_next_hour = ($secH + (60 * 60)); + ($NHsec,$NHmin,$NHhour,$NHmday,$NHmon,$NHyear,$NHwday,$NHyday,$NHisdst) = localtime($CL_next_hour); + $NHyear = ($NHyear + 1900); + $NHmon++; + if ($NHmon < 10) {$NHmon = "0$NHmon";} + if ($NHmday < 10) {$NHmday = "0$NHmday";} + $CL_next_hour_date = "$NHyear-$NHmon-$NHmday $NHhour:00:00"; + + $stmtA="SELECT type,sum(calls) from vicidial_carrier_hour_counts where date_hour >= '$sCL_first_hour_date' and date_hour < '$CL_next_hour_date' group by type;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $ctp=0; + while ($sthArows > $ctp) + { + @aryA = $sthA->fetchrow_array; + $TFhour_status[$ctp] = $aryA[0]; + $TFhour_count[$ctp] = $aryA[1]; + $TFhour_total = ($TFhour_total + $aryA[1]); + $dialstatuses .= "'$aryA[0]',"; + $ctp++; + } + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED 24-HOUR SINGLE QUERY: |$sthArows|$ctp($dialstatuses)|$stmtA|\n";} + } + ## END CACHED HOURLY ANALYSIS: CARRIER LOG - 24 hours + else + { + $stmtA="SELECT dialstatus,count(*) from vicidial_carrier_log where call_date >= \"$timeTWENTYFOURhoursAGO\" group by dialstatus;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $ctp=0; + while ($sthArows > $ctp) + { + @aryA = $sthA->fetchrow_array; + $TFhour_status[$ctp] = $aryA[0]; + $TFhour_count[$ctp] = $aryA[1]; + $TFhour_total = ($TFhour_total + $aryA[1]); + $dialstatuses .= "'$aryA[0]',"; + $ctp++; + } + $sthA->finish(); } - $sthA->finish(); $dialstatuses =~ s/,$//gi; $CARRIERstatsHTML .= ""; @@ -1920,28 +2774,73 @@ sub launch_carrier_stats_gather if (length($dialstatuses) > 1) { - $stmtA="SELECT dialstatus,count(*) from vicidial_carrier_log where call_date >= \"$timeSIXhoursAGO\" group by dialstatus;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $print_sctp=0; - while ($sthArows > $print_sctp) + ## BEGIN CACHED HOURLY ANALYSIS: CARRIER LOG - 6 hours + if ($VLhour_counts > 0) { - @aryA = $sthA->fetchrow_array; - $SIXhour_total = ($SIXhour_total + $aryA[1]); - $print_ctp=0; - while ($print_ctp < $ctp) + if ($DBX > 1) {print "STARTING CARRIER CACHED HOURLY TOTAL CALLS: |$CL_current_hour_date|$CL_next_hour_date|\n";} + + ### get date-time of start of 6 hours ago ### + $secH = time(); + $temp_sub_sec = (6 * 3600); + $temp_24_sec = ($secH - $temp_sub_sec); + ($cSHsec,$cSHmin,$cSHhour,$cSHmday,$cSHmon,$cSHyear,$cSHwday,$cSHyday,$cSHisdst) = localtime($temp_24_sec); + $cSHyear = ($cSHyear + 1900); + $cSHmon++; + $cSHhour_test = $cSHhour; + if ($cSHmon < 10) {$cSHmon = "0$cSHmon";} + if ($cSHmday < 10) {$cSHmday = "0$cSHmday";} + $sxCL_first_hour_date = "$cSHyear-$cSHmon-$cSHmday $cSHhour:00:00"; + + $stmtA="SELECT type,sum(calls) from vicidial_carrier_hour_counts where date_hour >= '$sxCL_first_hour_date' and date_hour < '$CL_next_hour_date' group by type;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $print_sctp=0; + while ($sthArows > $print_sctp) { - $temp_status = $aryA[0]; - if ($TFhour_status[$print_ctp] =~ /^$temp_status$/) + @aryA = $sthA->fetchrow_array; + $SIXhour_total = ($SIXhour_total + $aryA[1]); + $print_ctp=0; + while ($print_ctp < $ctp) { - $SIXhour_count[$print_ctp] = $aryA[1]; + $temp_status = $aryA[0]; + if ($TFhour_status[$print_ctp] =~ /^$temp_status$/) + { + $SIXhour_count[$print_ctp] = $aryA[1]; + } + $print_ctp++; } - $print_ctp++; + $print_sctp++; } - $print_sctp++; + $sthA->finish(); + if ($DBX) {print "VCLHC CACHED 6-HOUR SINGLE QUERY: |$sthArows|$ctp($dialstatuses)|$stmtA|\n";} + } + ## END CACHED HOURLY ANALYSIS: CARRIER LOG - 6 hours + else + { + $stmtA="SELECT dialstatus,count(*) from vicidial_carrier_log where call_date >= \"$timeSIXhoursAGO\" group by dialstatus;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $print_sctp=0; + while ($sthArows > $print_sctp) + { + @aryA = $sthA->fetchrow_array; + $SIXhour_total = ($SIXhour_total + $aryA[1]); + $print_ctp=0; + while ($print_ctp < $ctp) + { + $temp_status = $aryA[0]; + if ($TFhour_status[$print_ctp] =~ /^$temp_status$/) + { + $SIXhour_count[$print_ctp] = $aryA[1]; + } + $print_ctp++; + } + $print_sctp++; + } + $sthA->finish(); } - $sthA->finish(); $stmtA="SELECT dialstatus,count(*) from vicidial_carrier_log where call_date >= \"$timeONEhourAGO\" group by dialstatus;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; diff --git a/docs/AGENT_EVENTS_PUSH.txt b/docs/AGENT_EVENTS_PUSH.txt index 281187fe..24043fbb 100644 --- a/docs/AGENT_EVENTS_PUSH.txt +++ b/docs/AGENT_EVENTS_PUSH.txt @@ -1,4 +1,4 @@ -Agent Events Push Started: 2017-05-31 Updated: 2017-06-29 +Agent Events Push Started: 2017-05-31 Updated: 2017-07-25 This feature allows for selected events in the VICIdial agent screen to push out event triggers through HTTP requests sent to a URL as defined in the System Settings. @@ -10,13 +10,13 @@ There are two System Settings configurations that need to be set for Agent Event Agent Push Events - This setting will enable the sending of events from agent screens to the URL defined below. Default is 0 for disabled. -Agent Push URL - If Agent Push Events are enabled above, this is the URL that the events will be sent to. The variables that you can use within the URL are --A--user--B--, --A--event--B--, --A--message--B--, --A--lead_id--B--. Since this function uses AJAX, it must reference a local script on the web server. If you want to reference an external web address then you should use the get2post.php script that can be found in the extras directory. +Agent Push URL - If Agent Push Events are enabled above, this is the URL that the events will be sent to. The variables that you can use within the URL are --A--user--B--, --A--event--B--, --A--message--B--, --A--lead_id--B--, --A--counter--B--. Since this function uses AJAX, it must reference a local script on the web server. If you want to reference an external web address then you should use the get2post.php script that can be found in the extras directory. The "agent_events" function operates through AJAX in the agent screen, and as such it can only access web scripts that are local on the web server. So, if you want to send these HTTP Push events to an external server, you will have to use a script like the get2post.php script that is included in the "extras" directory in the source code and copy it to the "agc" web directory on your webserver. Below is an example of how to populate the System Settings "Agent Push URL" field to use the get2post.php script: -get2post.php?uniqueid=--A--epoch--B--.--A--agent_log_id--B--&type=event&HTTPURLTOPOST=192.168.1.3/agc/vdc_call_url_test.php?user=--A--user--B--&lead_id=--A--lead_id--B--&event=--A--event--B--&message=--A--message--B-- +get2post.php?uniqueid=--A--epoch--B--.--A--agent_log_id--B--&type=event&HTTPURLTOPOST=192.168.1.3/agc/vdc_call_url_test.php?user=--A--user--B--&lead_id=--A--lead_id--B--&event=--A--event--B--&message=--A--message--B--&counter=--A--counter--B-- The above URL is passing the following fields to the external web script: user, lead_id, event, message diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index 73db5806..1dac53f9 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -3746,6 +3746,30 @@ unique index (caller_code), index (monitor_start_time) ) ENGINE=MyISAM; +CREATE TABLE vicidial_campaign_hour_counts ( +campaign_id VARCHAR(8), +date_hour DATETIME, +next_hour DATETIME, +last_update DATETIME, +type VARCHAR(8) default 'CALLS', +calls MEDIUMINT(6) UNSIGNED default '0', +hr TINYINT(2) default '0', +index (campaign_id), +index (date_hour), +unique index vchc_camp_hour (campaign_id, date_hour, type) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_carrier_hour_counts ( +date_hour DATETIME, +next_hour DATETIME, +last_update DATETIME, +type VARCHAR(20) default 'ANSWERED', +calls MEDIUMINT(6) UNSIGNED default '0', +hr TINYINT(2) default '0', +index (date_hour), +unique index vclhc_hour (date_hour, type) +) ENGINE=MyISAM; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -3936,6 +3960,10 @@ CREATE UNIQUE INDEX vicidial_drop_log_archive_key on vicidial_drop_log_archive(d CREATE TABLE vicidial_rt_monitor_log_archive LIKE vicidial_rt_monitor_log; +CREATE TABLE vicidial_campaign_hour_counts_archive LIKE vicidial_campaign_hour_counts; + +CREATE TABLE vicidial_carrier_hour_counts_archive LIKE vicidial_carrier_hour_counts; + GRANT RELOAD ON *.* TO cron@'%'; GRANT RELOAD ON *.* TO cron@localhost; @@ -4010,4 +4038,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version'; UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1509',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1510',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/extras/upgrade_2.14.sql b/extras/upgrade_2.14.sql index 1884ad30..3d963336 100644 --- a/extras/upgrade_2.14.sql +++ b/extras/upgrade_2.14.sql @@ -291,3 +291,33 @@ ALTER TABLE user_call_log ADD xfer_hungup VARCHAR(20) default ''; ALTER TABLE user_call_log ADD xfer_hungup_datetime DATETIME; UPDATE system_settings SET db_schema_version='1509',db_schema_update_date=NOW() where db_schema_version < 1509; + +CREATE TABLE vicidial_campaign_hour_counts ( +campaign_id VARCHAR(8), +date_hour DATETIME, +next_hour DATETIME, +last_update DATETIME, +type VARCHAR(8) default 'CALLS', +calls MEDIUMINT(6) UNSIGNED default '0', +hr TINYINT(2) default '0', +index (campaign_id), +index (date_hour), +unique index vchc_camp_hour (campaign_id, date_hour, type) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_campaign_hour_counts_archive LIKE vicidial_campaign_hour_counts; + +CREATE TABLE vicidial_carrier_hour_counts ( +date_hour DATETIME, +next_hour DATETIME, +last_update DATETIME, +type VARCHAR(20) default 'ANSWERED', +calls MEDIUMINT(6) UNSIGNED default '0', +hr TINYINT(2) default '0', +index (date_hour), +unique index vclhc_hour (date_hour, type) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_carrier_hour_counts_archive LIKE vicidial_carrier_hour_counts; + +UPDATE system_settings SET db_schema_version='1510',db_schema_update_date=NOW() where db_schema_version < 1510; diff --git a/extras/vdc_call_url_test.php b/extras/vdc_call_url_test.php index 051b480b..d86091e6 100644 --- a/extras/vdc_call_url_test.php +++ b/extras/vdc_call_url_test.php @@ -12,10 +12,11 @@ # 130328-0023 - Converted ereg to preg functions # 170324-1251 - Added more debug output # 170529-2239 - Added event/message +# 170725-2102 - Added counter variable # -$version = '2.14-5'; -$build = '170529-2239'; +$version = '2.14-6'; +$build = '170725-2102'; require("dbconnect.php"); @@ -160,6 +161,8 @@ if (isset($_GET["event"])) {$event=$_GET["event"];} elseif (isset($_POST["event"])) {$event=$_POST["event"];} if (isset($_GET["message"])) {$message=$_GET["message"];} elseif (isset($_POST["message"])) {$message=$_POST["message"];} +if (isset($_GET["counter"])) {$counter=$_GET["counter"];} + elseif (isset($_POST["counter"])) {$counter=$_POST["counter"];} header ("Content-type: text/html; charset=utf-8"); header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 @@ -199,6 +202,7 @@ if ($non_latin < 1) $length_in_sec = preg_replace("/[^0-9]/","",$length_in_sec); $phone_code = preg_replace("/[^0-9]/","",$phone_code); $phone_number = preg_replace("/[^0-9]/","",$phone_number); + $counter = preg_replace("/[^0-9]/","",$counter); } else { @@ -300,6 +304,7 @@ $output .= "$agent_log_id|"; $output .= "$dispo_name|"; $output .= "$event|"; $output .= "$message|"; +$output .= "$counter|"; echo "$output\n$query_string\n"; diff --git a/www/agc/vicidial.php b/www/agc/vicidial.php index 1f2aab48..218ee1b5 100644 --- a/www/agc/vicidial.php +++ b/www/agc/vicidial.php @@ -559,10 +559,11 @@ # 170629-1831 - Added some new agent_events entries # 170709-1116 - Added Xfer Hung Up notification # 170710-1802 - Added logging of clicks on webform buttons +# 170725-2147 - Added counter(aec) to agent_events calls # -$version = '2.14-529c'; -$build = '170710-1802'; +$version = '2.14-530c'; +$build = '170725-2147'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=87; $one_mysql_log=0; @@ -4542,6 +4543,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} var script_name=''; var transfer_panel_open=0; var last_conf_channel_count=1; + var aec=0; var DiaLControl_auto_HTML = "\" border=\"0\" alt=\"You are paused\" />"; var DiaLControl_auto_HTML_ready = "\" border=\"0\" alt=\"You are active\" />"; var DiaLControl_auto_HTML_OFF = "\" border=\"0\" alt=\"pause button disabled\" />"; @@ -4934,7 +4936,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} // dialedcall_send_hangup(); // } - agent_events('3way_agent_leave', ''); + agent_events('3way_agent_leave', '', aec); aec++; if( document.images ) { document.images['livecall'].src = image_livecall_OFF.src;} } @@ -5030,7 +5032,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} if (SMDclick=='YES') {button_click_log = button_click_log + "" + SQLdate + "-----SendManualDial---" + taskFromConf + " " + agent_dialed_type + " " + manual_string + " " + three_way_call_cid + " " + threeway_cid + " " + dial_conf_exten + " " + sending_preset_name + " ";} - agent_events('3way_start', agent_dialed_type + ' ' + manual_string); + agent_events('3way_start', agent_dialed_type + ' ' + manual_string, aec); aec++; if (taskFromConf == 'YES') { @@ -5450,20 +5452,20 @@ function set_length(SLnumber,SLlength_goal,SLdirection) button_click_log = button_click_log + "" + SQLdate + "-----agent_disabled---" + AGLogiN + " " + vicidial_agent_disable + "|"; showDiv('AgenTDisablEBoX'); refresh_interval = 7300000; - agent_events('session_disabled', 'LIVE_AGENT'); + agent_events('session_disabled', 'LIVE_AGENT', aec); aec++; } if ( (AGLogiN == 'DEAD_EXTERNAL') && ( (vicidial_agent_disable == 'EXTERNAL') || (vicidial_agent_disable == 'ALL') ) ) { button_click_log = button_click_log + "" + SQLdate + "-----agent_disabled---" + AGLogiN + " " + vicidial_agent_disable + "|"; showDiv('AgenTDisablEBoX'); refresh_interval = 7300000; - agent_events('session_disabled', 'DEAD_EXTERNAL'); + agent_events('session_disabled', 'DEAD_EXTERNAL', aec); aec++; } if ( (AGLogiN == 'TIME_SYNC') && (vicidial_agent_disable == 'ALL') ) { button_click_log = button_click_log + "" + SQLdate + "-----system_disabled---" + AGLogiN + " " + vicidial_agent_disable + "|"; showDiv('SysteMDisablEBoX'); - agent_events('time_sync', ''); + agent_events('time_sync', '', aec); aec++; } if (AGLogiN == 'SHIFT_LOGOUT') { @@ -5860,7 +5862,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { if (CheckDEADcallON < 1) { - agent_events('call_dead', LasTCID); + agent_events('call_dead', LasTCID, aec); aec++; if( document.images ) { document.images['livecall'].src = image_livecall_DEAD.src;} @@ -5884,7 +5886,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { if (CheckDEADcallON < 1) { - agent_events('call_dead', LasTCID); + agent_events('call_dead', LasTCID, aec); aec++; if( document.images ) { document.images['livecall'].src = image_livechat_DEAD.src;} @@ -5918,7 +5920,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { if ( (last_conf_channel_count < 1) && (no_empty_session_warnings < 1) ) { - agent_events('session_channels', live_conf_calls); + agent_events('session_channels', live_conf_calls, aec); aec++; last_conf_channel_count = live_conf_calls; } var temp_blind_monitors=0; @@ -6066,7 +6068,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { if ( (last_conf_channel_count > 0) && (no_empty_session_warnings < 1) ) { - agent_events('session_empty', '0'); + agent_events('session_empty', '0', aec); aec++; last_conf_channel_count = 0; } LMAe[0]=''; LMAe[1]=''; LMAe[2]=''; LMAe[3]=''; LMAe[4]=''; LMAe[5]=''; @@ -6409,7 +6411,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) if (temp_blind_dialstring != 'vmail') {temp_blind_dialstring = blindxferdialstring;} - agent_events('transfer_blind', temp_blind_dialstring); + agent_events('transfer_blind', temp_blind_dialstring, aec); aec++; } } if (taskvar == 'XfeRINTERNAL') @@ -6440,7 +6442,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) xferredirect_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&user=" + user + "&pass=" + pass + "&ACTION=RedirectVD&format=text&channel=" + redirectvalue + "&call_server_ip=" + redirectserverip + "&queryCID=" + queryCID + "&exten=" + redirectdestination + "&ext_context=" + ext_context + "&ext_priority=1&auto_dial_level=" + auto_dial_level + "&campaign=" + campaign + "&uniqueid=" + document.vicidial_form.uniqueid.value + "&lead_id=" + document.vicidial_form.lead_id.value + "&secondS=" + VD_live_call_secondS + "&session_id=" + session_id + "&CalLCID=" + CalLCID + "&customerparked=" + customerparked; - agent_events('transfer_local_closer', XfeR_GrouP); + agent_events('transfer_local_closer', XfeR_GrouP, aec); aec++; } if (taskvar == 'XfeR') { @@ -6448,7 +6450,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) var redirectdestination = document.vicidial_form.extension_xfer.value; xferredirect_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&user=" + user + "&pass=" + pass + "&ACTION=RedirectName&format=text&channel=" + redirectvalue + "&call_server_ip=" + redirectserverip + "&queryCID=" + queryCID + "&extenName=" + redirectdestination + "&ext_context=" + ext_context + "&ext_priority=1" + "&session_id=" + session_id + "&CalLCID=" + CalLCID + "&customerparked=" + customerparked; - agent_events('transfer_blind', redirectdestination); + agent_events('transfer_blind', redirectdestination, aec); aec++; } if (taskvar == 'VMAIL') { @@ -6456,7 +6458,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) var redirectdestination = document.vicidial_form.extension_xfer.value; xferredirect_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&user=" + user + "&pass=" + pass + "&ACTION=RedirectNameVmail&format=text&channel=" + redirectvalue + "&call_server_ip=" + redirectserverip + "&queryCID=" + queryCID + "&exten=" + voicemail_dump_exten + "&extenName=" + redirectdestination + "&ext_context=" + ext_context + "&ext_priority=1" + "&session_id=" + session_id + "&CalLCID=" + CalLCID + "&customerparked=" + customerparked; - agent_events('transfer_vmail', redirectdestination); + agent_events('transfer_vmail', redirectdestination, aec); aec++; } if (taskvar == 'ENTRY') { @@ -6511,7 +6513,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) customerparked=1; customerparkedcounter=0; - agent_events('park_started', ''); + agent_events('park_started', '', aec); aec++; } if (taskvar == 'FROMParK') { @@ -6540,7 +6542,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) customerparked=0; customerparkedcounter=0; - agent_events('park_retrieved', ''); + agent_events('park_retrieved', '', aec); aec++; } if (taskvar == 'ParKivr') { @@ -6563,7 +6565,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) customerparked=1; customerparkedcounter=0; - agent_events('park_ivr_started', ''); + agent_events('park_ivr_started', '', aec); aec++; } if (taskvar == 'FROMParKivr') { @@ -6592,7 +6594,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) customerparked=0; customerparkedcounter=0; - agent_events('park_ivr_retrieved', ''); + agent_events('park_ivr_retrieved', '', aec); aec++; } if (taskvar == 'ParKXfeR') @@ -7273,7 +7275,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) } else { - agent_events('agent_alert', temp_message); + agent_events('agent_alert', temp_message, aec); aec++; } document.getElementById("AlertBox").style.top = ABtop; document.getElementById("AlertBox").style.left = ABleft; @@ -7448,7 +7450,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) } showDiv('NeWManuaLDiaLBox'); - agent_events('manual_dial_open', ''); + agent_events('manual_dial_open', '', aec); aec++; document.vicidial_form.search_phone_number.value=''; document.vicidial_form.search_lead_id.value=''; @@ -8261,7 +8263,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) var XDerrorDescSIP = MDlookResponse_array[4]; var DiaLAlerTMessagE = " " + XDchannel + "\n" + XDerrorDesc + "\n" + XDerrorDescSIP; TimerActionRun("DiaLAlerT",DiaLAlerTMessagE); - agent_events('agent_alert', "Call Rejected: " + XDerrorDesc + ' ' + XDerrorDescSIP); + agent_events('agent_alert', "Call Rejected: " + XDerrorDesc + ' ' + XDerrorDescSIP, aec); aec++; } if ( (XDchannel.match(regMDL)) && (asterisk_version != '1.0.8') && (asterisk_version != '1.0.9') && (MD_ring_secondS < 10) ) { @@ -8305,7 +8307,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) xferchannellive=1; XDcheck = ''; - agent_events('3way_answered', ''); + agent_events('3way_answered', '', aec); aec++; } } else @@ -8320,7 +8322,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) var MDerrorDescSIP = MDlookResponse_array[4]; var DiaLAlerTMessagE = " " + MDchannel + "\n" + MDerrorDesc + "\n" + MDerrorDescSIP; TimerActionRun("DiaLAlerT",DiaLAlerTMessagE); - agent_events('agent_alert', "Call Rejected: " + MDerrorDesc + ' ' + MDerrorDescSIP); + agent_events('agent_alert', "Call Rejected: " + MDerrorDesc + ' ' + MDerrorDescSIP, aec); aec++; } if ( (MDchannel.match(regMDL)) && (asterisk_version != '1.0.8') && (asterisk_version != '1.0.9') ) { @@ -8449,7 +8451,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) custchannellive=1; - agent_events('call_answered', CIDcheck); + agent_events('call_answered', CIDcheck, aec); aec++; } } } @@ -8761,7 +8763,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) document.getElementById("WebFormSpanTwo").innerHTML = "\" border=\"0\" alt=\"Web Form 3\" />\n"; } - agent_events('update_fields', event_data); + agent_events('update_fields', event_data, aec); aec++; } else { @@ -8880,7 +8882,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) var man_status = ""; } - agent_events('call_dialed', mdnPhonENumbeR + " " + agent_dialed_type); + agent_events('call_dialed', mdnPhonENumbeR + " " + agent_dialed_type, aec); aec++; var xmlhttp=false; /*@cc_on @*/ @@ -9879,7 +9881,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) else {VDRP_stage = 'READY';} } - agent_events('state_ready', VDRP_stage); + agent_events('state_ready', VDRP_stage, aec); aec++; AutoDialReady = 1; AutoDialWaiting = 1; if (dial_method == "INBOUND_MAN") @@ -9896,7 +9898,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) else { VDRP_stage = 'PAUSED'; - agent_events('state_paused', VDRP_stage); + agent_events('state_paused', VDRP_stage, aec); aec++; VDRP_stage_seconds=0; AutoDialReady = 0; AutoDialWaiting = 0; @@ -10075,7 +10077,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { new_script_content = xmlhttp.responseText; document.getElementById(script_span).innerHTML = new_script_content; - agent_events('call_script', script_span); + agent_events('call_script', script_span, aec); aec++; } } delete xmlhttp; @@ -10308,7 +10310,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) document.vicidial_form.SecondS.value = 0; document.getElementById("SecondSDISP").innerHTML = '0'; - agent_events('call_answered', CalLCID); + agent_events('call_answered', CalLCID, aec); aec++; if (uniqueid_status_display=='ENABLED') {custom_call_id = " Call ID " + VDIC_data_VDAC[1];} @@ -11615,7 +11617,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) var dial_display_number = phone_number_format(callnum); alert(" " + dial_display_number + "\n - " + VDIC_data_VDIG[1] + "   " + VDIC_fronter); } - agent_events('other_answered', CalL_AutO_LauncH); + agent_events('other_answered', CalL_AutO_LauncH, aec); aec++; } xmlhttprequestcheckother = undefined; delete xmlhttprequestcheckother; @@ -12152,7 +12154,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) // alert(xmlhttp.responseText); // } - agent_events('agent_hangup', ''); + agent_events('agent_hangup', '', aec); aec++; } } process_post_hangup=1; @@ -12416,7 +12418,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) Nactiveext = xmlhttp.responseText; // alert(xmlhttp.responseText); - agent_events('3way_agent_hangup', ''); + agent_events('3way_agent_hangup', '', aec); aec++; } } process_post_hangup=1; @@ -12759,7 +12761,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) PauseCode_HTML = PauseCode_HTML + "

" + Go_BacK_LinK; document.getElementById("PauseCodeSelectContent").innerHTML = PauseCode_HTML; - agent_events('pause_code_open', ''); + agent_events('pause_code_open', '', aec); aec++; } } if (focus_blur_enabled==1) @@ -12813,7 +12815,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) showDiv('SearcHForMDisplaYBox'); if ( (VD_live_customer_call!=1) || (inOUT=='OUT') ) {WaitingForNextStep=1;} - agent_events('lead_search_open', ''); + agent_events('lead_search_open', '', aec); aec++; } } @@ -12826,7 +12828,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) {button_click_log = button_click_log + "" + SQLdate + "-----generate_contacts_search---|";} HidEGenDerPulldown(); showDiv('SearcHContactsDisplaYBox'); - agent_events('contact_search_open', ''); + agent_events('contact_search_open', '', aec); aec++; } @@ -13125,7 +13127,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) showDiv('CallBackSelectBox'); - agent_events('callback_select_open', ''); + agent_events('callback_select_open', '', aec); aec++; } else { @@ -13180,7 +13182,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) } waiting_on_dispo=0; - agent_events('dispo_set', DispoChoice); + agent_events('dispo_set', DispoChoice, aec); aec++; } } delete xmlhttp; @@ -13825,7 +13827,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { showDiv('CustomerGoneBox'); - agent_events('customer_gone', ''); + agent_events('customer_gone', '', aec); aec++; document.getElementById("callchannel").innerHTML = ''; document.vicidial_form.callserverip.value = ''; @@ -13854,7 +13856,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) function NoneInSession() { showDiv('NoneInSessionBox'); - agent_events('none_in_session', ''); + agent_events('none_in_session', '', aec); aec++; document.getElementById("NoneInSessionID").innerHTML = session_id; WaitingForNextStep=1; } @@ -14134,7 +14136,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) } hideDiv('CloserSelectBox'); - agent_events('ingroup_screen_closed', ''); + agent_events('ingroup_screen_closed', '', aec); aec++; MainPanelToFront(); CloserSelecting = 0; scroll(0,0); @@ -14297,7 +14299,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) } hideDiv('TerritorySelectBox'); - agent_events('territory_screen_closed', ''); + agent_events('territory_screen_closed', '', aec); aec++; MainPanelToFront(); TerritorySelecting = 0; scroll(0,0); @@ -14402,7 +14404,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) } else { - agent_events('logged_out', tempreason); + agent_events('logged_out', tempreason, aec); aec++; document.getElementById("LogouTProcess").innerHTML = "



          \" height=\"206px\" width=\"206px\" alt=\"\" />"; // document.getElementById("LogouTProcess").innerHTML = ""; @@ -14441,7 +14443,7 @@ function set_length(SLnumber,SLlength_goal,SLdirection) document.getElementById("LogouTProcess").innerHTML = "



          \" height=\"206px\" width=\"206px\" alt=\"\" />"; - agent_events('logged_out_complete', ''); + agent_events('logged_out_complete', '', aec); aec++; } } delete xmlhttp; @@ -16224,11 +16226,11 @@ function phone_number_format(formatphone) { // ################################################################################ // Run the Agent Push Events process - function agent_events(event_type,event_msg) + function agent_events(event_type,event_msg,event_counter) { if ( (agent_push_events > 0) && (agent_push_url.length > 10) ) { - button_click_log = button_click_log + "" + SQLdate + "-----AgentEvent---" + event_type + "|"; + button_click_log = button_click_log + "" + SQLdate + "-----AgentEvent---" + event_type + " " + event_counter + "|"; // if (event_type == 'logged_out') // {check_for_conf_calls(session_id, '0');} var xmlhttp=false; @@ -16264,6 +16266,7 @@ function phone_number_format(formatphone) { var SClead_id = document.vicidial_form.lead_id.value; var SCepoch = UnixTime; var SCagent_log_id = agent_log_id; + var SCcounter = event_counter; SCuser = SCuser.replace(RGplus,'+'); SCevent = SCevent.replace(RGplus,'+'); SCmessage = SCmessage.replace(RGplus,'+'); @@ -16274,12 +16277,14 @@ function phone_number_format(formatphone) { var RGlead_id = new RegExp("--A--lead_id--B--","g"); var RGepoch = new RegExp("--A--epoch--B--","g"); var RGagent_log_id = new RegExp("--A--agent_log_id--B--","g"); + var RGcounter = new RegExp("--A--counter--B--","g"); temp_agent_push_url = temp_agent_push_url.replace(RGuser, SCuser); temp_agent_push_url = temp_agent_push_url.replace(RGevent, SCevent); temp_agent_push_url = temp_agent_push_url.replace(RGmessage, SCmessage); temp_agent_push_url = temp_agent_push_url.replace(RGlead_id, SClead_id); temp_agent_push_url = temp_agent_push_url.replace(RGepoch, SCepoch); temp_agent_push_url = temp_agent_push_url.replace(RGagent_log_id, SCagent_log_id); + temp_agent_push_url = temp_agent_push_url.replace(RGcounter, SCcounter); temp_agent_push_url = temp_agent_push_url.replace(RGplus, '+'); temp_agent_push_url = temp_agent_push_url.replace(RGnl, '+'); temp_agent_push_url = temp_agent_push_url.replace(RGtab, '+'); @@ -16441,7 +16446,7 @@ function phone_number_format(formatphone) { { HidEGenDerPulldown(); showDiv('CloserSelectBox'); - agent_events('ingroup_screen_open', ''); + agent_events('ingroup_screen_open', '', aec); aec++; } } } @@ -16469,7 +16474,7 @@ function phone_number_format(formatphone) { if (move_on == 1) { showDiv('TerritorySelectBox'); - agent_events('territory_screen_open', ''); + agent_events('territory_screen_open', '', aec); aec++; } } @@ -16947,12 +16952,12 @@ function phone_number_format(formatphone) { CloserSelectContent_create(); if (VU_agent_choose_ingroups_DV == "MGRLOCK") {VU_agent_choose_ingroups_skip_count = mrglock_ig_select_ct;} - agent_events('ingroup_screen_open', ''); + agent_events('ingroup_screen_open', '', aec); aec++; } else { hideDiv('CloserSelectBox'); - agent_events('ingroup_screen_closed', ''); + agent_events('ingroup_screen_closed', '', aec); aec++; MainPanelToFront(); var CloserSelecting = 0; if (dial_method == "INBOUND_MAN") @@ -16970,12 +16975,12 @@ function phone_number_format(formatphone) { TerritorySelectContent_create(); if (agent_select_territories == "MGRLOCK") {agent_select_territories_skip_count=4;} - agent_events('territory_screen_open', ''); + agent_events('territory_screen_open', '', aec); aec++; } else { hideDiv('TerritorySelectBox'); - agent_events('territory_screen_closed', ''); + agent_events('territory_screen_closed', '', aec); aec++; MainPanelToFront(); var TerritorySelecting = 0; } @@ -17082,7 +17087,7 @@ function phone_number_format(formatphone) { // alert("IFRAME submitting!"); customsubmit_trigger=1; } - agent_events('dispo_screen_open', ''); + agent_events('dispo_screen_open', '', aec); aec++; } // trigger custom form submit if standard form has already been submitted or 3 seconds have gone by if (customsubmit_trigger > 0) @@ -17395,7 +17400,7 @@ function phone_number_format(formatphone) { { document.getElementById("blind_monitor_alert_span_contents").innerHTML = blind_monitor_message; showDiv('blind_monitor_alert_span'); - agent_events('blind_monitor_alert', ''); + agent_events('blind_monitor_alert', '', aec); aec++; } if ( (blind_monitor_filename.length > 0) && ( (blind_monitor_warning=='AUDIO') || (blind_monitor_warning=='ALERT_AUDIO')|| (blind_monitor_warning=='NOTICE_AUDIO') || (blind_monitor_warning=='ALL') ) ) { @@ -17676,9 +17681,9 @@ function phone_number_format(formatphone) { if (check_n==2) { hideDiv('LoadingBox'); - agent_events('logged_in', session_id + ' ' + server_ip + ' ' + version + ' ' + build + ' ' + script_name); + agent_events('logged_in', session_id + ' ' + server_ip + ' ' + version + ' ' + build + ' ' + script_name, aec); aec++; if (deactivated_old_session > 0) - {agent_events('session_disabled', '');} + {agent_events('session_disabled', '', aec); aec++;} if (invalid_opener > 0) { @@ -17686,7 +17691,7 @@ function phone_number_format(formatphone) { logout_stop_timeouts = 1; showDiv('InvalidOpenerSpan'); - agent_events('login_invalid', ''); + agent_events('login_invalid', '', aec); aec++; } } } @@ -17877,7 +17882,7 @@ function phone_number_format(formatphone) { if (custom_3way_button_transfer_enabled > 0) {document.getElementById("CustomXfer").innerHTML = "\" border=\"0\" alt=\"Custom Transfer\" />";} - agent_events('transfer_panel_open', ''); + agent_events('transfer_panel_open', '', aec); aec++; transfer_panel_open=1; } else @@ -17904,7 +17909,7 @@ function phone_number_format(formatphone) { } if (transfer_panel_open > 0) { - agent_events('transfer_panel_closed', ''); + agent_events('transfer_panel_closed', '', aec); aec++; transfer_panel_open=0; } } diff --git a/www/vicidial/help.php b/www/vicidial/help.php index 71b9aa82..d730401b 100644 --- a/www/vicidial/help.php +++ b/www/vicidial/help.php @@ -6248,7 +6248,7 @@ if ($SSqc_features_active > 0) CUSTOMER = Time the agent is in a live call with a customer."); ?>
System Statuses."); ?>

-TOTAL = Total time on the system (WAIT + TALK + DISPO + PAUSE)."); ?>
+LOGIN TIME = Total time on the system (WAIT + TALK + DISPO + PAUSE)."); ?>
NONPAUSE = Everything except pause (WAIT + TALK + DISPO)."); ?>
PAUSE = Only Pause."); ?>