$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)
};
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';