[open-ils-commits] [GIT] Evergreen ILS branch master updated. b051ae99087ebcc4adac220c91f7981c5e1280ae

Evergreen Git git at git.evergreen-ils.org
Thu Aug 10 11:20:12 EDT 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  b051ae99087ebcc4adac220c91f7981c5e1280ae (commit)
       via  9c4e9660a6ec10687504966a84ed4259fced6610 (commit)
       via  2f8bf6c328c2caa7ded0cfe7debe3b7423fb8f70 (commit)
      from  dcf52caab8f188d250ac82fd9e6b95fa07a1f320 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b051ae99087ebcc4adac220c91f7981c5e1280ae
Author: Mike Rylander <mrylander at gmail.com>
Date:   Thu Aug 10 11:16:13 2017 -0400

    Stamping populariy parameter upgrade scripts
    
    Also, the org-count parameter function is adjusted to consistently find
    and count copies by circ lib.  Because this parameter is about counting
    copies on the shelves of libraries, this makes more sense than owing
    library.  Changed in consultation with Kathy Lussier.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 96e1170..f42d9e9 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -90,7 +90,7 @@ CREATE TRIGGER no_overlapping_deps
     BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
     FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
 
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1051', :eg_version); -- berick/miker
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('1053', :eg_version); -- kmlussier/miker
 
 CREATE TABLE config.bib_source (
 	id		SERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/220.schema.rating.sql b/Open-ILS/src/sql/Pg/220.schema.rating.sql
index 242ecb0..b5e4fb3 100644
--- a/Open-ILS/src/sql/Pg/220.schema.rating.sql
+++ b/Open-ILS/src/sql/Pg/220.schema.rating.sql
@@ -950,13 +950,13 @@ BEGIN
     );
     ANALYZE precalc_copy_filter_bib_list;
 
+    -- Use circ rather than owning lib here as that means "on the shelf at..."
     RETURN QUERY
      SELECT f.id::INT AS bib,
             COUNT(DISTINCT cp.circ_lib)::NUMERIC
      FROM asset.copy cp
           JOIN precalc_copy_filter_bib_list f ON (cp.id = f.copy)
-          JOIN asset.call_number cn ON (cn.id = cp.call_number)
-     WHERE cn.owning_lib = ANY (badge.orgs) GROUP BY 1;
+     WHERE cp.circ_lib = ANY (badge.orgs) GROUP BY 1;
 
 END;
 $f$ LANGUAGE PLPGSQL STRICT;
diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.data-inhouse-use-badge.sql b/Open-ILS/src/sql/Pg/upgrade/1052.data-inhouse-use-badge.sql
similarity index 96%
rename from Open-ILS/src/sql/Pg/upgrade/xxxx.data-inhouse-use-badge.sql
rename to Open-ILS/src/sql/Pg/upgrade/1052.data-inhouse-use-badge.sql
index 16d3f16..b47d390 100644
--- a/Open-ILS/src/sql/Pg/upgrade/xxxx.data-inhouse-use-badge.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/1052.data-inhouse-use-badge.sql
@@ -1,6 +1,6 @@
 BEGIN;
 
--- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('1052', :eg_version);
 
 CREATE OR REPLACE FUNCTION rating.inhouse_over_time(badge_id INT)
     RETURNS TABLE (record BIGINT, value NUMERIC) AS $f$
diff --git a/Open-ILS/src/sql/Pg/upgrade/yyyy.data.org-unit-count-badge.sql b/Open-ILS/src/sql/Pg/upgrade/1053.data.org-unit-count-badge.sql
similarity index 82%
rename from Open-ILS/src/sql/Pg/upgrade/yyyy.data.org-unit-count-badge.sql
rename to Open-ILS/src/sql/Pg/upgrade/1053.data.org-unit-count-badge.sql
index 8eae7a2..adb457f 100644
--- a/Open-ILS/src/sql/Pg/upgrade/yyyy.data.org-unit-count-badge.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/1053.data.org-unit-count-badge.sql
@@ -1,6 +1,6 @@
 BEGIN;
 
--- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('1053', :eg_version);
 
 CREATE OR REPLACE FUNCTION rating.org_unit_count(badge_id INT)
     RETURNS TABLE (record INT, value NUMERIC) AS $f$
@@ -19,13 +19,13 @@ BEGIN
     );
     ANALYZE precalc_copy_filter_bib_list;
 
+    -- Use circ rather than owning lib here as that means "on the shelf at..."
     RETURN QUERY
      SELECT f.id::INT AS bib,
             COUNT(DISTINCT cp.circ_lib)::NUMERIC
      FROM asset.copy cp
           JOIN precalc_copy_filter_bib_list f ON (cp.id = f.copy)
-          JOIN asset.call_number cn ON (cn.id = cp.call_number)
-     WHERE cn.owning_lib = ANY (badge.orgs) GROUP BY 1;
+     WHERE cp.circ_lib = ANY (badge.orgs) GROUP BY 1;
 
 END;
 $f$ LANGUAGE PLPGSQL STRICT;

commit 9c4e9660a6ec10687504966a84ed4259fced6610
Author: Kathy Lussier <klussier at masslnc.org>
Date:   Mon Jul 31 13:43:38 2017 -0400

    LP#1688099: Popularity parameter for the number of OUs that own a title
    
    Creates a new badge that calculates a score based on a count of libraries
    that own a copy of a title. The badge is based on libraries that are the copy's
    circulation library. The intent of the badge is to measure the breadth of
    ownership within a particular consortium with the hope that it doesn't
    generate as many 'false hits' that are seen with the similar Total Copy Counts
    badge.
    
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/220.schema.rating.sql b/Open-ILS/src/sql/Pg/220.schema.rating.sql
index 1b25814..242ecb0 100644
--- a/Open-ILS/src/sql/Pg/220.schema.rating.sql
+++ b/Open-ILS/src/sql/Pg/220.schema.rating.sql
@@ -79,6 +79,7 @@ INSERT INTO rating.popularity_parameter (id,name,func,require_horizon,require_im
     (14,'Bib has attributes and copies or URIs','rating.generic_fixed_rating_by_copy_or_uri',FALSE,FALSE,FALSE),
     (15,'Bib has attributes','rating.generic_fixed_rating_global',FALSE,FALSE,FALSE),
     (16,'Copy Count','rating.copy_count',FALSE,FALSE,TRUE),
+    (17,'Circulation Library Count', 'rating.org_unit_count',FALSE,FALSE, TRUE); 
     (18, 'In-House Use Over Time', 'rating.inhouse_over_time',TRUE,FALSE,TRUE);
 
 
@@ -932,7 +933,33 @@ BEGIN
 END;
 $f$ LANGUAGE PLPGSQL STRICT;
 
-BEGIN;
+CREATE OR REPLACE FUNCTION rating.org_unit_count(badge_id INT)
+    RETURNS TABLE (record INT, value NUMERIC) AS $f$
+DECLARE
+    badge   rating.badge_with_orgs%ROWTYPE;
+BEGIN
+
+    SELECT * INTO badge FROM rating.badge_with_orgs WHERE id = badge_id;
+
+    PERFORM rating.precalc_bibs_by_copy(badge_id);
+
+    DELETE FROM precalc_copy_filter_bib_list WHERE id NOT IN (
+        SELECT id FROM precalc_filter_bib_list
+            INTERSECT
+        SELECT id FROM precalc_bibs_by_copy_list
+    );
+    ANALYZE precalc_copy_filter_bib_list;
+
+    RETURN QUERY
+     SELECT f.id::INT AS bib,
+            COUNT(DISTINCT cp.circ_lib)::NUMERIC
+     FROM asset.copy cp
+          JOIN precalc_copy_filter_bib_list f ON (cp.id = f.copy)
+          JOIN asset.call_number cn ON (cn.id = cp.call_number)
+     WHERE cn.owning_lib = ANY (badge.orgs) GROUP BY 1;
+
+END;
+$f$ LANGUAGE PLPGSQL STRICT;
 
 CREATE OR REPLACE FUNCTION rating.inhouse_over_time(badge_id INT)
     RETURNS TABLE (record BIGINT, value NUMERIC) AS $f$
diff --git a/Open-ILS/src/sql/Pg/upgrade/yyyy.data.org-unit-count-badge.sql b/Open-ILS/src/sql/Pg/upgrade/yyyy.data.org-unit-count-badge.sql
new file mode 100644
index 0000000..8eae7a2
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/yyyy.data.org-unit-count-badge.sql
@@ -0,0 +1,37 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION rating.org_unit_count(badge_id INT)
+    RETURNS TABLE (record INT, value NUMERIC) AS $f$
+DECLARE
+    badge   rating.badge_with_orgs%ROWTYPE;
+BEGIN
+
+    SELECT * INTO badge FROM rating.badge_with_orgs WHERE id = badge_id;
+
+    PERFORM rating.precalc_bibs_by_copy(badge_id);
+
+    DELETE FROM precalc_copy_filter_bib_list WHERE id NOT IN (
+        SELECT id FROM precalc_filter_bib_list
+            INTERSECT
+        SELECT id FROM precalc_bibs_by_copy_list
+    );
+    ANALYZE precalc_copy_filter_bib_list;
+
+    RETURN QUERY
+     SELECT f.id::INT AS bib,
+            COUNT(DISTINCT cp.circ_lib)::NUMERIC
+     FROM asset.copy cp
+          JOIN precalc_copy_filter_bib_list f ON (cp.id = f.copy)
+          JOIN asset.call_number cn ON (cn.id = cp.call_number)
+     WHERE cn.owning_lib = ANY (badge.orgs) GROUP BY 1;
+
+END;
+$f$ LANGUAGE PLPGSQL STRICT;
+
+INSERT INTO rating.popularity_parameter (id, name, func, require_percentile) VALUES
+    (17,'Circulation Library Count', 'rating.org_unit_count', TRUE);
+
+COMMIT;
+
diff --git a/docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc b/docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc
index 993f404..ed4a710 100644
--- a/docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc
+++ b/docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc
@@ -1,6 +1,11 @@
 New Popularity Parameter
 ^^^^^^^^^^^^^^^^^^^^^^^^
-A new popularity parameter for in-house use over time is now available. 
-Evergreen sites can use the parameter to create a new statistical popularity
-badge based on in-house use of materials.
+New popularity parameters for in-house use over time and for count of distinct
+organizational units that own a title are now available. Evergreen sites
+can use these parameters to create new statistical popularity badges for
+sorting in the catalog by Most Popular or by Popularity-Adjusted Relevance.
 
+The in-house use parameters will apply a badge to titles that have the most
+in-house use activity over time. The organizational unit count parameter
+will apply a badge to titles owned by the most number of libraries in a
+consortium. Ownership is determined by the copy's circulation library.

commit 2f8bf6c328c2caa7ded0cfe7debe3b7423fb8f70
Author: Kathy Lussier <klussier at masslnc.org>
Date:   Mon Jul 31 16:36:50 2017 -0400

    LP#1688096: Popularity parameter for in-house use
    
    Adds a new popularity parameter based on in-house use over time. The parameter
    can be used for creating a statistically-generated popularity badge for titles.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/sql/Pg/220.schema.rating.sql b/Open-ILS/src/sql/Pg/220.schema.rating.sql
index 8fed4cd..1b25814 100644
--- a/Open-ILS/src/sql/Pg/220.schema.rating.sql
+++ b/Open-ILS/src/sql/Pg/220.schema.rating.sql
@@ -78,7 +78,8 @@ INSERT INTO rating.popularity_parameter (id,name,func,require_horizon,require_im
     (13,'Bib has attributes and copies','rating.generic_fixed_rating_by_copy',FALSE,FALSE,FALSE),
     (14,'Bib has attributes and copies or URIs','rating.generic_fixed_rating_by_copy_or_uri',FALSE,FALSE,FALSE),
     (15,'Bib has attributes','rating.generic_fixed_rating_global',FALSE,FALSE,FALSE),
-    (16,'Copy Count','rating.copy_count',FALSE,FALSE,TRUE);
+    (16,'Copy Count','rating.copy_count',FALSE,FALSE,TRUE),
+    (18, 'In-House Use Over Time', 'rating.inhouse_over_time',TRUE,FALSE,TRUE);
 
 
 CREATE TABLE rating.badge (
@@ -931,5 +932,60 @@ BEGIN
 END;
 $f$ LANGUAGE PLPGSQL STRICT;
 
+BEGIN;
+
+CREATE OR REPLACE FUNCTION rating.inhouse_over_time(badge_id INT)
+    RETURNS TABLE (record BIGINT, value NUMERIC) AS $f$
+DECLARE
+    badge   rating.badge_with_orgs%ROWTYPE;
+    iage    INT     := 1;
+    iint    INT     := NULL;
+    iscale  NUMERIC := NULL;
+BEGIN
+
+    SELECT * INTO badge FROM rating.badge_with_orgs WHERE id = badge_id;
+
+    IF badge.horizon_age IS NULL THEN
+        RAISE EXCEPTION 'Badge "%" with id % requires a horizon age but has none.',
+            badge.name,
+            badge.id;
+    END IF;
+
+    PERFORM rating.precalc_bibs_by_copy(badge_id);
+
+    DELETE FROM precalc_copy_filter_bib_list WHERE id NOT IN (
+        SELECT id FROM precalc_filter_bib_list
+            INTERSECT
+        SELECT id FROM precalc_bibs_by_copy_list
+    );
+
+    ANALYZE precalc_copy_filter_bib_list;
+
+    iint := EXTRACT(EPOCH FROM badge.importance_interval);
+    IF badge.importance_age IS NOT NULL THEN
+        iage := (EXTRACT(EPOCH FROM badge.importance_age) / iint)::INT;
+    END IF;
+
+    -- if iscale is smaller than 1, scaling slope will be shallow ... BEWARE!
+    iscale := COALESCE(badge.importance_scale, 1.0);
+
+    RETURN QUERY
+     SELECT bib,
+            SUM( uses * GREATEST( iscale * (iage - cage), 1.0 ))
+      FROM (
+         SELECT cn.record AS bib,
+                (1 + EXTRACT(EPOCH FROM AGE(u.use_time)) / iint)::INT AS cage,
+                COUNT(u.id)::INT AS uses
+          FROM  action.in_house_use u
+                JOIN precalc_copy_filter_bib_list cf ON (u.item = cf.copy)
+                JOIN asset.copy cp ON (cp.id = u.item)
+                JOIN asset.call_number cn ON (cn.id = cp.call_number)
+          WHERE u.use_time >= NOW() - badge.horizon_age
+                AND cn.owning_lib = ANY (badge.orgs)
+          GROUP BY 1, 2
+      ) x
+      GROUP BY 1;
+END;
+
 COMMIT;
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.data-inhouse-use-badge.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.data-inhouse-use-badge.sql
new file mode 100644
index 0000000..16d3f16
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/xxxx.data-inhouse-use-badge.sql
@@ -0,0 +1,63 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION rating.inhouse_over_time(badge_id INT)
+    RETURNS TABLE (record BIGINT, value NUMERIC) AS $f$
+DECLARE
+    badge   rating.badge_with_orgs%ROWTYPE;
+    iage    INT     := 1;
+    iint    INT     := NULL;
+    iscale  NUMERIC := NULL;
+BEGIN
+
+    SELECT * INTO badge FROM rating.badge_with_orgs WHERE id = badge_id;
+
+    IF badge.horizon_age IS NULL THEN
+        RAISE EXCEPTION 'Badge "%" with id % requires a horizon age but has none.',
+            badge.name,
+            badge.id;
+    END IF;
+
+    PERFORM rating.precalc_bibs_by_copy(badge_id);
+
+    DELETE FROM precalc_copy_filter_bib_list WHERE id NOT IN (
+        SELECT id FROM precalc_filter_bib_list
+            INTERSECT
+        SELECT id FROM precalc_bibs_by_copy_list
+    );
+
+    ANALYZE precalc_copy_filter_bib_list;
+
+    iint := EXTRACT(EPOCH FROM badge.importance_interval);
+    IF badge.importance_age IS NOT NULL THEN
+        iage := (EXTRACT(EPOCH FROM badge.importance_age) / iint)::INT;
+    END IF;
+
+    -- if iscale is smaller than 1, scaling slope will be shallow ... BEWARE!
+    iscale := COALESCE(badge.importance_scale, 1.0);
+
+    RETURN QUERY
+     SELECT bib,
+            SUM( uses * GREATEST( iscale * (iage - cage), 1.0 ))
+      FROM (
+         SELECT cn.record AS bib,
+                (1 + EXTRACT(EPOCH FROM AGE(u.use_time)) / iint)::INT AS cage,
+                COUNT(u.id)::INT AS uses
+          FROM  action.in_house_use u
+                JOIN precalc_copy_filter_bib_list cf ON (u.item = cf.copy)
+                JOIN asset.copy cp ON (cp.id = u.item)
+                JOIN asset.call_number cn ON (cn.id = cp.call_number)
+          WHERE u.use_time >= NOW() - badge.horizon_age
+                AND cn.owning_lib = ANY (badge.orgs)
+          GROUP BY 1, 2
+      ) x
+      GROUP BY 1;
+END;
+$f$ LANGUAGE PLPGSQL STRICT;
+
+INSERT INTO rating.popularity_parameter (id, name, func, require_horizon,require_percentile) VALUES
+    (18,'In-House Use Over Time', 'rating.inhouse_over_time', TRUE, TRUE);
+
+COMMIT;
+
diff --git a/docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc b/docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc
new file mode 100644
index 0000000..993f404
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc
@@ -0,0 +1,6 @@
+New Popularity Parameter
+^^^^^^^^^^^^^^^^^^^^^^^^
+A new popularity parameter for in-house use over time is now available. 
+Evergreen sites can use the parameter to create a new statistical popularity
+badge based on in-house use of materials.
+

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/002.schema.config.sql          |    2 +-
 Open-ILS/src/sql/Pg/220.schema.rating.sql          |   85 +++++++++++++++++++-
 .../sql/Pg/upgrade/1052.data-inhouse-use-badge.sql |   63 +++++++++++++++
 ...adge.sql => 1053.data.org-unit-count-badge.sql} |   17 ++--
 .../OPAC/new-activity-metric-badge.adoc            |   11 +++
 5 files changed, 168 insertions(+), 10 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/1052.data-inhouse-use-badge.sql
 copy Open-ILS/src/sql/Pg/upgrade/{0990.data.copy-count-badge.sql => 1053.data.org-unit-count-badge.sql} (56%)
 create mode 100644 docs/RELEASE_NOTES_NEXT/OPAC/new-activity-metric-badge.adoc


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list