From bf858efd5a6c847219227a66528e1aa27c7ee2c8 Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 19 Sep 2006 16:54:49 +0000 Subject: [PATCH] fixed bug in AST_VDadapt.pl where it could use incorrect stats in some cases with multiple active campaigns git-svn-id: svn://192.168.202.10@289 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/bin/AST_VDadapt.pl | 383 ++++++++++++++++--------------- 1 file changed, 192 insertions(+), 191 deletions(-) diff --git a/agc_2-X/trunk/bin/AST_VDadapt.pl b/agc_2-X/trunk/bin/AST_VDadapt.pl index f0337c7e..bc8908c9 100644 --- a/agc_2-X/trunk/bin/AST_VDadapt.pl +++ b/agc_2-X/trunk/bin/AST_VDadapt.pl @@ -13,6 +13,7 @@ # 60827-0035 - separate Drop calculation and target dial level calculation into different subroutines # - alter code so that DROP percentages would calculate only about once a minute no matter he loop delay # 60828-1149 - add field for target dial_level difference, -1 would target one agent waiting, +1 would target 1 customer waiting +# 60919-1243 - changed variables to use arrays for all campaign-specific values # # constants @@ -20,43 +21,43 @@ $DB=0; # Debug flag, set to 0 for no debug messages, On an active system this w $US='__'; $MT[0]=''; +$i=0; $drop_count_updater=0; -$VCScalls_today=0; -$VCSdrops_today=0; -$VCSdrops_today_pct=0; -$VCScalls_hour=0; -$VCSdrops_hour=0; -$VCSdrops_hour_pct=0; -$VCScalls_halfhour=0; -$VCSdrops_halfhour=0; -$VCSdrops_halfhour_pct=0; -$VCScalls_five=0; -$VCSdrops_five=0; -$VCSdrops_five_pct=0; -$VCScalls_one=0; -$VCSdrops_one=0; -$VCSdrops_one_pct=0; -$total_agents=0; -$ready_agents=0; -$waiting_calls=0; $stat_it=15; -$ready_diff_total=0; -$waiting_diff_total=0; -$total_agents_total=0; -$ready_diff_avg=0; -$waiting_diff_avg=0; -$total_agents_avg=0; -$stat_differential=0; -$diff_ratio_updater=0; -$VCSINCALL=0; -$VCSREADY=0; -$VCSCLOSER=0; -$VCSPAUSED=0; -$VCSagents=0; -$VCSagents_calc=0; -$VCSagents_active=0; $diff_ratio_updater=0; $stat_count=1; +$VCScalls_today[$i]=0; +$VCSdrops_today[$i]=0; +$VCSdrops_today_pct[$i]=0; +$VCScalls_hour[$i]=0; +$VCSdrops_hour[$i]=0; +$VCSdrops_hour_pct[$i]=0; +$VCScalls_halfhour[$i]=0; +$VCSdrops_halfhour[$i]=0; +$VCSdrops_halfhour_pct[$i]=0; +$VCScalls_five[$i]=0; +$VCSdrops_five[$i]=0; +$VCSdrops_five_pct[$i]=0; +$VCScalls_one[$i]=0; +$VCSdrops_one[$i]=0; +$VCSdrops_one_pct[$i]=0; +$total_agents[$i]=0; +$ready_agents[$i]=0; +$waiting_calls[$i]=0; +$ready_diff_total[$i]=0; +$waiting_diff_total[$i]=0; +$total_agents_total[$i]=0; +$ready_diff_avg[$i]=0; +$waiting_diff_avg[$i]=0; +$total_agents_avg[$i]=0; +$stat_differential[$i]=0; +$VCSINCALL[$i]=0; +$VCSREADY[$i]=0; +$VCSCLOSER[$i]=0; +$VCSPAUSED[$i]=0; +$VCSagents[$i]=0; +$VCSagents_calc[$i]=0; +$VCSagents_active[$i]=0; # set to 61 initially so that a baseline drop count is pulled $drop_count_updater=61; @@ -286,7 +287,7 @@ while ($master_loop<$CLIloops) @lead_filter_id=@MT; @use_internal_dnc=@MT; @dial_method=@MT; -@available_only_ratio_tally=@MT; +@available_only_ratio_tally[$i]=@MT; @adaptive_dropped_percentage=@MT; @adaptive_maximum_level=@MT; @adaptive_latest_server_time=@MT; @@ -324,7 +325,7 @@ while ($sthArows > $rec_count) $lead_filter_id[$rec_count] = "$aryA[35]"; $use_internal_dnc[$rec_count] = "$aryA[43]"; $dial_method[$rec_count] = $aryA[46]; - $available_only_ratio_tally[$rec_count] = $aryA[47]; + $available_only_ratio_tally[$i][$rec_count] = $aryA[47]; $adaptive_dropped_percentage[$rec_count] = $aryA[48]; $adaptive_maximum_level[$rec_count] = $aryA[49]; $adaptive_latest_server_time[$rec_count] = $aryA[50]; @@ -366,8 +367,8 @@ foreach(@campaign_id) { ### BEGIN - GATHER STATS FOR THE vicidial_campaign_stats TABLE ### $vicidial_log = 'vicidial_log'; - $differential_onemin=0; - $agents_average_onemin=0; + $differential_onemin[$i]=0; + $agents_average_onemin[$i]=0; ### Grab the count of agents and lines if ($campaign_id[$i] !~ /CLOSER/) @@ -379,7 +380,7 @@ foreach(@campaign_id) if ($DB) {print " CLOSER CAMPAIGN\n";} } - if ($total_agents_avg > 0) + if ($total_agents_avg[$i] > 0) { ### Update Drop counter every 60 seconds if ($drop_count_updater>=60) @@ -515,17 +516,17 @@ $VDL_one = "$Vyear-$Vmon-$Vmday $Vhour:$Vmin:$Vsec"; sub count_agents_lines { ### Calculate campaign-wide agent waiting and calls waiting differential -$total_agents=0; -$ready_agents=0; -$waiting_calls=0; $stat_it=15; -$ready_diff_total=0; -$waiting_diff_total=0; -$total_agents_total=0; -$ready_diff_avg=0; -$waiting_diff_avg=0; -$total_agents_avg=0; -$stat_differential=0; +$total_agents[$i]=0; +$ready_agents[$i]=0; +$waiting_calls[$i]=0; +$ready_diff_total[$i]=0; +$waiting_diff_total[$i]=0; +$total_agents_total[$i]=0; +$ready_diff_avg[$i]=0; +$waiting_diff_avg[$i]=0; +$total_agents_avg[$i]=0; +$stat_differential[$i]=0; $stmtA = "SELECT count(*),status from vicidial_live_agents where campaign_id='$campaign_id[$i]' and last_update_time > '$VDL_one' group by status;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -535,11 +536,11 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCSagent_count = "$aryA[0]"; - $VCSagent_status = "$aryA[1]"; + $VCSagent_count[$i] = "$aryA[0]"; + $VCSagent_status[$i] = "$aryA[1]"; $rec_count++; - if ($VCSagent_status =~ /READY|DONE/) {$ready_agents = ($ready_agents + $VCSagent_count);} - $total_agents = ($total_agents + $VCSagent_count); + if ($VCSagent_status[$i] =~ /READY|DONE/) {$ready_agents[$i] = ($ready_agents[$i] + $VCSagent_count[$i]);} + $total_agents[$i] = ($total_agents[$i] + $VCSagent_count[$i]); } $sthA->finish(); @@ -551,14 +552,14 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $waiting_calls = "$aryA[0]"; + $waiting_calls[$i] = "$aryA[0]"; $rec_count++; } $sthA->finish(); -$stat_ready_agents[$i][$stat_count] = $ready_agents; -$stat_waiting_calls[$i][$stat_count] = $waiting_calls; -$stat_total_agents[$i][$stat_count] = $total_agents; +$stat_ready_agents[$i][$stat_count] = $ready_agents[$i]; +$stat_waiting_calls[$i][$stat_count] = $waiting_calls[$i]; +$stat_total_agents[$i][$stat_count] = $total_agents[$i]; if ($stat_count < 15) { @@ -574,30 +575,30 @@ $it=0; while($it < $stat_it) { $it_ary = ($it + $stat_B); - $ready_diff_total = ($ready_diff_total + $stat_ready_agents[$i][$it_ary]); - $waiting_diff_total = ($waiting_diff_total + $stat_waiting_calls[$i][$it_ary]); - $total_agents_total = ($total_agents_total + $stat_total_agents[$i][$it_ary]); + $ready_diff_total[$i] = ($ready_diff_total[$i] + $stat_ready_agents[$i][$it_ary]); + $waiting_diff_total[$i] = ($waiting_diff_total[$i] + $stat_waiting_calls[$i][$it_ary]); + $total_agents_total[$i] = ($total_agents_total[$i] + $stat_total_agents[$i][$it_ary]); # $event_string="$stat_count $it_ary $stat_total_agents[$i][$it_ary]|$stat_ready_agents[$i][$it_ary]|$stat_waiting_calls[$i][$it_ary]"; # if ($DB) {print " $event_string\n";} # &event_logger; $it++; } -if ($ready_diff_total > 0) - {$ready_diff_avg = ($ready_diff_total / $stat_it);} -if ($waiting_diff_total > 0) - {$waiting_diff_avg = ($waiting_diff_total / $stat_it);} -if ($total_agents_total > 0) - {$total_agents_avg = ($total_agents_total / $stat_it);} -$stat_differential = ($ready_diff_avg - $waiting_diff_avg); +if ($ready_diff_total[$i] > 0) + {$ready_diff_avg[$i] = ($ready_diff_total[$i] / $stat_it);} +if ($waiting_diff_total[$i] > 0) + {$waiting_diff_avg[$i] = ($waiting_diff_total[$i] / $stat_it);} +if ($total_agents_total[$i] > 0) + {$total_agents_avg[$i] = ($total_agents_total[$i] / $stat_it);} +$stat_differential[$i] = ($ready_diff_avg[$i] - $waiting_diff_avg[$i]); -$event_string="CAMPAIGN DIFFERENTIAL: $total_agents_avg $stat_differential ($ready_diff_avg - $waiting_diff_avg)"; +$event_string="CAMPAIGN DIFFERENTIAL: $total_agents_avg[$i] $stat_differential[$i] ($ready_diff_avg[$i] - $waiting_diff_avg[$i])"; if ($DBX) {print "$campaign_id[$i]|$event_string\n";} if ($DB) {print " $event_string\n";} &event_logger; -# $stmtA = "UPDATE vicidial_campaign_stats SET differential_onemin='$stat_differential', agents_average_onemin='$total_agents_avg' where campaign_id='$DBIPcampaign[$i]';"; +# $stmtA = "UPDATE vicidial_campaign_stats SET differential_onemin[$i]='$stat_differential[$i]', agents_average_onemin[$i]='$total_agents_avg[$i]' where campaign_id='$DBIPcampaign[$i]';"; # $affected_rows = $dbhA->do($stmtA); } @@ -605,21 +606,21 @@ if ($DB) {print " $event_string\n";} sub calculate_drops { $RESETdrop_count_updater++; -$VCScalls_today=0; -$VCSdrops_today=0; -$VCSdrops_today_pct=0; -$VCScalls_hour=0; -$VCSdrops_hour=0; -$VCSdrops_hour_pct=0; -$VCScalls_halfhour=0; -$VCSdrops_halfhour=0; -$VCSdrops_halfhour_pct=0; -$VCScalls_five=0; -$VCSdrops_five=0; -$VCSdrops_five_pct=0; -$VCScalls_one=0; -$VCSdrops_one=0; -$VCSdrops_one_pct=0; +$VCScalls_today[$i]=0; +$VCSdrops_today[$i]=0; +$VCSdrops_today_pct[$i]=0; +$VCScalls_hour[$i]=0; +$VCSdrops_hour[$i]=0; +$VCSdrops_hour_pct[$i]=0; +$VCScalls_halfhour[$i]=0; +$VCSdrops_halfhour[$i]=0; +$VCSdrops_halfhour_pct[$i]=0; +$VCScalls_five[$i]=0; +$VCSdrops_five[$i]=0; +$VCSdrops_five_pct[$i]=0; +$VCScalls_one[$i]=0; +$VCSdrops_one[$i]=0; +$VCSdrops_one_pct[$i]=0; # LAST ONE MINUTE CALL AND DROP STATS $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_one';"; @@ -630,11 +631,11 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCScalls_one = "$aryA[0]"; + $VCScalls_one[$i] = "$aryA[0]"; $rec_count++; } $sthA->finish(); -if ($VCScalls_one > 0) +if ($VCScalls_one[$i] > 0) { $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_one' and status IN('DROP','XDROP');"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -644,11 +645,11 @@ if ($VCScalls_one > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCSdrops_one = "$aryA[0]"; - if ($VCSdrops_one > 0) + $VCSdrops_one[$i] = "$aryA[0]"; + if ($VCSdrops_one[$i] > 0) { - $VCSdrops_one_pct = ( ($VCSdrops_one / $VCScalls_one) * 100 ); - $VCSdrops_one_pct = sprintf("%.2f", $VCSdrops_one_pct); + $VCSdrops_one_pct[$i] = ( ($VCSdrops_one[$i] / $VCScalls_one[$i]) * 100 ); + $VCSdrops_one_pct[$i] = sprintf("%.2f", $VCSdrops_one_pct[$i]); } $rec_count++; } @@ -664,11 +665,11 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCScalls_today = "$aryA[0]"; + $VCScalls_today[$i] = "$aryA[0]"; $rec_count++; } $sthA->finish(); -if ($VCScalls_today > 0) +if ($VCScalls_today[$i] > 0) { $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; @@ -678,11 +679,11 @@ if ($VCScalls_today > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCSdrops_today = "$aryA[0]"; - if ($VCSdrops_today > 0) + $VCSdrops_today[$i] = "$aryA[0]"; + if ($VCSdrops_today[$i] > 0) { - $VCSdrops_today_pct = ( ($VCSdrops_today / $VCScalls_today) * 100 ); - $VCSdrops_today_pct = sprintf("%.2f", $VCSdrops_today_pct); + $VCSdrops_today_pct[$i] = ( ($VCSdrops_today[$i] / $VCScalls_today[$i]) * 100 ); + $VCSdrops_today_pct[$i] = sprintf("%.2f", $VCSdrops_today_pct[$i]); } $rec_count++; } @@ -698,11 +699,11 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCScalls_hour = "$aryA[0]"; + $VCScalls_hour[$i] = "$aryA[0]"; $rec_count++; } $sthA->finish(); -if ($VCScalls_hour > 0) +if ($VCScalls_hour[$i] > 0) { $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_hour' and status IN('DROP','XDROP');"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -712,11 +713,11 @@ if ($VCScalls_hour > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCSdrops_hour = "$aryA[0]"; - if ($VCSdrops_hour > 0) + $VCSdrops_hour[$i] = "$aryA[0]"; + if ($VCSdrops_hour[$i] > 0) { - $VCSdrops_hour_pct = ( ($VCSdrops_hour / $VCScalls_hour) * 100 ); - $VCSdrops_hour_pct = sprintf("%.2f", $VCSdrops_hour_pct); + $VCSdrops_hour_pct[$i] = ( ($VCSdrops_hour[$i] / $VCScalls_hour[$i]) * 100 ); + $VCSdrops_hour_pct[$i] = sprintf("%.2f", $VCSdrops_hour_pct[$i]); } $rec_count++; } @@ -732,11 +733,11 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCScalls_halfhour = "$aryA[0]"; + $VCScalls_halfhour[$i] = "$aryA[0]"; $rec_count++; } $sthA->finish(); -if ($VCScalls_halfhour > 0) +if ($VCScalls_halfhour[$i] > 0) { $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_halfhour' and status IN('DROP','XDROP');"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -746,11 +747,11 @@ if ($VCScalls_halfhour > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCSdrops_halfhour = "$aryA[0]"; - if ($VCSdrops_halfhour > 0) + $VCSdrops_halfhour[$i] = "$aryA[0]"; + if ($VCSdrops_halfhour[$i] > 0) { - $VCSdrops_halfhour_pct = ( ($VCSdrops_halfhour / $VCScalls_halfhour) * 100 ); - $VCSdrops_halfhour_pct = sprintf("%.2f", $VCSdrops_halfhour_pct); + $VCSdrops_halfhour_pct[$i] = ( ($VCSdrops_halfhour[$i] / $VCScalls_halfhour[$i]) * 100 ); + $VCSdrops_halfhour_pct[$i] = sprintf("%.2f", $VCSdrops_halfhour_pct[$i]); } $rec_count++; } @@ -766,11 +767,11 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCScalls_five = "$aryA[0]"; + $VCScalls_five[$i] = "$aryA[0]"; $rec_count++; } $sthA->finish(); -if ($VCScalls_five > 0) +if ($VCScalls_five[$i] > 0) { $stmtA = "SELECT count(*) from $vicidial_log where campaign_id='$campaign_id[$i]' and call_date > '$VDL_five' and status IN('DROP','XDROP');"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; @@ -780,17 +781,17 @@ if ($VCScalls_five > 0) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCSdrops_five = "$aryA[0]"; - if ($VCSdrops_five > 0) + $VCSdrops_five[$i] = "$aryA[0]"; + if ($VCSdrops_five[$i] > 0) { - $VCSdrops_five_pct = ( ($VCSdrops_five / $VCScalls_five) * 100 ); - $VCSdrops_five_pct = sprintf("%.2f", $VCSdrops_five_pct); + $VCSdrops_five_pct[$i] = ( ($VCSdrops_five[$i] / $VCScalls_five[$i]) * 100 ); + $VCSdrops_five_pct[$i] = sprintf("%.2f", $VCSdrops_five_pct[$i]); } $rec_count++; } $sthA->finish(); } -if ($DBX) {print "$campaign_id[$i]|$VCSdrops_five_pct|$VCSdrops_today_pct\n";} +if ($DBX) {print "$campaign_id[$i]|$VCSdrops_five_pct[$i]|$VCSdrops_today_pct[$i]\n";} } @@ -799,13 +800,13 @@ if ($DBX) {print "$campaign_id[$i]|$VCSdrops_five_pct|$VCSdrops_today_pct\n";} sub calculate_dial_level { $RESETdiff_ratio_updater++; -$VCSINCALL=0; -$VCSREADY=0; -$VCSCLOSER=0; -$VCSPAUSED=0; -$VCSagents=0; -$VCSagents_calc=0; -$VCSagents_active=0; +$VCSINCALL[$i]=0; +$VCSREADY[$i]=0; +$VCSCLOSER[$i]=0; +$VCSPAUSED[$i]=0; +$VCSagents[$i]=0; +$VCSagents_calc[$i]=0; +$VCSagents_active[$i]=0; # COUNTS OF STATUSES OF AGENTS IN THIS CAMPAIGN $stmtA = "SELECT count(*),status from vicidial_live_agents where campaign_id='$campaign_id[$i]' and last_update_time > '$VDL_one' group by status;"; @@ -816,29 +817,29 @@ $rec_count=0; while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $VCSagent_count = "$aryA[0]"; - $VCSagent_status = "$aryA[1]"; + $VCSagent_count[$i] = "$aryA[0]"; + $VCSagent_status[$i] = "$aryA[1]"; $rec_count++; - if ($VCSagent_status =~ /INCALL|QUEUE/) {$VCSINCALL = ($VCSINCALL + $VCSagent_count);} - if ($VCSagent_status =~ /READY/) {$VCSREADY = ($VCSREADY + $VCSagent_count);} - if ($VCSagent_status =~ /CLOSER/) {$VCSCLOSER = ($VCSCLOSER + $VCSagent_count);} - if ($VCSagent_status =~ /PAUSED/) {$VCSPAUSED = ($VCSPAUSED + $VCSagent_count);} - $VCSagents = ($VCSagents + $VCSagent_count); + if ($VCSagent_status[$i] =~ /INCALL|QUEUE/) {$VCSINCALL[$i] = ($VCSINCALL[$i] + $VCSagent_count[$i]);} + if ($VCSagent_status[$i] =~ /READY/) {$VCSREADY[$i] = ($VCSREADY[$i] + $VCSagent_count[$i]);} + if ($VCSagent_status[$i] =~ /CLOSER/) {$VCSCLOSER[$i] = ($VCSCLOSER[$i] + $VCSagent_count[$i]);} + if ($VCSagent_status[$i] =~ /PAUSED/) {$VCSPAUSED[$i] = ($VCSPAUSED[$i] + $VCSagent_count[$i]);} + $VCSagents[$i] = ($VCSagents[$i] + $VCSagent_count[$i]); } $sthA->finish(); -if ($available_only_ratio_tally =~ /Y/) - {$VCSagents_calc = $VCSREADY;} +if ($available_only_ratio_tally[$i] =~ /Y/) + {$VCSagents_calc[$i] = $VCSREADY[$i];} else - {$VCSagents_calc = ($VCSINCALL + $VCSREADY);} -$VCSagents_active = ($VCSINCALL + $VCSREADY + $VCSCLOSER); + {$VCSagents_calc[$i] = ($VCSINCALL[$i] + $VCSREADY[$i]);} +$VCSagents_active[$i] = ($VCSINCALL[$i] + $VCSREADY[$i] + $VCSCLOSER[$i]); ### END - GATHER STATS FOR THE vicidial_campaign_stats TABLE ### if ($campaign_id[$i] =~ /CLOSER/) { # GET AVERAGES FROM THIS CAMPAIGN - $stmtA = "SELECT differential_onemin,agents_average_onemin from vicidial_campaign_stats where campaign_id='$campaign_id[$i]';"; + $stmtA = "SELECT differential_onemin[$i],agents_average_onemin[$i] from vicidial_campaign_stats where campaign_id='$campaign_id[$i]';"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -846,20 +847,20 @@ if ($campaign_id[$i] =~ /CLOSER/) while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $differential_onemin = "$aryA[0]"; - $agents_average_onemin = "$aryA[1]"; + $differential_onemin[$i] = "$aryA[0]"; + $agents_average_onemin[$i] = "$aryA[1]"; $rec_count++; } $sthA->finish(); } else { - $agents_average_onemin = $total_agents_avg; - $differential_onemin = $stat_differential; + $agents_average_onemin[$i] = $total_agents_avg[$i]; + $differential_onemin[$i] = $stat_differential[$i]; } ## UPDATE STATS FOR CAMPAIGN -$stmtA = "UPDATE vicidial_campaign_stats SET calls_today='$VCScalls_today',drops_today='$VCSdrops_today',drops_today_pct='$VCSdrops_today_pct',calls_hour='$VCScalls_hour',drops_hour='$VCSdrops_hour',drops_hour_pct='$VCSdrops_hour_pct',calls_halfhour='$VCScalls_halfhour',drops_halfhour='$VCSdrops_halfhour',drops_halfhour_pct='$VCSdrops_halfhour_pct',calls_fivemin='$VCScalls_five',drops_fivemin='$VCSdrops_five',drops_fivemin_pct='$VCSdrops_five_pct',calls_onemin='$VCScalls_one',drops_onemin='$VCSdrops_one',drops_onemin_pct='$VCSdrops_one_pct' where campaign_id='$campaign_id[$i]';"; +$stmtA = "UPDATE vicidial_campaign_stats SET calls_today='$VCScalls_today[$i]',drops_today='$VCSdrops_today[$i]',drops_today_pct='$VCSdrops_today_pct[$i]',calls_hour='$VCScalls_hour[$i]',drops_hour='$VCSdrops_hour[$i]',drops_hour_pct='$VCSdrops_hour_pct[$i]',calls_halfhour='$VCScalls_halfhour[$i]',drops_halfhour='$VCSdrops_halfhour[$i]',drops_halfhour_pct='$VCSdrops_halfhour_pct[$i]',calls_fivemin='$VCScalls_five[$i]',drops_fivemin='$VCSdrops_five[$i]',drops_fivemin_pct='$VCSdrops_five_pct[$i]',calls_onemin='$VCScalls_one[$i]',drops_onemin='$VCSdrops_one[$i]',drops_onemin_pct='$VCSdrops_one_pct[$i]' where campaign_id='$campaign_id[$i]';"; $affected_rows = $dbhA->do($stmtA); if ($DBX) {print "$campaign_id[$i]|$stmtA|\n";} @@ -867,39 +868,39 @@ if ($DBX) {print "$campaign_id[$i]|$stmtA|\n";} if ( ($dial_method[$i] =~ /ADAPT_HARD_LIMIT|ADAPT_AVERAGE|ADAPT_TAPERED/) || ($force_test>0) ) { # Calculate the optimal dial_level differential for the past minute - $differential_target = ($differential_onemin + $adaptive_dl_diff_target[$i]); - $differential_mul = ($differential_target / $agents_average_onemin); - $differential_pct_raw = ($differential_mul * 100); - $differential_pct = sprintf("%.2f", $differential_pct_raw); + $differential_target[$i] = ($differential_onemin[$i] + $adaptive_dl_diff_target[$i]); + $differential_mul[$i] = ($differential_target[$i] / $agents_average_onemin[$i]); + $differential_pct_raw[$i] = ($differential_mul[$i] * 100); + $differential_pct[$i] = sprintf("%.2f", $differential_pct_raw[$i]); # Factor in the intensity setting - $intensity_mul = ($adaptive_intensity[$i] / 100); - if ($differential_pct_raw < 0) + $intensity_mul[$i] = ($adaptive_intensity[$i] / 100); + if ($differential_pct_raw[$i] < 0) { - $abs_intensity_mul = abs($intensity_mul - 1); - $intensity_diff = ($differential_pct_raw * $abs_intensity_mul); + $abs_intensity_mul[$i] = abs($intensity_mul[$i] - 1); + $intensity_diff[$i] = ($differential_pct_raw[$i] * $abs_intensity_mul[$i]); } else - {$intensity_diff = ($differential_pct_raw * ($intensity_mul + 1) );} - $intensity_pct = sprintf("%.2f", $intensity_diff); - $intensity_diff_mul = ($intensity_diff / 100); + {$intensity_diff[$i] = ($differential_pct_raw[$i] * ($intensity_mul[$i] + 1) );} + $intensity_pct[$i] = sprintf("%.2f", $intensity_diff[$i]); + $intensity_diff_mul[$i] = ($intensity_diff[$i] / 100); # Suggested dial_level based on differential - $suggested_dial_level = ($auto_dial_level[$i] * ($differential_mul + 1) ); - $suggested_dial_level = sprintf("%.3f", $suggested_dial_level); + $suggested_dial_level[$i] = ($auto_dial_level[$i] * ($differential_mul[$i] + 1) ); + $suggested_dial_level[$i] = sprintf("%.3f", $suggested_dial_level[$i]); # Suggested dial_level based on differential with intensity setting - $intensity_dial_level = ($auto_dial_level[$i] * ($intensity_diff_mul + 1) ); - $intensity_dial_level = sprintf("%.3f", $intensity_dial_level); + $intensity_dial_level[$i] = ($auto_dial_level[$i] * ($intensity_diff_mul[$i] + 1) ); + $intensity_dial_level[$i] = sprintf("%.3f", $intensity_dial_level[$i]); # Calculate last timezone target for ADAPT_TAPERED - $last_target_hour_final = $adaptive_latest_server_time[$i]; -# if ($last_target_hour_final>2400) {$last_target_hour_final=2400;} - $tapered_hours_left = ($last_target_hour_final - $current_hourmin); - if ($tapered_hours_left > 1000) - {$tapered_rate = 1;} + $last_target_hour_final[$i] = $adaptive_latest_server_time[$i]; +# if ($last_target_hour_final[$i]>2400) {$last_target_hour_final[$i]=2400;} + $tapered_hours_left[$i] = ($last_target_hour_final[$i] - $current_hourmin); + if ($tapered_hours_left[$i] > 1000) + {$tapered_rate[$i] = 1;} else - {$tapered_rate = ($tapered_hours_left / 1000);} + {$tapered_rate[$i] = ($tapered_hours_left[$i] / 1000);} $adaptive_string = "\n"; $adaptive_string .= "CAMPAIGN: $campaign_id[$i]\n"; @@ -910,82 +911,82 @@ if ( ($dial_method[$i] =~ /ADAPT_HARD_LIMIT|ADAPT_AVERAGE|ADAPT_TAPERED/) || ($f $adaptive_string .= " DROP PERCENT: $adaptive_dropped_percentage[$i]\n"; $adaptive_string .= " MAX LEVEL: $adaptive_maximum_level[$i]\n"; $adaptive_string .= " SERVER TIME: $current_hourmin\n"; - $adaptive_string .= " LATE TARGET: $last_target_hour_final ($tapered_hours_left left|$tapered_rate)\n"; + $adaptive_string .= " LATE TARGET: $last_target_hour_final[$i] ($tapered_hours_left[$i] left|$tapered_rate[$i])\n"; $adaptive_string .= " INTENSITY: $adaptive_intensity[$i]\n"; $adaptive_string .= " DLDIFF TARGET: $adaptive_dl_diff_target[$i]\n"; $adaptive_string .= "CURRENT STATS-\n"; - $adaptive_string .= " AVG AGENTS: $agents_average_onemin\n"; - $adaptive_string .= " AGENTS: $VCSagents ACTIVE: $VCSagents_active CALC: $VCSagents_calc INCALL: $VCSINCALL READY: $VCSREADY\n"; - $adaptive_string .= " DL DIFFERENTIAL: $differential_target = ($differential_onemin + $adaptive_dl_diff_target[$i])\n"; + $adaptive_string .= " AVG AGENTS: $agents_average_onemin[$i]\n"; + $adaptive_string .= " AGENTS: $VCSagents[$i] ACTIVE: $VCSagents_active[$i] CALC: $VCSagents_calc[$i] INCALL: $VCSINCALL[$i] READY: $VCSREADY[$i]\n"; + $adaptive_string .= " DL DIFFERENTIAL: $differential_target[$i] = ($differential_onemin[$i] + $adaptive_dl_diff_target[$i])\n"; $adaptive_string .= "DIAL LEVEL SUGGESTION-\n"; - $adaptive_string .= " PERCENT DIFF: $differential_pct\n"; - $adaptive_string .= " SUGGEST DL: $suggested_dial_level = ($auto_dial_level[$i] * ($differential_mul + 1) )\n"; - $adaptive_string .= " INTENSE DIFF: $intensity_pct\n"; - $adaptive_string .= " INTENSE DL: $intensity_dial_level = ($auto_dial_level[$i] * ($intensity_diff_mul + 1) )\n"; - if ($intensity_dial_level > $adaptive_maximum_level[$i]) + $adaptive_string .= " PERCENT DIFF: $differential_pct[$i]\n"; + $adaptive_string .= " SUGGEST DL: $suggested_dial_level[$i] = ($auto_dial_level[$i] * ($differential_mul[$i] + 1) )\n"; + $adaptive_string .= " INTENSE DIFF: $intensity_pct[$i]\n"; + $adaptive_string .= " INTENSE DL: $intensity_dial_level[$i] = ($auto_dial_level[$i] * ($intensity_diff_mul[$i] + 1) )\n"; + if ($intensity_dial_level[$i] > $adaptive_maximum_level[$i]) { $adaptive_string .= " DIAL LEVEL OVER CAP! SETTING TO CAP: $adaptive_maximum_level[$i]\n"; - $intensity_dial_level = $adaptive_maximum_level[$i]; + $intensity_dial_level[$i] = $adaptive_maximum_level[$i]; } - if ($intensity_dial_level < 1) + if ($intensity_dial_level[$i] < 1) { $adaptive_string .= " DIAL LEVEL TOO LOW! SETTING TO 1\n"; - $intensity_dial_level = "1.0"; + $intensity_dial_level[$i] = "1.0"; } $adaptive_string .= "DROP STATS-\n"; - $adaptive_string .= " TODAY DROPS: $VCScalls_today $VCSdrops_today $VCSdrops_today_pct%\n"; - $adaptive_string .= " ONE HOUR DROPS: $VCScalls_hour $VCSdrops_hour $VCSdrops_hour_pct%\n"; - $adaptive_string .= " HALF HOUR DROPS: $VCScalls_halfhour $VCSdrops_halfhour $VCSdrops_halfhour_pct%\n"; - $adaptive_string .= " FIVE MIN DROPS: $VCScalls_five $VCSdrops_five $VCSdrops_five_pct%\n"; - $adaptive_string .= " ONE MIN DROPS: $VCScalls_one $VCSdrops_one $VCSdrops_one_pct%\n"; + $adaptive_string .= " TODAY DROPS: $VCScalls_today[$i] $VCSdrops_today[$i] $VCSdrops_today_pct[$i]%\n"; + $adaptive_string .= " ONE HOUR DROPS: $VCScalls_hour[$i] $VCSdrops_hour[$i] $VCSdrops_hour_pct[$i]%\n"; + $adaptive_string .= " HALF HOUR DROPS: $VCScalls_halfhour[$i] $VCSdrops_halfhour[$i] $VCSdrops_halfhour_pct[$i]%\n"; + $adaptive_string .= " FIVE MIN DROPS: $VCScalls_five[$i] $VCSdrops_five[$i] $VCSdrops_five_pct[$i]%\n"; + $adaptive_string .= " ONE MIN DROPS: $VCScalls_one[$i] $VCSdrops_one[$i] $VCSdrops_one_pct[$i]%\n"; ### DROP PERCENTAGE RULES TO LOWER DIAL_LEVEL ### - if ( ($VCScalls_one > 20) && ($VCSdrops_one_pct > 50) ) + if ( ($VCScalls_one[$i] > 20) && ($VCSdrops_one_pct[$i] > 50) ) { - $intensity_dial_level = ($intensity_dial_level / 2); - $adaptive_string .= " DROP RATE OVER 50% FOR LAST MINUTE! CUTTING DIAL LEVEL TO: $intensity_dial_level\n"; + $intensity_dial_level[$i] = ($intensity_dial_level[$i] / 2); + $adaptive_string .= " DROP RATE OVER 50% FOR LAST MINUTE! CUTTING DIAL LEVEL TO: $intensity_dial_level[$i]\n"; } - if ( ($VCScalls_today > 50) && ($VCSdrops_today_pct > $adaptive_dropped_percentage[$i]) ) + if ( ($VCScalls_today[$i] > 50) && ($VCSdrops_today_pct[$i] > $adaptive_dropped_percentage[$i]) ) { if ($dial_method[$i] =~ /ADAPT_HARD_LIMIT/) { - $intensity_dial_level = "1.0"; + $intensity_dial_level[$i] = "1.0"; $adaptive_string .= " DROP RATE OVER HARD LIMIT FOR TODAY! HARD DIAL LEVEL TO: 1.0\n"; } if ($dial_method[$i] =~ /ADAPT_AVERAGE/) { - $intensity_dial_level = ($intensity_dial_level / 2); - $adaptive_string .= " DROP RATE OVER LIMIT FOR TODAY! AVERAGING DIAL LEVEL TO: $intensity_dial_level\n"; + $intensity_dial_level[$i] = ($intensity_dial_level[$i] / 2); + $adaptive_string .= " DROP RATE OVER LIMIT FOR TODAY! AVERAGING DIAL LEVEL TO: $intensity_dial_level[$i]\n"; } if ($dial_method[$i] =~ /ADAPT_TAPERED/) { - if ($tapered_hours_left < 0) + if ($tapered_hours_left[$i] < 0) { - $intensity_dial_level = "1.0"; + $intensity_dial_level[$i] = "1.0"; $adaptive_string .= " DROP RATE OVER LAST HOUR LIMIT FOR TODAY! TAPERING DIAL LEVEL TO: 1.0\n"; } else { - $intensity_dial_level = ($intensity_dial_level * $tapered_rate); - $adaptive_string .= " DROP RATE OVER LIMIT FOR TODAY! TAPERING DIAL LEVEL TO: $intensity_dial_level\n"; + $intensity_dial_level[$i] = ($intensity_dial_level[$i] * $tapered_rate[$i]); + $adaptive_string .= " DROP RATE OVER LIMIT FOR TODAY! TAPERING DIAL LEVEL TO: $intensity_dial_level[$i]\n"; } } } ### ALWAYS RAISE DIAL_LEVEL TO 1.0 IF IT IS LOWER ### - if ($intensity_dial_level < 1) + if ($intensity_dial_level[$i] < 1) { $adaptive_string .= " DIAL LEVEL TOO LOW! SETTING TO 1\n"; - $intensity_dial_level = "1.0"; + $intensity_dial_level[$i] = "1.0"; } if (!$TEST) { - $stmtA = "UPDATE vicidial_campaigns SET auto_dial_level='$intensity_dial_level' where campaign_id='$campaign_id[$i]';"; + $stmtA = "UPDATE vicidial_campaigns SET auto_dial_level='$intensity_dial_level[$i]' where campaign_id='$campaign_id[$i]';"; $Uaffected_rows = $dbhA->do($stmtA); } - $adaptive_string .= "DIAL LEVEL UPDATED TO: $intensity_dial_level CONFIRM: $Uaffected_rows\n"; + $adaptive_string .= "DIAL LEVEL UPDATED TO: $intensity_dial_level[$i] CONFIRM: $Uaffected_rows\n"; } if ($DB) {print "campaign stats updated: $campaign_id[$i] $adaptive_string\n";}