[open-ils-commits] r16493 - in trunk/Open-ILS/src/perlmods/OpenILS: . Application/Circ (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue May 25 09:51:28 EDT 2010


Author: erickson
Date: 2010-05-25 09:51:26 -0400 (Tue, 25 May 2010)
New Revision: 16493

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
   trunk/Open-ILS/src/perlmods/OpenILS/Const.pm
Log:
support for calculating estimated hold wait time based on new circ estimated wait field

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm	2010-05-25 13:51:25 UTC (rev 16492)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm	2010-05-25 13:51:26 UTC (rev 16493)
@@ -1055,21 +1055,50 @@
         $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)
     };

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Const.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Const.pm	2010-05-25 13:51:25 UTC (rev 16492)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Const.pm	2010-05-25 13:51:26 UTC (rev 16493)
@@ -84,7 +84,7 @@
 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';



More information about the open-ils-commits mailing list