Added SHARED_... campaign dial method auto-dial options, for more efficient agent multi-campaign dialing. Read the AGENT_MULTI-CAMPAIGN_DIALING.txt document for more information.

git-svn-id: svn://192.168.202.10@3339 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2021-01-02 22:05:07 +00:00
parent d23f5e1dbf
commit e8fff646ab
12 changed files with 600 additions and 73 deletions
+28 -1
View File
@@ -143,9 +143,10 @@
# 200425-0218 - Added purging of vicidial_lead_messages after 1 day
# 200623-2304 - Added Answer Signal options
# 201123-1651 - Added reset of vicidial_lead_call_daily_counts table
# 201218-2054 - Added reset of vicidial_agent_dial_campaigns table
#
$build = '201123-1651';
$build = '201218-2054';
$DB=0; # Debug flag
$teodDB=0; # flag to log Timeclock End of Day processes to log file
@@ -232,7 +233,18 @@ if ($SXsec < 10) {$SXsec = "0$SXsec";}
$SXSQLdate = "$SXyear-$SXmon-$SXmday $SXhour:$SXmin:$SXsec";
$SXdate = "$SXyear-$SXmon-$SXmday";
### calculate the date and time for 5 minutes ago
$FMtarget = ($secX - 300); # 5 minutes ago
($Fsec,$Fmin,$Fhour,$Fmday,$Fmon,$Fyear,$Fwday,$Fyday,$Fisdst) = localtime($FMtarget);
$Fyear = ($Fyear + 1900);
$Fmon++;
if ($Fmon < 10) {$Fmon = "0$Fmon";}
if ($Fmday < 10) {$Fmday = "0$Fmday";}
if ($Fhour < 10) {$Fhour = "0$Fhour";}
if ($Fmin < 10) {$Fmin = "0$Fmin";}
if ($Fsec < 10) {$Fsec = "0$Fsec";}
$FMSQLdate = "$Fyear-$Fmon-$Fmday $Fhour:$Fmin:$Fsec";
### begin parsing run-time options ###
if (length($ARGV[0])>1)
@@ -1297,6 +1309,21 @@ if ($timeclock_end_of_day_NOW > 0)
if ($DB) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
$sthA->finish();
$stmtA = "delete from vicidial_agent_dial_campaigns where validate_time < \"$FMSQLdate\";";
if($DBX){print STDERR "\n|$stmtA|\n";}
$affected_rows = $dbhA->do($stmtA);
if($DB){print STDERR "\n|$affected_rows vicidial_agent_dial_campaigns records deleted|\n";}
if ($teodDB) {$event_string = "vicidial_agent_dial_campaigns records reset: $affected_rows"; &teod_logger;}
$stmtA = "optimize table vicidial_agent_dial_campaigns;";
if($DBX){print STDERR "\n|$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@aryA = $sthA->fetchrow_array;
if ($DB) {print "|",$aryA[0],"|",$aryA[1],"|",$aryA[2],"|",$aryA[3],"|","\n";}
$sthA->finish();
if ($agents_calls_reset > 0)
{
$stmtA = "delete from vicidial_live_inbound_agents where last_call_finish < \"$TDSQLdate\";";
+209 -7
View File
@@ -53,6 +53,7 @@
# 190722-1004 - Added more logging and log-audit portions to Call Quotas log audit code
# 200811-1600 - Include live agents from other campaigns if they have the campaign Drop-InGroup selected and drop sec < 0
# 201106-2141 - Added calculation and caching of park_log stats per campaign/in-group
# 201214-0857 - Added SHARED_ campaign agent rotation functions
#
# constants
@@ -76,6 +77,7 @@ $SSofcom_uk_drop_calc=0;
$i=0;
$daily_stats=1;
$drop_count_updater=0;
$shared_agent_count_updater=0;
$stat_it=15;
$diff_ratio_updater=0;
$stat_count=1;
@@ -116,6 +118,8 @@ $cwu_any_on=0;
# set to 61 initially so that a baseline drop count is pulled
$drop_count_updater=61;
# set to 61 initially so that a baseline shared agent process is run
$shared_agent_count_updater=61;
$secT = time();
@@ -306,7 +310,7 @@ $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VA
if ($DBX) {print "CONNECTED TO DATABASE: $VARDB_server|$VARDB_database\n";}
##### gather relevent system settings
$stmtA = "SELECT cache_carrier_stats_realtime,ofcom_uk_drop_calc,call_quota_lead_ranking,use_non_latin from system_settings;";
$stmtA = "SELECT cache_carrier_stats_realtime,ofcom_uk_drop_calc,call_quota_lead_ranking,use_non_latin,allow_shared_dial from system_settings;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -317,6 +321,7 @@ if ($sthArows > 0)
$SSofcom_uk_drop_calc = $aryA[1];
$SScall_quota_lead_ranking = $aryA[2];
$non_latin = $aryA[3];
$SSallow_shared_dial = $aryA[4];
}
$sthA->finish();
@@ -340,6 +345,16 @@ $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthA->finish();
$stmtA = "INSERT IGNORE into vicidial_campaign_stats_debug SET campaign_id='--ALL--',server_ip='SHARED';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthA->finish();
$stmtA = "INSERT IGNORE into vicidial_campaign_stats_debug (campaign_id,server_ip) select campaign_id,'SHARED' from vicidial_campaigns;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthA->finish();
&get_time_now;
@@ -540,14 +555,14 @@ while ($master_loop < $CLIloops)
### Find out how many agents are logged in to a specific campaign
# check if drop-in-group agents should be included ---NONE---
$drop_ingroup_SQL[$i]='';
if ( ($drop_call_seconds[$i] < 0) && ($drop_action[$i] =~ /IN_GROUP/i) && ($drop_inbound_group[$i] !~ /^---NONE---$/) && (length($drop_inbound_group[$i]) > 0) && ($new_agent_multicampaign > 0) )
if ( ($drop_call_seconds[$i] < 0) && ($drop_action[$i] =~ /IN_GROUP/i) && ($drop_inbound_group[$i] !~ /^---NONE---$/) && (length($drop_inbound_group[$i]) > 0) && ($new_agent_multicampaign > 0) && ($dial_method[$i] !~ /SHARED_/i) )
{
$SQL_group_id=$drop_inbound_group[$i]; $SQL_group_id =~ s/_/\\_/gi;
$drop_ingroup_SQL[$i] = " or ( (campaign_id!='$campaign_id[$i]') and (closer_campaigns LIKE \"% $SQL_group_id %\") )";
if ($DB) {print " $campaign_id[$i] Drop In-Group agents included from: $drop_inbound_group[$i]";}
$debug_camp_output .= " $campaign_id[$i] Drop In-Group agents included from: $drop_inbound_group[$i]\n";
}
$stmtA = "SELECT count(*) from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one';";
$stmtA = "SELECT count(*) from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') or (dial_campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -561,7 +576,7 @@ while ($master_loop < $CLIloops)
}
$sthA->finish();
$event_string = "|$campaign_id[$i]|$hopper_level[$i]|$hopper_ready_count|$local_call_time[$i]|$diff_ratio_updater|$drop_count_updater|";
$event_string = "|$campaign_id[$i]|$hopper_level[$i]|$hopper_ready_count|$local_call_time[$i]|$diff_ratio_updater|$drop_count_updater|$shared_agent_count_updater|";
if ($DBX) {print "$i $event_string\n";}
$debug_camp_output .= "$i $event_string\n";
&event_logger;
@@ -677,6 +692,12 @@ while ($master_loop < $CLIloops)
&launch_max_calls_gather;
}
### Update Drop counter every 60 seconds
if ($shared_agent_count_updater >= 60)
{
&shared_agent_process;
}
if ( (($stat_count =~ /00$|50$/) || ($stat_count==1)) )
{
$stmtA = "SELECT cache_carrier_stats_realtime,ofcom_uk_drop_calc from system_settings;";
@@ -698,8 +719,10 @@ while ($master_loop < $CLIloops)
if ($RESETdiff_ratio_updater > 0) {$RESETdiff_ratio_updater=0; $diff_ratio_updater=0;}
if ($RESETdrop_count_updater > 0) {$RESETdrop_count_updater=0; $drop_count_updater=0;}
if ($RESETshared_agent_count_updater > 0) {$RESETshared_agent_count_updater=0; $shared_agent_count_updater=0;}
$diff_ratio_updater = ($diff_ratio_updater + $CLIdelay);
$drop_count_updater = ($drop_count_updater + $CLIdelay);
$shared_agent_count_updater = ($shared_agent_count_updater + $CLIdelay);
@@ -2171,7 +2194,7 @@ sub count_agents_lines
$total_agents_avg[$i]=0;
$stat_differential[$i]=0;
$stmtA = "SELECT count(*),status from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one' group by status;";
$stmtA = "SELECT count(*),status from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') or (dial_campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one' group by status;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -2228,7 +2251,7 @@ sub count_agents_lines
# LIVE CAMPAIGN CALLS RIGHT NOW
if ($daily_stats > 0)
{
$stmtA = "SELECT count(*) from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one' and extension LIKE \"R/%\";";
$stmtA = "SELECT count(*) from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') or (dial_campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one' and extension LIKE \"R/%\";";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -2261,7 +2284,186 @@ sub count_agents_lines
sub shared_agent_process
{
$RESETshared_agent_count_updater++;
$SHARED_campaigns_ct=0;
$SHARED_agents_ct=0;
@SHARED_campaigns=@MT;
@SHARED_campaigns_drop_ig=@MT;
@SHARED_campaigns_agnt_ct=@MT;
@SHARED_campaigns_agnt_dl=@MT;
@SHARED_campaigns_dial_ct=@MT;
@SHARED_agents=@MT;
@SHARED_agents_cig=@MT;
@SHARED_agents_dig=@MT;
$debug_shared_output='';
if ($SSallow_shared_dial > 0)
{
$camp_SHARED_SQL='';
$drop_SHARED_SQL='';
# Get list of active SHARED_ campaigns
$stmtA = "SELECT campaign_id,drop_inbound_group from vicidial_campaigns where active='Y' and dial_method IN('SHARED_RATIO','SHARED_ADAPT_HARD_LIMIT','SHARED_ADAPT_TAPERED','SHARED_ADAPT_AVERAGE');";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
while ($sthArows > $SHARED_campaigns_ct)
{
@aryA = $sthA->fetchrow_array;
$camp_SHARED_SQL .= "'$aryA[0]',";
$SHARED_campaigns[$SHARED_campaigns_ct] = $aryA[0];
$SHARED_campaigns_agnt_ct[$SHARED_campaigns_ct] = 0;
$SHARED_campaigns_agnt_dl[$SHARED_campaigns_ct] = 0;
$SHARED_campaigns_dial_ct[$SHARED_campaigns_ct] = 0;
if (length($aryA[1]) > 0)
{
$SHARED_campaigns_drop_ig[$SHARED_campaigns_ct] = $aryA[1];
$SQL_group_id=$aryA[1]; $SQL_group_id =~ s/_/\\_/gi;
$temp_drop_ingroup_SQL = "(closer_campaigns LIKE \"% $SQL_group_id %\")";
if (length($drop_SHARED_SQL) > 10) {$drop_SHARED_SQL .= " or ";}
$drop_SHARED_SQL .= "$temp_drop_ingroup_SQL";
}
else {if ($DBX) {print "Empty Drop In-Group for campaign: $aryA[0]\n";}}
$SHARED_campaigns_ct++;
}
$sthA->finish();
chop($camp_SHARED_SQL);
if (length($camp_SHARED_SQL)<2)
{$camp_SHARED_SQL="'-NONE-'";}
if (length($drop_SHARED_SQL)<2)
{$drop_SHARED_SQL="closer_campaigns='----------'";}
$drop_SHARED_SQL = "and ($drop_SHARED_SQL)";
$now_epoch = time();
$BDtarget = ($now_epoch - 10);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
$agent_SHARED_SQL='';
# Get list of active SHARED_ campaigns
$stmtA = "SELECT user,closer_campaigns,dial_campaign_id from vicidial_live_agents where last_update_time > '$BDtsSQLdate' $drop_SHARED_SQL;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($DBX) {print "$sthArows|$stmtA|\n";}
$SHARED_agents_ct=0;
while ($sthArows > $SHARED_agents_ct)
{
@aryA = $sthA->fetchrow_array;
$SHARED_agents[$SHARED_agents_ct] = $aryA[0];
$SHARED_agents_cig[$SHARED_agents_ct] = $aryA[1];
$SHARED_agents_dig[$SHARED_agents_ct] = $aryA[2];
$agent_SHARED_SQL .= "'$aryA[0]',";
$SHARED_agents_ct++;
}
$sthA->finish();
chop($agent_SHARED_SQL);
if (length($agent_SHARED_SQL)<2)
{$agent_SHARED_SQL="'-NONE-'";}
$event_string="SHARED CAMPAIGNS: $SHARED_campaigns_ct $SHARED_agents_ct";
$DBX_string="CAMP SQL: $camp_SHARED_SQL\nDROP SQL: $drop_SHARED_SQL\nAGNT SQL: $agent_SHARED_SQL\n";
if ($DBX) {print "$DBX_string";}
if ($DB) {print " $event_string\n";}
$DBX_string =~ s/'//gi;
$debug_shared_output .= "$event_string\n$DBX_string";
&event_logger;
# update debug output
$stmtA = "UPDATE vicidial_campaign_stats_debug SET entry_time='$now_date',debug_output='$debug_shared_output' where campaign_id='--ALL--' and server_ip='SHARED';";
$affected_rows = $dbhA->do($stmtA);
### If there are active SHARED_ campaigns and agents set to take calls from the drop-in-groups of those campaigns, then start processing SHARED_ agents
if ( ($SHARED_campaigns_ct > 0) and ($SHARED_agents_ct > 0) )
{
$agent_shared_output="Shared Agent Rotation process last ran: $now_date \n";
$sh_ct=0;
while($SHARED_agents_ct > $sh_ct)
{
$cp_ct=0;
while($SHARED_campaigns_ct > $cp_ct)
{
$temp_drop = $SHARED_campaigns_drop_ig[$cp_ct];
if ( ($SHARED_agents_cig[$sh_ct] =~ / $temp_drop /) && (length($temp_drop) > 0) )
{
$SHARED_campaigns_agnt_ct[$cp_ct]++;
# insert/update vicidial_agent_dial_campaigns record for this agent/campaign
$stmtA = "INSERT IGNORE INTO vicidial_agent_dial_campaigns SET validate_time='$now_date',group_id='$temp_drop',campaign_id='$SHARED_campaigns[$cp_ct]',user='$SHARED_agents[$sh_ct]',dial_time='2020-01-01 00:00:00' ON DUPLICATE KEY UPDATE validate_time='$now_date',group_id='$temp_drop';";
$affected_rows_vadc_up = $dbhA->do($stmtA);
}
$cp_ct++;
}
# delete old vicidial_agent_dial_campaigns entries for this agent
$stmtA = "DELETE FROM vicidial_agent_dial_campaigns WHERE validate_time < \"$now_date\" and user='$SHARED_agents[$sh_ct]';";
$affected_rows_vadc_del = $dbhA->do($stmtA);
# gather oldest dial campaign for this agent
$next_dial_campaign_id='';
$stmtA = "SELECT campaign_id from vicidial_agent_dial_campaigns where user='$SHARED_agents[$sh_ct]' order by dial_time asc limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($DBX) {print "$sthArows|$stmtA|\n";}
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$next_dial_campaign_id = $aryA[0];
$cp_ct=0;
while($SHARED_campaigns_ct > $cp_ct)
{
if ($SHARED_campaigns[$cp_ct] =~ /^$next_dial_campaign_id$/)
{
$SHARED_campaigns_agnt_dl[$cp_ct]++;
}
$cp_ct++;
}
}
$sthA->finish();
# update dial campaign for this agent vicidial_agent_dial_campaigns
$stmtA = "UPDATE vicidial_agent_dial_campaigns SET dial_time = \"$now_date\" where user='$SHARED_agents[$sh_ct]' and campaign_id='$next_dial_campaign_id';";
$affected_rows_vadc_dial = $dbhA->do($stmtA);
# update dial campaign for this agent in vicidial_live_agents
$stmtA = "UPDATE vicidial_live_agents SET dial_campaign_id='$next_dial_campaign_id' where user='$SHARED_agents[$sh_ct]';";
$affected_rows_vla_dial = $dbhA->do($stmtA);
$agent_temp = $SHARED_agents[$sh_ct];
$sh_ct++;
$agent_shared_output .= "Agent $sh_ct: $agent_temp |$next_dial_campaign_id|$affected_rows_vadc_up|$affected_rows_vadc_del|$affected_rows_vadc_dial|$affected_rows_vla_dial|\n";
}
$cp_ct=0;
$agent_shared_output .= "\nSHARED Campaigns:\n";
while($SHARED_campaigns_ct > $cp_ct)
{
$shared_camp_output="$SHARED_campaigns[$cp_ct] Drop In-Group: $SHARED_campaigns_drop_ig[$cp_ct] Shared Agents: $SHARED_campaigns_agnt_ct[$cp_ct] (Dial Agents: $SHARED_campaigns_agnt_dl[$cp_ct])";
$agent_shared_output .= "$shared_camp_output\n";
# update debug output for each campaign
$stmtA = "UPDATE vicidial_campaign_stats_debug SET entry_time='$now_date',adapt_output='$shared_camp_output' where campaign_id='$SHARED_campaigns[$cp_ct]' and server_ip='SHARED';";
$affected_rows = $dbhA->do($stmtA);
$cp_ct++;
}
# update debug output
$stmtA = "UPDATE vicidial_campaign_stats_debug SET entry_time='$now_date',adapt_output='$agent_shared_output' where campaign_id='--ALL--' and server_ip='SHARED';";
$affected_rows = $dbhA->do($stmtA);
}
}
}
sub calculate_drops
{
@@ -5998,7 +6200,7 @@ sub calculate_dial_level
$adaptive_string .= "CAMPAIGN: $campaign_id[$i] $i\n";
# COUNTS OF STATUSES OF AGENTS IN THIS CAMPAIGN
$stmtA = "SELECT count(*),status from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one' group by status;";
$stmtA = "SELECT count(*),status from vicidial_live_agents where ( (campaign_id='$campaign_id[$i]') or (dial_campaign_id='$campaign_id[$i]') $drop_ingroup_SQL[$i] ) and last_update_time > '$VDL_one' group by status;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
+129 -16
View File
@@ -135,6 +135,7 @@
# 200122-1851 - Added code for CID Group auto-rotate feature
# 200825-0032 - Include live agents from other campaigns if they have the campaign Drop-InGroup selected and drop sec < 0
# 201122-0928 - Added code for dialy call count limits
# 201218-2224 - Added code for SHARED agent campaigns
#
### begin parsing run-time options ###
@@ -367,6 +368,11 @@ if ($non_latin > 0)
$sthA->finish();
}
$stmtA = "INSERT IGNORE into vicidial_campaign_stats_debug SET campaign_id='-SHARE-',server_ip='$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthA->finish();
$one_day_interval = 12; # 1 month loops for one year
while($one_day_interval > 0)
@@ -386,12 +392,19 @@ while($one_day_interval > 0)
@DBlive_user=@MT;
@DBlive_server_ip=@MT;
@DBlive_campaign=@MT;
@DBlive_campaign_rank=@MT;
@DBlive_campaign_sort=@MT;
@DBlive_campaign_sorted=@MT;
@DBlive_dial_campaign=@MT;
@DBlive_conf_exten=@MT;
@DBlive_status=@MT;
@DBlive_call_id=@MT;
@DBlive_last_call_epoch=@MT;
@DBcampaigns=@MT;
@DBIPaddress=@MT;
@DBIPcampaign=@MT;
@DBIPcampaign_sort=@MT;
@DBIPcampaign_sorted=@MT;
@DBIPactive=@MT;
@DBIPvdadexten=@MT;
@DBIPcount=@MT;
@@ -445,6 +458,8 @@ while($one_day_interval > 0)
@DBIPdrop_call_seconds=@MT;
@DBIPdrop_action=@MT;
@DBIPdrop_inbound_group=@MT;
@DBshare_camp=@MT;
@DBshare_camp_rank=@MT;
$active_line_counter=0;
$user_counter=0;
$user_campaigns = '|';
@@ -457,6 +472,7 @@ while($one_day_interval > 0)
$LUcount=0;
$campaigns_update = '';
$CPcount=0;
$shared_dial_camp_override=0;
##### Get maximum calls per second that this process can send out
$stmtA = "SELECT outbound_calls_per_second,vicidial_recording_limit FROM servers where server_ip='$server_ip';";
@@ -481,10 +497,9 @@ while($one_day_interval > 0)
#############################################
##### Check if auto-dialing is enabled
$stmtA = "SELECT outbound_autodial_active,noanswer_log,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db FROM system_settings;";
$stmtA = "SELECT outbound_autodial_active,noanswer_log,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,disable_auto_dial,allow_shared_dial FROM system_settings;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -499,12 +514,69 @@ while($one_day_interval > 0)
$alt_log_pass = $aryA[5];
$tables_use_alt_log_db = $aryA[6];
$disable_auto_dial = $aryA[7];
$allow_shared_dial = $aryA[8];
}
$sthA->finish();
#############################################
##### Gather SHARED campaigns info
$debug_shared_output='';
$shared_SQL='';
$shared_callsTOTAL=0;
$shared_callsSERVER=0;
if ($allow_shared_dial > 0)
{
$stmtA = "SELECT campaign_id,drop_inbound_group,shared_dial_rank FROM vicidial_campaigns where active='Y' and dial_method IN('SHARED_RATIO','SHARED_ADAPT_HARD_LIMIT','SHARED_ADAPT_TAPERED','SHARED_ADAPT_AVERAGE') order by shared_dial_rank desc;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$DBshare_camp[$rec_count] = $aryA[0];
$DBshare_camp_rank[$rec_count] = $aryA[2];
if (length($DBshare_camp_rank[$rec_count])<2) {$DBshare_camp_rank[$rec_count] = "0$DBshare_camp_rank[$rec_count]";}
$shared_SQL .= "'$aryA[0]','$aryA[1]',";
$debug_shared_output .= "$aryA[0] Drop-In-Group: $aryA[1] Shared-Rank: $DBshare_camp_rank[$rec_count]\n";
$rec_count++;
}
chop($shared_SQL);
if (length($shared_SQL)<2)
{$shared_SQL="'-NONE-'";}
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where campaign_id IN($shared_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;
$shared_callsTOTAL = $aryA[0];
}
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where campaign_id IN($shared_SQL) and server_ip='$VARserver_ip';";
$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;
$shared_callsSERVER = $aryA[0];
}
$event_string="SHARED-AGENT CAMPAIGNS ON SYSTEM: $rec_count TOTAL CALLS: $shared_callsTOTAL SERVER CALLS: $shared_callsSERVER";
&event_logger;
# update debug output
$stmtA = "UPDATE vicidial_campaign_stats_debug SET entry_time='$now_date',debug_output='$event_string\n$debug_shared_output' where campaign_id='-SHARE-' and server_ip='$VARserver_ip';";
$affected_rows = $dbhA->do($stmtA);
}
$debug_shared_output='';
##### Get a listing of the users that are active and ready to take calls
##### Also get a listing of the campaigns and campaigns/serverIP that will be used
$stmtA = "SELECT user,server_ip,campaign_id,conf_exten,status,callerid FROM vicidial_live_agents where status IN($active_agents) and outbound_autodial='Y' and server_ip='$server_ip' and last_update_time > '$BDtsSQLdate' order by last_call_time";
$stmtA = "SELECT user,server_ip,campaign_id,conf_exten,status,callerid,dial_campaign_id,UNIX_TIMESTAMP(last_call_time) FROM vicidial_live_agents where status IN($active_agents) and outbound_autodial='Y' and server_ip='$server_ip' and last_update_time > '$BDtsSQLdate' order by last_call_time";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -512,13 +584,40 @@ while($one_day_interval > 0)
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$DBlive_user[$user_counter] = $aryA[0];
$DBlive_server_ip[$user_counter] = $aryA[1];
$DBlive_campaign[$user_counter] = $aryA[2];
$DBlive_conf_exten[$user_counter] = $aryA[3];
$DBlive_status[$user_counter] = $aryA[4];
$DBlive_call_id[$user_counter] = $aryA[5];
$DBlive_user[$user_counter] = $aryA[0];
$DBlive_server_ip[$user_counter] = $aryA[1];
$DBlive_campaign[$user_counter] = $aryA[2];
$DBlive_conf_exten[$user_counter] = $aryA[3];
$DBlive_status[$user_counter] = $aryA[4];
$DBlive_call_id[$user_counter] = $aryA[5];
$DBlive_dial_campaign[$user_counter] = $aryA[6];
$DBlive_last_call_epoch[$user_counter] = $aryA[7];
$DBlive_campaign_rank[$user_counter] = 0;
$DBlive_campaign_sort[$user_counter] = 0;
if (length($DBlive_dial_campaign[$user_counter]) > 0)
{
if ($DBlive_dial_campaign[$user_counter] ne $DBlive_campaign[$user_counter])
{
$shared_dial_camp_override++;
if ($DBX) {print "Shared-Dial-Agent Dial-Campaign Override: $shared_dial_camp_override/$rec_count - $DBlive_user[$user_counter] ($DBlive_campaign[$user_counter] -> $DBlive_dial_campaign[$user_counter])\n";}
$debug_shared_output .= "Agent Dial-Campaign Override: $shared_dial_camp_override/$rec_count - $DBlive_user[$user_counter] ($DBlive_campaign[$user_counter] -> $DBlive_dial_campaign[$user_counter])\n";
$DBlive_campaign[$user_counter] = $DBlive_dial_campaign[$user_counter];
}
else
{
$debug_shared_output .= "Agent Dial-Campaign No-Change: $rec_count - $DBlive_user[$user_counter] ($DBlive_campaign[$user_counter] -> $DBlive_dial_campaign[$user_counter])\n";
}
}
$temp_ct=0;
foreach(@DBshare_camp)
{
if ($DBlive_campaign[$user_counter] eq $DBshare_camp[$temp_ct])
{
$DBlive_campaign_rank[$user_counter] = $DBshare_camp_rank[$temp_ct];
}
$temp_ct++;
}
if ($user_campaigns !~ /\|$DBlive_campaign[$user_counter]\|/i)
{
if ($campaigns_update !~ /'$DBlive_campaign[$user_counter]'/) {$campaigns_update .= "'$DBlive_campaign[$user_counter]',"; $CPcount++;}
@@ -532,8 +631,12 @@ while($one_day_interval > 0)
$user_campaignIP .= "$DBlive_campaign[$user_counter]__$DBlive_server_ip[$user_counter]|";
$DBIPcampaign[$user_CIPct] = "$DBlive_campaign[$user_counter]";
$DBIPaddress[$user_CIPct] = "$DBlive_server_ip[$user_counter]";
$DBIPcampaign_sort[$user_CIPct] = $DBlive_campaign_rank[$user_counter].'_'.$DBlive_last_call_epoch[$user_counter].'_'.$DBlive_campaign[$user_counter].'_'.$user_CIPct;
if ($DBX) {print "Debug agent campaign sort: $DBIPcampaign_sort[$user_CIPct]\n";}
$user_CIPct++;
}
$DBlive_campaign_sort[$user_counter] = $DBlive_campaign_rank[$user_counter].'_'.$DBlive_last_call_epoch[$user_counter].'_'.$DBlive_campaign[$user_counter].'_'.$user_counter;
if ($DBX) {print "Debug live agent sort: $DBlive_campaign_sort[$user_counter]\n";}
$user_counter++;
$rec_count++;
}
@@ -561,9 +664,15 @@ while($one_day_interval > 0)
$event_string="OLD TRUNK SHORTS CLEARED: $UVCSSaffected_rows |$user_campaignsSQL|";
&event_logger;
}
$user_CIPct = 0;
foreach(@DBIPcampaign)
### sort campaigns by shared campaign rank, then last agent call handle time
@DBIPcampaign_sorted = sort { $a cmp $b } @DBIPcampaign_sort;
$user_CIPct_sort = 0;
foreach(@DBIPcampaign_sorted)
{
@camp_sort_line = split(/\n/,$DBIPcampaign_sorted[$user_CIPct_sort]);
$user_CIPct = $camp_sort_line[3];
$debug_string='';
$user_counter=0;
foreach(@DBlive_campaign)
@@ -607,7 +716,7 @@ while($one_day_interval > 0)
}
### get count of READY-status agents in this campaign
$stmtA = "SELECT count(*) FROM vicidial_live_agents where campaign_id='$DBIPcampaign[$user_CIPct]' and server_ip='$server_ip' and status='READY';";
$stmtA = "SELECT count(*) FROM vicidial_live_agents where ( (campaign_id='$DBIPcampaign[$user_CIPct]') or (dial_campaign_id='$DBIPcampaign[$user_CIPct]') ) and server_ip='$server_ip' and status='READY';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -741,7 +850,7 @@ while($one_day_interval > 0)
}
# BEGIN check if drop-in-group agents should be included ---NONE--- #
if ( ($DBIPdrop_call_seconds[$user_CIPct] < 0) && ($DBIPdrop_action[$user_CIPct] =~ /IN_GROUP/i) && ($DBIPdrop_inbound_group[$user_CIPct] !~ /^---NONE---$/) && (length($DBIPdrop_inbound_group[$user_CIPct]) > 0) && ($new_agent_multicampaign > 0) )
if ( ($DBIPdrop_call_seconds[$user_CIPct] < 0) && ($DBIPdrop_action[$user_CIPct] =~ /IN_GROUP/i) && ($DBIPdrop_inbound_group[$user_CIPct] !~ /^---NONE---$/) && (length($DBIPdrop_inbound_group[$user_CIPct]) > 0) && ($new_agent_multicampaign > 0) && ($DBIPdial_method[$user_CIPct] !~ /SHARED_/i) )
{
if ($DBIPcount[$user_CIPct] > 0) {$DBIPcount[$user_CIPct] = ($DBIPcount[$user_CIPct] - 1);}
if ($DBIPACTIVEcount[$user_CIPct] > 0) {$DBIPACTIVEcount[$user_CIPct] = ($DBIPACTIVEcount[$user_CIPct] - 1);}
@@ -1111,7 +1220,7 @@ while($one_day_interval > 0)
$waiting_calls_IN=0;
$waiting_calls_OUT=0;
$stmtA = "SELECT count(*),status from vicidial_live_agents where campaign_id='$DBIPcampaign[$user_CIPct]' and last_update_time > '$halfminSQLdate' group by status;";
$stmtA = "SELECT count(*),status from vicidial_live_agents where ( (campaign_id='$DBIPcampaign[$user_CIPct]') or (dial_campaign_id='$DBIPcampaign[$user_CIPct]') ) and last_update_time > '$halfminSQLdate' group by status;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
@@ -1264,7 +1373,7 @@ while($one_day_interval > 0)
$stmtA="INSERT IGNORE INTO vicidial_campaign_stats_debug SET server_ip='$server_ip',campaign_id='$DBIPcampaign[$user_CIPct]',entry_time='$now_date',debug_output='$debug_string' ON DUPLICATE KEY UPDATE entry_time='$now_date',debug_output='$debug_string';";
$affected_rows = $dbhA->do($stmtA);
$user_CIPct++;
$user_CIPct_sort++;
}
###############################################################################
@@ -4503,6 +4612,10 @@ while($one_day_interval > 0)
$bad_grabber_counter=0;
$stat_count++;
# update debug output
$stmtA = "UPDATE vicidial_campaign_stats_debug SET entry_time='$now_date',adapt_output='$debug_shared_output' where campaign_id='-SHARE-' and server_ip='$VARserver_ip';";
$affected_rows = $dbhA->do($stmtA);
}
+2 -1
View File
@@ -47,6 +47,7 @@
# 200108-1314 - Added CID Group type of NONE
# 200122-1850 - Added code for CID Group auto-rotate feature
# 201122-0932 - Added code for dialy call count limits
# 201220-1034 - Changes for shared agent campaigns
#
### begin parsing run-time options ###
@@ -602,7 +603,7 @@ while($one_day_interval > 0)
$event_string.=" Campaign Dial Fill tally: $DBfill_tally[$camp_CIPct]/$DBfill_needed[$camp_CIPct]";
&event_logger;
$stmtA = "SELECT count(*) FROM vicidial_live_agents where campaign_id='$DBfill_campaign[$camp_CIPct]' and status NOT IN('PAUSED');";
$stmtA = "SELECT count(*) FROM vicidial_live_agents where ( (campaign_id='$DBfill_campaign[$camp_CIPct]') or (dial_campaign_id='$DBfill_campaign[$camp_CIPct]') ) and status NOT IN('PAUSED');";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
+4 -3
View File
@@ -99,10 +99,11 @@
# 200814-2132 - Added support for Internation DNC scrubbing
# 201111-1359 - Added support for hopper_drop_run_trigger
# 201122-1039 - Added support for daily call count limits
# 201220-1032 - Changes for shared agent campaigns
#
# constants
$build = '201122-1039';
$build = '201220-1032';
$DB=0; # Debug flag, set to 0 for no debug messages. Can be overriden with CLI --debug flag
$US='__';
$MT[0]='';
@@ -1158,14 +1159,14 @@ while ($sthArows > $rec_count)
if ( $use_auto_hopper[$rec_count] =~ /Y/)
{
### Find the number of agents
$stmtB = "SELECT COUNT(*) FROM vicidial_live_agents WHERE campaign_id='$campaign_id[$rec_count]' and status IN ('READY','QUEUE','INCALL','CLOSER') and last_update_time >= '$VDL_tensec'";
$stmtB = "SELECT COUNT(*) FROM vicidial_live_agents WHERE ( (campaign_id='$campaign_id[$rec_count]') or (dial_campaign_id='$campaign_id[$rec_count]') ) and status IN ('READY','QUEUE','INCALL','CLOSER') and last_update_time >= '$VDL_tensec'";
$sthB = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr;
$sthB->execute or die "executing: $stmtB ", $dbhA->errstr;
@aryAgent = $sthB->fetchrow_array;
$num_agents = $aryAgent[0];
$sthB->finish();
$stmtB = "SELECT COUNT(*) FROM vicidial_live_agents WHERE campaign_id='$campaign_id[$rec_count]' and status IN ('PAUSED') and last_update_time >= '$VDL_tensec' and last_state_change >= '$VDL_one'";
$stmtB = "SELECT COUNT(*) FROM vicidial_live_agents WHERE ( (campaign_id='$campaign_id[$rec_count]') or (dial_campaign_id='$campaign_id[$rec_count]') ) and status IN ('PAUSED') and last_update_time >= '$VDL_tensec' and last_state_change >= '$VDL_one'";
$sthB = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr;
$sthB->execute or die "executing: $stmtB ", $dbhA->errstr;
@aryAgent = $sthB->fetchrow_array;