fixes, approx, etc
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 17 Dec 2012 23:06:07 +0000 (18:06 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 21 Dec 2012 00:18:47 +0000 (19:18 -0500)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.custom-best-hold-selection.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.org_prox_adjust.sql

index 50db1da..d243efd 100644 (file)
@@ -2304,6 +2304,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
             </actions>
         </permacrud>
        </class>
+       <class id="cbho" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="config::best_hold_order" oils_persist:tablename="config.best_hold_order" reporter:label="Best-Hold Sort Order">
+               <fields oils_persist:primary="id" oils_persist:sequence="config.best_hold_order_id_seq">
+                       <field reporter:label="ID" name="id" reporter:datatype="id" />
+                       <field reporter:label="Name" name="name" reporter:datatype="text"/>
+                       <field reporter:label="Capture Lib to Pickup Lib Proximity" name="pprox" reporter:datatype="int" />
+                       <field reporter:label="Circ Lib to Request Lib Proximity" name="hprox" reporter:datatype="int" />
+                       <field reporter:label="Adjusted Circ Lib to Pickup Lib Proximity" name="aprox" reporter:datatype="int" />
+                       <field reporter:label="Adjusted Capture Location to Pickup Lib Proximity" name="approx" reporter:datatype="int" />
+                       <field reporter:label="Hold Priority" name="priority" reporter:datatype="int" />
+                       <field reporter:label="Hold Cut-in-line State" name="cut" reporter:datatype="int" />
+                       <field reporter:label="Hold Selection Depth" name="depth" reporter:datatype="int" />
+                       <field reporter:label="Copy Has Circulated From Home Lately" name="htime" reporter:datatype="int" />
+                       <field reporter:label="Hold Request Time" name="rtime" reporter:datatype="int" />
+                       <field reporter:label="Copy Has Been Home At All Lately" name="shtime" reporter:datatype="int" />
+               </fields>
+               <links>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <create permission="ADMIN_CONFIG_BEST_HOLD_ORDER" global_required="true"/>
+                               <retrieve permission="ADMIN_CONFIG_BEST_HOLD_ORDER" global_required="true"/>
+                               <update permission="ADMIN_CONFIG_BEST_HOLD_ORDER" global_required="true"/>
+                               <delete permission="ADMIN_CONFIG_BEST_HOLD_ORDER" global_required="true"/>
+                       </actions>
+               </permacrud>
+       </class>
        <class id="cbfp" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="config::biblio_fingerprint" oils_persist:tablename="config.biblio_fingerprint" reporter:label="Fingerprint Definition">
                <fields oils_persist:primary="id" oils_persist:sequence="config.biblio_fingerprint_id_seq">
                        <field name="id" reporter:datatype="id" />
index 32a519c..05dedcf 100644 (file)
@@ -20,9 +20,9 @@ my $U = "OpenILS::Application::AppUtils";
 # used in build_hold_sort_clause()
 my %HOLD_SORT_ORDER_BY = (
     pprox => 'p.prox',
-    hprox => 'actor.org_unit_proximity(%d, h.request_lib)',
+    hprox => 'actor.org_unit_proximity(%d, h.request_lib)',  # $cp->circ_lib
     aprox => 'COALESCE(hm.proximity, p.prox)',
-    approx => 'action.hold_copy_calculated_proximity(h.id, %d, %d)',
+    approx => 'action.hold_copy_calculated_proximity(h.id, %d, %d)', # $cp,$here
     priority => 'pgt.hold_priority',
     cut => 'CASE WHEN h.cut_in_line IS TRUE THEN 0 ELSE 1 END',
     depth => 'h.selection_depth',
@@ -476,7 +476,7 @@ sub nearest_hold {
 
        local $OpenILS::Application::Storage::WRITE = 1;
 
-       my $ids = action::hold_request->db_Main->selectcol_arrayref(<<" SQL", {}, $here, $cp->id, $age);
+       my $ids = action::hold_request->db_Main->selectcol_arrayref(<<" SQL", {}, $cp->circ_lib, $here, $cp->id, $age);
         WITH go_home_interval AS (
             SELECT OILS_JSON_TO_TEXT(
                 (SELECT value FROM actor.org_unit_ancestor_setting(
index bb42fbe..cc9c486 100644 (file)
@@ -1008,11 +1008,13 @@ CREATE TABLE config.best_hold_order(
     pprox       INT, -- copy capture <-> pickup lib prox
     hprox       INT, -- copy circ lib <-> request lib prox
     aprox       INT, -- copy circ lib <-> pickup lib ADJUSTED prox on ahcm
+    approx      INT, -- copy capture <-> pickup lib ADJUSTED prox from function
     priority    INT, -- group hold priority
     cut         INT, -- cut-in-line
     depth       INT, -- selection depth
     htime       INT, -- time since last home-lib circ exceeds org-unit setting
-    rtime       INT  -- request time
+    rtime       INT, -- request time
+    shtime      INT  -- time since copy last trip home exceeds org-unit setting
 );
 
 -- At least one of these columns must contain a non-null value
index 3f7bb6f..fd82cf0 100644 (file)
@@ -973,7 +973,16 @@ query-based fieldsets.
 Returns NULL if successful, or an error message if not.
 $$;
 
-CREATE OR REPLACE FUNCTION action.hold_copy_calculated_proximity(ahr_id INT, acp_id BIGINT, context_ou INT DEFAULT NULL) RETURNS NUMERIC AS $f$
+CREATE OR REPLACE FUNCTION action.hold_copy_calculated_proximity(
+    ahr_id INT,
+    acp_id BIGINT,
+    copy_context_ou INT DEFAULT NULL
+    -- TODO maybe? hold_context_ou INT DEFAULT NULL.  This would optionally
+    -- support an "ahprox" measurement: adjust prox between copy circ lib and
+    -- hold request lib, but I'm unsure whether to use this theoretical
+    -- argument only in the baseline calculation or later in the other
+    -- queries in this function.
+) RETURNS NUMERIC AS $f$
 DECLARE
     aoupa           actor.org_unit_proximity_adjustment%ROWTYPE;
     ahr             action.hold_request%ROWTYPE;
@@ -995,17 +1004,17 @@ BEGIN
     SELECT * INTO acn FROM asset.call_number WHERE id = acp.call_number;
     SELECT * INTO acl FROM asset.copy_location WHERE id = acp.location;
 
-    IF context_ou IS NULL THEN
-        context_ou := acp.circ_lib;
+    IF copy_context_ou IS NULL THEN
+        copy_context_ou := acp.circ_lib;
     END IF;
 
     -- First, gather the baseline proximity of "here" to pickup lib
-    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = context_ou AND to_org = ahr.pickup_lib;
+    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = copy_context_ou AND to_org = ahr.pickup_lib;
 
     -- Find any absolute adjustments, and set the baseline prox to that
     SELECT  adj.* INTO aoupa
       FROM  actor.org_unit_proximity_adjustment adj
-            LEFT JOIN actor.org_unit_ancestors_distance(context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(copy_context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
             LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
             LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
             LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
@@ -1030,7 +1039,7 @@ BEGIN
     FOR aoupa IN
         SELECT  adj.* 
           FROM  actor.org_unit_proximity_adjustment adj
-                LEFT JOIN actor.org_unit_ancestors_distance(context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(copy_context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
                 LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
                 LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
                 LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
index bb1f6e7..55e3906 100644 (file)
@@ -6,11 +6,13 @@ CREATE TABLE config.best_hold_order(
     pprox       INT, -- copy capture <-> pickup lib prox
     hprox       INT, -- copy circ lib <-> request lib prox
     aprox       INT, -- copy circ lib <-> pickup lib ADJUSTED prox on ahcm
+    approx      INT, -- copy capture <-> pickup lib ADJUSTED prox from function
     priority    INT, -- group hold priority
     cut         INT, -- cut-in-line
     depth       INT, -- selection depth
     htime       INT, -- time since last home-lib circ exceeds org-unit setting
-    rtime       INT  -- request time
+    rtime       INT, -- request time
+    shtime      INT  -- time since copy last trip home exceeds org-unit setting
 );
 
 -- At least one of these columns must contain a non-null value
index d9eb082..43876d8 100644 (file)
@@ -32,7 +32,16 @@ CREATE OR REPLACE FUNCTION actor.org_unit_ancestors_distance( INT ) RETURNS TABL
     SELECT * FROM org_unit_ancestors_distance;
 $$ LANGUAGE SQL STABLE ROWS 1;
 
-CREATE OR REPLACE FUNCTION action.hold_copy_calculated_proximity(ahr_id INT, acp_id BIGINT, context_ou INT DEFAULT NULL) RETURNS NUMERIC AS $f$
+CREATE OR REPLACE FUNCTION action.hold_copy_calculated_proximity(
+    ahr_id INT,
+    acp_id BIGINT,
+    copy_context_ou INT DEFAULT NULL
+    -- TODO maybe? hold_context_ou INT DEFAULT NULL.  This would optionally
+    -- support an "ahprox" measurement: adjust prox between copy circ lib and
+    -- hold request lib, but I'm unsure whether to use this theoretical
+    -- argument only in the baseline calculation or later in the other
+    -- queries in this function.
+) RETURNS NUMERIC AS $f$
 DECLARE
     aoupa           actor.org_unit_proximity_adjustment%ROWTYPE;
     ahr             action.hold_request%ROWTYPE;
@@ -54,17 +63,17 @@ BEGIN
     SELECT * INTO acn FROM asset.call_number WHERE id = acp.call_number;
     SELECT * INTO acl FROM asset.copy_location WHERE id = acp.location;
 
-    IF context_ou IS NULL THEN
-        context_ou := acp.circ_lib;
+    IF copy_context_ou IS NULL THEN
+        copy_context_ou := acp.circ_lib;
     END IF;
 
     -- First, gather the baseline proximity of "here" to pickup lib
-    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = context_ou AND to_org = ahr.pickup_lib;
+    SELECT prox INTO baseline_prox FROM actor.org_unit_proximity WHERE from_org = copy_context_ou AND to_org = ahr.pickup_lib;
 
     -- Find any absolute adjustments, and set the baseline prox to that
     SELECT  adj.* INTO aoupa
       FROM  actor.org_unit_proximity_adjustment adj
-            LEFT JOIN actor.org_unit_ancestors_distance(context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+            LEFT JOIN actor.org_unit_ancestors_distance(copy_context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
             LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
             LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
             LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)
@@ -89,7 +98,7 @@ BEGIN
     FOR aoupa IN
         SELECT  adj.* 
           FROM  actor.org_unit_proximity_adjustment adj
-                LEFT JOIN actor.org_unit_ancestors_distance(context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
+                LEFT JOIN actor.org_unit_ancestors_distance(copy_context_ou) acp_cl ON (acp_cl.id = adj.item_circ_lib)
                 LEFT JOIN actor.org_unit_ancestors_distance(acn.owning_lib) acn_ol ON (acn_ol.id = adj.item_owning_lib)
                 LEFT JOIN actor.org_unit_ancestors_distance(acl.owning_lib) acl_ol ON (acn_ol.id = adj.copy_location)
                 LEFT JOIN actor.org_unit_ancestors_distance(ahr.pickup_lib) ahr_pl ON (ahr_pl.id = adj.hold_pickup_lib)