[open-ils-commits] r16402 - trunk/Open-ILS/examples (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu May 6 18:14:12 EDT 2010


Author: phasefx
Date: 2010-05-06 18:14:06 -0400 (Thu, 06 May 2010)
New Revision: 16402

Modified:
   trunk/Open-ILS/examples/fm_IDL.xml
Log:
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


Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2010-05-06 19:52:20 UTC (rev 16401)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2010-05-06 22:14:06 UTC (rev 16402)
@@ -7042,7 +7042,71 @@
 		</permacrud>
 	</class>
 
+	<class id="rhcrpb" controller="open-ils.cstore open-ils.pcrud open-ils.reporter-store" oils_obj:fieldmapper="reporter::hold_copy_ratio_per_bib" oils_persist:readonly="true" reporter:core="true" reporter:label="Hold/Copy Ratio per Bib">
+		<oils_persist:source_definition>
 
+            -- -- 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)
+                ;
+
+		</oils_persist:source_definition>
+		<fields oils_persist:primary="id" oils_persist:sequence="biblio.record_entry">
+			<field reporter:label="Record ID" name="id" reporter:datatype="id"/>
+			<field reporter:label="Holdable Copy Count" name="copy_count" reporter:datatype="int"/>
+			<field reporter:label="Active Holds" name="hold_count" reporter:datatype="int"/>
+			<field reporter:label="Hold/Copy Ratio" name="hold_copy_ratio" reporter:datatype="float"/>
+		</fields>
+		<links>
+			<link field="id" reltype="has_a" key="id" map="" class="bre"/>
+		</links>
+		<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+			<actions>
+				<retrieve/>
+			</actions>
+		</permacrud>
+	</class>
+
 	<!-- ********************************************************************************************************************* -->
 	<!-- What follows is a set of example extensions that are useful for PINES.  Comment out or remove if you don't want them. -->
 	<!-- ********************************************************************************************************************* -->



More information about the open-ils-commits mailing list