From d1e36d36fdff529a381b6f609992df6577793ce7 Mon Sep 17 00:00:00 2001 From: mattf Date: Fri, 23 Dec 2011 16:49:28 +0000 Subject: [PATCH] small fixes for max stats in AGI scripts git-svn-id: svn://192.168.202.10@1766 3d104415-ff17-0410-8863-d5cf3c621b8a --- agi/agi-VDAD_ALL_inbound.agi | 90 +++++++++++++-------------- agi/agi-VDAD_ALL_outbound.agi | 111 +++++++++++++++++----------------- 2 files changed, 101 insertions(+), 100 deletions(-) diff --git a/agi/agi-VDAD_ALL_inbound.agi b/agi/agi-VDAD_ALL_inbound.agi index 37a523eb..073ee8b9 100644 --- a/agi/agi-VDAD_ALL_inbound.agi +++ b/agi/agi-VDAD_ALL_inbound.agi @@ -1122,64 +1122,66 @@ if (length($action_xfer_cid) > 4) -##### BEGIN MAX CONCURRENT CALLS CHECK ##### +##### BEGIN MAX CONCURRENT CALLS LOOKUP AND CHECK ##### $MCafterhours_override=0; $MCnanque_override=0; $MCdrop_override=0; $MCstatus=''; $MCterm=''; $MCcomments=''; -if ( ($max_calls_method !~ /DISABLED/) && ($max_calls_count > 0) ) +$concurrent_calls=0; +$incalls_count=0; + +### Get count of concurrent calls for this in-group +$stmtA = "SELECT count(*) FROM vicidial_auto_calls where campaign_id='$channel_group' and callerid!='$callerid';"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02187'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) { - $concurrent_calls=0; - $incalls_count=0; - ### Get count of concurrent calls for this in-group - $stmtA = "SELECT count(*) FROM vicidial_auto_calls where campaign_id='$channel_group' and callerid!='$callerid';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $dbhP=$dbhA; $mysql_count='02187'; $MEL_aff_rows=$sthArows; &mysql_error_logging; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $concurrent_calls = $aryA[0]; - $incalls_count = $aryA[0]; - $incalls_count++; - } + @aryA = $sthA->fetchrow_array; + $concurrent_calls = $aryA[0]; + $incalls_count = $aryA[0]; + $incalls_count++; + } +$sthA->finish(); + +$STATSmax_inbound=0; +$stmtA = "SELECT max_inbound from vicidial_daily_max_stats where campaign_id='$channel_group' and stats_type='INGROUP' and stats_flag='OPEN' order by update_time desc limit 1;"; +$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; +$sthA->execute or die "executing: $stmtA ", $dbhA->errstr; +$sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='02192'; $MEL_aff_rows=$sthArows; &mysql_error_logging; +if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $STATSmax_inbound = $aryA[0]; $sthA->finish(); - $STATSmax_inbound=0; - $stmtA = "SELECT max_inbound from vicidial_daily_max_stats where campaign_id='$channel_group' and stats_type='INGROUP' and stats_flag='OPEN' order by update_time desc limit 1;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $dbhP=$dbhA; $mysql_count='02192'; $MEL_aff_rows=$sthArows; &mysql_error_logging; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $STATSmax_inbound = $aryA[0]; - $sthA->finish(); + $update_SQL=''; + if ($STATSmax_inbound < $incalls_count) + {$update_SQL .= ",max_inbound='$incalls_count'";} - $update_SQL=''; - if ($STATSmax_inbound < $incalls_count) - {$update_SQL .= ",max_inbound='$incalls_count'";} - - if (length($update_SQL) > 5) - { - $stmtA = "UPDATE vicidial_daily_max_stats SET update_time=NOW()$update_SQL where campaign_id='$channel_group' and stats_type='INGROUP' and stats_flag='OPEN';"; - $affected_rows = $dbhA->do($stmtA); - $dbhP=$dbhA; $mysql_count='02193'; $MEL_aff_rows=$sthArows; &mysql_error_logging; - if ($AGILOG) {$agi_string = "DAILY STATS UPDATE $channel_group|$affected_rows|$stmtA|\n"; &agi_output;} - } - } - else + if (length($update_SQL) > 5) { - $stmtA = "INSERT INTO vicidial_daily_max_stats SET stats_date='$YMD',update_time=NOW(),max_inbound='$incalls_count',campaign_id='$channel_group',stats_type='INGROUP',stats_flag='OPEN';"; + $stmtA = "UPDATE vicidial_daily_max_stats SET update_time=NOW()$update_SQL where campaign_id='$channel_group' and stats_type='INGROUP' and stats_flag='OPEN';"; $affected_rows = $dbhA->do($stmtA); - $dbhP=$dbhA; $mysql_count='02195'; $MEL_aff_rows=$sthArows; &mysql_error_logging; - if ($AGILOG) {$agi_string = "DAILY STATS INSERT $channel_group|$affected_rows|$stmtA|\n"; &agi_output;} + $dbhP=$dbhA; $mysql_count='02193'; $MEL_aff_rows=$sthArows; &mysql_error_logging; + if ($AGILOG) {$agi_string = "DAILY STATS UPDATE $channel_group|$affected_rows|$stmtA|\n"; &agi_output;} } + } +else + { + $stmtA = "INSERT INTO vicidial_daily_max_stats SET stats_date='$YMD',update_time=NOW(),max_inbound='$incalls_count',campaign_id='$channel_group',stats_type='INGROUP',stats_flag='OPEN';"; + $affected_rows = $dbhA->do($stmtA); + $dbhP=$dbhA; $mysql_count='02195'; $MEL_aff_rows=$sthArows; &mysql_error_logging; + if ($AGILOG) {$agi_string = "DAILY STATS INSERT $channel_group|$affected_rows|$stmtA|\n"; &agi_output;} + } + +if ( ($max_calls_method !~ /DISABLED/) && ($max_calls_count > 0) ) + { if (($max_calls_method =~ /IN_QUEUE/)) { $stmtA = "SELECT count(*) FROM vicidial_auto_calls where campaign_id='$channel_group' and status IN('LIVE','IVR') and callerid!='$callerid';"; diff --git a/agi/agi-VDAD_ALL_outbound.agi b/agi/agi-VDAD_ALL_outbound.agi index 444fb21c..749f6801 100644 --- a/agi/agi-VDAD_ALL_outbound.agi +++ b/agi/agi-VDAD_ALL_outbound.agi @@ -428,6 +428,60 @@ if ($VDACaffected_rows < 1) { if ($AGILOG) {$agi_string = "-- NO VDM FOUND!!!!!!!!!!: $callerid"; &agi_output;} } + } +if ($VDACaffected_rows > 0) + { + ### find list of callback statuses + $SCstatuses="'CBHOLD'"; + $stmtA = "select status from vicidial_statuses where scheduled_callback='Y' limit 10000000;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsSCS=$sthA->rows; + $rec_count=0; + while ($sthArowsSCS > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $SCstatuses .= ",'$aryA[0]'"; + $rec_count++; + } + $sthA->finish(); + $stmtA = "select status from vicidial_campaign_statuses where scheduled_callback='Y' limit 10000000;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsSCS=$sthA->rows; + $rec_count=0; + while ($sthArowsSCS > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $SCstatuses .= ",'$aryA[0]'"; + $rec_count++; + } + $sthA->finish(); + + # flag the lead as being Answered or Picked up + $stmtA = "UPDATE vicidial_list set status='PU' where lead_id='$CIDlead_id' and status NOT IN($SCstatuses);"; + if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} + $affected_rows = $dbhA->do($stmtA); + $dbhP=$dbhA; $mysql_count='01005'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; + if ($AGILOG) {$agi_string = "-- VDAD vicidial_list PU update: |$affected_rows|$uniqueid|"; &agi_output;} + + $stmtA = "SELECT campaign_id,phone_number,phone_code,lead_id,call_time,alt_dial,queue_priority FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $dbhP=$dbhA; $mysql_count='01006'; $MEL_aff_rows=$sthArows; &mysql_error_logging; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $VDADcampaign = $aryA[0]; + $VDADphone = $aryA[1]; + $VDADphone_code = $aryA[2]; + $VDADlead_id = $aryA[3]; + $VDADcall_time = $aryA[4]; + $VDADalt_dial = $aryA[5]; + $VDADqueue_priority = $aryA[6]; + } + $sthA->finish(); ##### BEGIN - Max call stats $outcalls_count=0; @@ -465,7 +519,7 @@ if ($VDACaffected_rows < 1) $stmtA = "UPDATE vicidial_daily_max_stats SET update_time=NOW()$update_SQL where campaign_id='$VDADcampaign' and stats_type='CAMPAIGN' and stats_flag='OPEN';"; $affected_rows = $dbhA->do($stmtA); $dbhP=$dbhA; $mysql_count='02095'; $MEL_aff_rows=$sthArows; &mysql_error_logging; - if ($AGILOG) {$agi_string = "DAILY STATS UPDATE $VDADcampaign|$affected_rows|$stmtA|\n"; &agi_output;} + if ($AGILOG) {$agi_string = "DAILY STATS UPDATE $VDADcampaign|$affected_rows|$stmtA|"; &agi_output;} } } else @@ -476,61 +530,6 @@ if ($VDACaffected_rows < 1) if ($AGILOG) {$agi_string = "DAILY STATS INSERT $VDADcampaign|$affected_rows|$stmtA|\n"; &agi_output;} } ##### END - Max call stats - } -if ($VDACaffected_rows > 0) - { - ### find list of callback statuses - $SCstatuses="'CBHOLD'"; - $stmtA = "select status from vicidial_statuses where scheduled_callback='Y' limit 10000000;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArowsSCS=$sthA->rows; - $rec_count=0; - while ($sthArowsSCS > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $SCstatuses .= ",'$aryA[0]'"; - $rec_count++; - } - $sthA->finish(); - $stmtA = "select status from vicidial_campaign_statuses where scheduled_callback='Y' limit 10000000;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArowsSCS=$sthA->rows; - $rec_count=0; - while ($sthArowsSCS > $rec_count) - { - @aryA = $sthA->fetchrow_array; - $SCstatuses .= ",'$aryA[0]'"; - $rec_count++; - } - $sthA->finish(); - - - # flag the lead as being Answered or Picked up - $stmtA = "UPDATE vicidial_list set status='PU' where lead_id='$CIDlead_id' and status NOT IN($SCstatuses);"; - if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} - $affected_rows = $dbhA->do($stmtA); - $dbhP=$dbhA; $mysql_count='01005'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; - if ($AGILOG) {$agi_string = "-- VDAD vicidial_list PU update: |$affected_rows|$uniqueid|"; &agi_output;} - - $stmtA = "SELECT campaign_id,phone_number,phone_code,lead_id,call_time,alt_dial,queue_priority FROM vicidial_auto_calls where callerid='$callerid' order by call_time desc limit 1;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $dbhP=$dbhA; $mysql_count='01006'; $MEL_aff_rows=$sthArows; &mysql_error_logging; - if ($sthArows > 0) - { - @aryA = $sthA->fetchrow_array; - $VDADcampaign = $aryA[0]; - $VDADphone = $aryA[1]; - $VDADphone_code = $aryA[2]; - $VDADlead_id = $aryA[3]; - $VDADcall_time = $aryA[4]; - $VDADalt_dial = $aryA[5]; - $VDADqueue_priority = $aryA[6]; - } - $sthA->finish(); ### Grab campaign values from the database $stmtA = "SELECT drop_call_seconds,drop_action,safe_harbor_exten,concurrent_transfers,next_agent_call,voicemail_ext,drop_inbound_group,use_internal_dnc,use_campaign_dnc,cpd_amd_action,am_message_exten,three_way_call_cid,campaign_cid,survey_first_audio_file,survey_opt_in_audio_file,survey_ni_audio_file,survey_third_audio_file,survey_fourth_audio_file,extension_appended_cidname,queue_priority,closer_campaigns,queuemetrics_phone_environment,campaign_recording,campaign_rec_filename,safe_harbor_audio,safe_harbor_menu_id,survey_recording FROM vicidial_campaigns where campaign_id = '$VDADcampaign';";