From: Lebbeous Fogle-Weekley Date: Fri, 20 Apr 2012 03:42:48 +0000 (-0400) Subject: besides queue_position, we should now have estimated_wait_time et al X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fsimplified-hpl;p=evergreen%2Fequinox.git besides queue_position, we should now have estimated_wait_time et al Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index d3f758abd2..18d2b3275e 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4846,10 +4846,22 @@ SELECT usr, COALESCE(au.first_given_name, ''), COALESCE(au.second_given_name, '') ], ' '), E'\\s+,', ',') - END AS usr_display_name, + END AS usr_display_name, TRIM(acnp.label || ' ' || acn.label || ' ' || acns.label) - AS call_number_label + AS call_number_label, + ahqa.queue_position, + ahqa.total_holds, + ahawt.avg_wait_time, + ahawt.num_potentials, + action.estimate_wait_time_for_hold( + ahawt.avg_wait_time, + ahqa.queue_position::INTEGER, + au.home_ou + ) AS estimated_wait_time FROM action.hold_request ahr + JOIN action.hold_avg_wait_time ahawt ON (ahawt.hold = ahr.id) + JOIN action.hold_queue_approximation ahqa + ON (ahqa.this_hold=ahr.id AND ahqa.other_hold=ahr.id) JOIN asset.copy acp ON (acp.id = ahr.current_copy) JOIN asset.call_number acn ON (acp.call_number = acn.id) JOIN asset.call_number_prefix acnp ON (acn.prefix = acnp.id) @@ -4907,6 +4919,11 @@ SELECT usr, + + + + + diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index 1af6e89ead..d72ea6d07d 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -972,5 +972,56 @@ query-based fieldsets. Returns NULL if successful, or an error message if not. $$; +-- For a given hold, get avg wait time of copies on potentials list and +-- the number of copies on potentials list. Estimated wait time can be +-- calculated from these results based on queue position. +CREATE VIEW action.hold_avg_wait_time AS + SELECT + SUM(num_potentials * avg_wait_time) / SUM(num_potentials) AS avg_wait_time, + SUM(num_potentials) AS num_potentials, + hold + FROM ( + SELECT + COUNT(acp.id) AS num_potentials, + ahcm.hold, + COALESCE(ccm.avg_wait_time, (SELECT MAX(value) FROM ( + SELECT value::INTERVAL FROM actor.org_unit_ancestor_setting('circ.holds.default_estimated_wait_interval', au.home_ou) + UNION + SELECT '0 seconds'::INTERVAL + ) ous)) AS avg_wait_time + FROM action.hold_copy_map ahcm + JOIN action.hold_request ahr ON (ahr.id = ahcm.hold) + JOIN actor.usr au ON (au.id = ahr.usr) + JOIN asset.copy acp ON (acp.id = ahcm.target_copy) + LEFT JOIN config.circ_modifier ccm ON (ccm.code = acp.circ_modifier) + GROUP BY 2, 3, au.home_ou + ) x + GROUP by 3; + + +CREATE OR REPLACE FUNCTION action.estimate_wait_time_for_hold( + avg_wait_time INTERVAL, + queue_position INT, + home_ou INT +) RETURNS INTERVAL AS $$ +SELECT + CASE WHEN min_wait > estimated_wait_time THEN + min_wait + ELSE + estimated_wait_time + END +FROM ( + SELECT + (SELECT MAX(value) FROM ( + SELECT value::INTERVAL + FROM actor.org_unit_ancestor_setting( + 'circ.holds.min_estimated_wait_interval', $3 + ) + UNION + SELECT '0 seconds'::INTERVAL + ) ous) AS min_wait, + $1 * $2 AS estimated_wait_time +) x +$$ LANGUAGE SQL; COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.simplified-hold-pull-list.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.simplified-hold-pull-list.sql index 7c355dc73a..be40625360 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.simplified-hold-pull-list.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.simplified-hold-pull-list.sql @@ -77,4 +77,57 @@ SELECT h1.id AS this_hold, JOIN action.hold_request h2 ON (h2.id = r2.id) ; -- End hold queue approximation + +-- For a given hold, get avg wait time of copies on potentials list and +-- the number of copies on potentials list. Estimated wait time can be +-- calculated from these results based on queue position. +CREATE VIEW action.hold_avg_wait_time AS + SELECT + SUM(num_potentials * avg_wait_time) / SUM(num_potentials) AS avg_wait_time, + SUM(num_potentials) AS num_potentials, + hold + FROM ( + SELECT + COUNT(acp.id) AS num_potentials, + ahcm.hold, + COALESCE(ccm.avg_wait_time, (SELECT MAX(value) FROM ( + SELECT value::INTERVAL FROM actor.org_unit_ancestor_setting('circ.holds.default_estimated_wait_interval', au.home_ou) + UNION + SELECT '0 seconds'::INTERVAL + ) ous)) AS avg_wait_time + FROM action.hold_copy_map ahcm + JOIN action.hold_request ahr ON (ahr.id = ahcm.hold) + JOIN actor.usr au ON (au.id = ahr.usr) + JOIN asset.copy acp ON (acp.id = ahcm.target_copy) + LEFT JOIN config.circ_modifier ccm ON (ccm.code = acp.circ_modifier) + GROUP BY 2, 3, au.home_ou + ) x + GROUP by 3; + + +CREATE OR REPLACE FUNCTION action.estimate_wait_time_for_hold( + avg_wait_time INTERVAL, + queue_position INT, + home_ou INT +) RETURNS INTERVAL AS $$ +SELECT + CASE WHEN min_wait > estimated_wait_time THEN + min_wait + ELSE + estimated_wait_time + END +FROM ( + SELECT + (SELECT MAX(value) FROM ( + SELECT value::INTERVAL + FROM actor.org_unit_ancestor_setting( + 'circ.holds.min_estimated_wait_interval', $3 + ) + UNION + SELECT '0 seconds'::INTERVAL + ) ous) AS min_wait, + $1 * $2 AS estimated_wait_time +) x +$$ LANGUAGE SQL; + COMMIT;