From 560e4fea22713df23610ee516289439e785bb8ff Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 25 May 2010 13:51:26 +0000 Subject: [PATCH] support for calculating estimated hold wait time based on new circ estimated wait field git-svn-id: svn://svn.open-ils.org/ILS/trunk@16493 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Circ/Holds.pm | 47 +++++++++++++++++----- Open-ILS/src/perlmods/OpenILS/Const.pm | 2 +- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index a8dbb47dd9..a1c6caed5e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -1055,21 +1055,50 @@ sub retrieve_hold_queue_status_impl { $qpos++; } - # total count of potential copies - my $num_potentials = $e->json_query({ - select => {ahcm => [{column => 'id', transform => 'count', alias => 'count'}]}, - from => 'ahcm', - where => {hold => $hold->id} - })->[0]; + my $hold_data = $e->json_query({ + select => { + ccm => [ + {column => 'code', transform => 'count', aggregate => 1, alias => 'count'}, + {column =>'avg_wait_time'} + ] + }, + from => {ahcm => {acp => {join => 'ccm'}}}, + where => {'+ahcm' => {hold => $hold->id}} + }); my $user_org = $e->json_query({select => {au => ['home_ou']}, from => 'au', where => {id => $hold->usr}})->[0]->{home_ou}; - my $default_hold_interval = $U->ou_ancestor_setting_value($user_org, OILS_SETTING_HOLD_ESIMATE_WAIT_INTERVAL); - my $estimated_wait = $qpos * ($default_hold_interval / $num_potentials) if $default_hold_interval; + + my $default_wait = $U->ou_ancestor_setting_value($user_org, OILS_SETTING_HOLD_ESIMATE_WAIT_INTERVAL); + my $min_wait = $U->ou_ancestor_setting_value($user_org, 'circ.holds.min_estimated_wait_interval'); + $min_wait = OpenSRF::Utils::interval_to_seconds($min_wait || '0 seconds'); + $default_wait ||= '0 seconds'; + + # Estimated wait time is the average wait time across the set + # of potential copies, divided by the number of potential copies + # times the queue position. + + my $combined_secs = 0; + my $num_potentials = 0; + + for my $wait_data (@$hold_data) { + my $count += $wait_data->{count}; + $combined_secs += $count * + OpenSRF::Utils::interval_to_seconds($wait_data->{avg_wait_time} || $default_wait); + $num_potentials += $count; + } + + my $estimated_wait = -1; + + if($num_potentials) { + my $avg_wait = $combined_secs / $num_potentials; + $estimated_wait = $qpos * ($avg_wait / $num_potentials); + $estimated_wait = $min_wait if $estimated_wait < $min_wait and $estimated_wait != -1; + } return { total_holds => scalar(@$q_holds), queue_position => $qpos, - potential_copies => $num_potentials->{count}, + potential_copies => $num_potentials, status => _hold_status( $e, $hold ), estimated_wait => int($estimated_wait) }; diff --git a/Open-ILS/src/perlmods/OpenILS/Const.pm b/Open-ILS/src/perlmods/OpenILS/Const.pm index d1cf7668c1..be451673ba 100644 --- a/Open-ILS/src/perlmods/OpenILS/Const.pm +++ b/Open-ILS/src/perlmods/OpenILS/Const.pm @@ -84,7 +84,7 @@ econst OILS_SETTING_HOLD_HARD_STALL => 'circ.hold_stalling.hard'; econst OILS_SETTING_HOLD_SOFT_BOUNDARY => 'circ.hold_boundary.soft'; econst OILS_SETTING_HOLD_HARD_BOUNDARY => 'circ.hold_boundary.hard'; econst OILS_SETTING_HOLD_EXPIRE => 'circ.hold_expire_interval'; -econst OILS_SETTING_HOLD_ESIMATE_WAIT_INTERVAL => 'circ.hold_estimate_wait_interval'; +econst OILS_SETTING_HOLD_ESIMATE_WAIT_INTERVAL => 'circ.holds.default_estimated_wait_interval'; econst OILS_SETTING_VOID_LOST_ON_CHECKIN => 'circ.void_lost_on_checkin'; econst OILS_SETTING_MAX_ACCEPT_RETURN_OF_LOST => 'circ.max_accept_return_of_lost'; econst OILS_SETTING_VOID_LOST_PROCESS_FEE_ON_CHECKIN => 'circ.void_lost_proc_fee_on_checkin'; -- 2.11.0