From 9c4e9660a6ec10687504966a84ed4259fced6610 Mon Sep 17 00:00:00 2001 From: Kathy Lussier Date: Mon, 31 Jul 2017 13:43:38 -0400 Subject: [PATCH] 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 Signed-off-by: Mike Rylander --- Open-ILS/src/sql/Pg/220.schema.rating.sql | 29 ++++++++++++++- .../yyyy.data.org-unit-count-badge.sql | 37 +++++++++++++++++++ .../OPAC/new-activity-metric-badge.adoc | 11 ++++-- 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/yyyy.data.org-unit-count-badge.sql diff --git a/Open-ILS/src/sql/Pg/220.schema.rating.sql b/Open-ILS/src/sql/Pg/220.schema.rating.sql index 1b258141eb..242ecb0576 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 0000000000..8eae7a217c --- /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 993f404bb4..ed4a7108e8 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. -- 2.43.2