From c56298235c51240110584bcd877474d3e7b30949 Mon Sep 17 00:00:00 2001 From: phasefx Date: Thu, 6 May 2010 22:14:06 +0000 Subject: [PATCH] rough cut at reporting extension for a purchase alert list (based on holds to copy ratio). mulling over the notion of using action.hold_copy_map for counting copies... exceptions abound however we do it as far as accuracy goes git-svn-id: svn://svn.open-ils.org/ILS/trunk@16402 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 82d72b3e66..d6fbf28142 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -7042,6 +7042,70 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + + + -- -- If we uncomment the RIGHT JOIN against biblio.record_entry, then we'll get a row for every non-deleted bib, whether it has active holds or not. + -- -- If we expect to use pcrud to query against specific bibs, we probably want to do this. However, if we're using this to populate a report, we + -- -- may not. + -- SELECT + -- bre.id AS "bib_id", + -- COALESCE( z.copy_count, 0 ) AS "copy_count", + -- COALESCE( z.hold_count, 0 ) AS "hold_count", + -- COALESCE( z.copy_hold_ratio, 0 ) AS "hold_copy_ratio" + -- FROM ( + SELECT + y.bre AS "bib_id", + COALESCE( x.copy_count, 0 ) AS "copy_count", + y.hold_count AS "hold_count", + (y.hold_count::REAL / (CASE WHEN x.copy_count = 0 OR x.copy_count IS NULL THEN 0.1 ELSE x.copy_count::REAL END)) AS "hold_copy_ratio" + FROM ( + SELECT + (SELECT bib_record FROM reporter.hold_request_record r WHERE r.id = h.id LIMIT 1) AS "bre", + COUNT(*) AS "hold_count" + FROM action.hold_request h + WHERE + cancel_time IS NULL + AND fulfillment_time IS NULL + -- AND NOT frozen -- a frozen hold is still a desired hold, eh? + GROUP BY 1 + )y LEFT JOIN ( + SELECT + (SELECT id + FROM biblio.record_entry + WHERE id = (SELECT record FROM asset.call_number WHERE id = call_number) + ) AS "bre", + COUNT(*) AS "copy_count" + FROM asset.copy + JOIN asset.copy_location loc ON (copy.location = loc.id AND loc.holdable) + WHERE copy.holdable + AND NOT copy.deleted + AND copy.status IN ( SELECT id FROM config.copy_status WHERE holdable ) + GROUP BY 1 + )x ON x.bre = y.bre + -- )z RIGHT JOIN ( + -- SELECT id + -- FROM biblio.record_entry + -- WHERE NOT deleted + -- )bre ON (z.bib_id = bre.id) + ; + + + + + + + + + + + + + + + + + -- 2.43.2