LP#1549505: fix rating.percent_time_circulating()
authorGalen Charlton <gmc@esilibrary.com>
Thu, 10 Mar 2016 17:57:26 +0000 (12:57 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 10 Mar 2016 17:57:26 +0000 (12:57 -0500)
Fixes an issue with the item age calculation; not all items
will have a non-NULL active_date. This led to return
records with a NULL time circulating value, meaning
that they didn't get excluded by the percentile
filter.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statisitcal-ratings.sql

index 2b3e1ad..b9e7016 100644 (file)
@@ -890,7 +890,7 @@ BEGIN
             SUM(COALESCE(circ_time,0))::NUMERIC / SUM(age)::NUMERIC
       FROM  (SELECT cn.record AS bib,
                     cp.id,
-                    EXTRACT( EPOCH FROM AGE(cp.active_date) ) + 1 AS age,
+                    EXTRACT( EPOCH FROM AGE(COALESCE(cp.active_date, cp.create_date)) ) + 1 AS age,
                     SUM(  -- time copy spent circulating
                         EXTRACT(
                             EPOCH FROM