(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);
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$
--- /dev/null
+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;
+
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.