Advertisement
roganhamby

Annual State Statistics - Sections G & H

May 20th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.77 KB | None | 0 0
  1. /*
  2. Section G: LIBRARY USERS, VISITS, COMPUTER AND INTERNET
  3.  
  4. Registered Users
  5. G1 Adult__________________________
  6. G2 Juvenile__________________________
  7. G3 TOTAL (G1 + G2)__________________________
  8.  
  9. counts patron accounts under the age of 18 by the end of the fiscal year where the age is blank due to the dob
  10. being null because we used to allow that. we look to see if the account is labeled as juvenile in the description,
  11. this will change after the Fall 2015 profile consolidaiton and we should be able to do it more cleanly off
  12. pgt.name
  13.  
  14. I check for dob first becuase it could be an adult in a child account but I assume if the dob is null that it is on the
  15. exception list above and a child, I look to see if it's marked deleted and if it was marked past the cut off
  16. and if it was created in the last three years
  17.  
  18. */
  19.  
  20. select a.library as "Library", a.adults as "Adults - G1", j.juveniles as "Juveniles - G2", a.adults+j.juveniles as "Total - G3"
  21. from (
  22. SELECT org2.shortname as "library", COUNT(usr.id) AS "adults"
  23. FROM actor.usr usr
  24. JOIN actor.org_unit org ON org.id = usr.home_ou
  25. JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  26. join permission.grp_tree pgt on pgt.id = usr.profile
  27. WHERE
  28. (
  29. date(usr.create_date) >= '2012-07-01'
  30. OR
  31. (
  32. usr.deleted = FALSE
  33. AND
  34. date(usr.expire_date) >= '2012-07-01'
  35. )
  36. )
  37. AND
  38. (
  39. date(usr.dob) <= date('1997-07-01')
  40. OR
  41. (dob IS NULL AND pgt.description not ilike '%juv%')
  42. )
  43. GROUP BY 1
  44. ORDER BY 1
  45. ) a
  46. join (
  47. SELECT org2.shortname as "library", COUNT(usr.id) AS "juveniles"
  48. FROM actor.usr usr
  49. JOIN actor.org_unit org ON org.id = usr.home_ou
  50. JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  51. join permission.grp_tree pgt on pgt.id = usr.profile
  52. WHERE
  53. (
  54. date(usr.create_date) >= '2012-07-01'
  55. OR
  56. (
  57. usr.deleted = FALSE
  58. AND
  59. date(usr.expire_date) >= '2012-07-01'
  60. )
  61. )
  62. AND
  63. (
  64. date(usr.dob) >= date('1997-07-01')
  65. OR
  66. -- next year after next round we should be able to do this more cleanly off pgt.name
  67. (dob IS NULL AND pgt.description ilike '%juv%')
  68. )
  69. GROUP BY 1
  70. ORDER BY 1
  71. ) j on j.library = a.library;
  72.  
  73.  
  74.  
  75. /*
  76.  
  77.  
  78. Section H: REFERENCE, CIRCULATION
  79.  
  80. Circulation Transactions and Interlibrary Loan H2 - H11 (In all sections, if no circulation to report, enter 0)
  81. Juvenile Circulation (may include Teen/YA circulation per library policy)
  82. H2 Print__________________________
  83. H3 Non-Print (not books or electronic/downloadable items)__________________________
  84. H4 TOTAL JUVENILE CIRCULATION (H2 + H3)__________________________
  85.  
  86. Adult Circulation (may include Teen/YA circulation per library policy)
  87. H5 Print__________________________
  88. H6 Non-Print (not books or electronic/downloadable items)__________________________
  89. H7 TOTAL (H5 + H6)__________________________
  90.  
  91. */
  92.  
  93. -------------------------------------- circ by material format from circ mod and shelving location
  94. ------------------------------------------------------------------------------------------------------------------
  95. ------------------------------------------------------------------------------------------------------------------
  96.  
  97. drop table if exists rogan.action_circulation;
  98.  
  99. /* create a table and map per circulation */
  100.  
  101. create table rogan.action_circulation as
  102. select * from action.circulation where date(create_time) between '2014-07-01' and '2015-06-30';
  103.  
  104. alter table rogan.action_circulation add column print boolean default TRUE;
  105.  
  106. /* map print = true based on these circ mods */
  107.  
  108. update rogan.action_circulation set print = false where target_copy in (
  109. select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id
  110. where ac.circ_modifier in ('ELECTRONIC EQUIPMENT','VIDEO','AUDIO','EREADER','PLAYAWAY','AUDIO BOOK',
  111. 'THEME KIT','EQUIPMENT','KIT','INTERNET','GAME','LEASE DVD')
  112. );
  113.  
  114. /* then it got a lot more manual looking at shelving locations. I made a review of a sample of five thousand shelving
  115. location entries and based on that assumed that copies with shelving locations saying AUDIO or VIDEO or EQUIPMENT
  116. should be changed to non-print then I re-ran it with exclusions and found more like DVD */
  117.  
  118. update rogan.action_circulation set print = false where target_copy in (
  119. select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id
  120. join asset.copy_location acl on acl.id = ac.location
  121. where ac.circ_modifier in ('ELECTRONIC EQUIPMENT','VIDEO','AUDIO','EREADER','PLAYAWAY','AUDIO BOOK',
  122. 'THEME KIT','EQUIPMENT','KIT','INTERNET','GAME','LEASE DVD')
  123. and (acl.name ilike '%audio%' or acl.name ilike '%video%' or acl.name ilike '%equipment%' or acl.name ilike '%dvd%'
  124. or acl.name ilike '%books on cd%' or acl.name ilike '%books on cassette%' or acl.name ilike '%music cd%' or
  125. acl.name ilike '%adult 360%' or acl.name ilike '%adult ps2%')
  126. );
  127.  
  128. /* now I will go through all distinct occurances of the library systems and these circ mods with other shelving
  129. location names excluding those that had audio, video or unknown in the name */
  130.  
  131. select DISTINCT aou.parent_ou, ac.circ_modifier, acl.name
  132. from asset.copy ac
  133. join actor.org_unit aou on aou.id = ac.circ_lib
  134. join asset.copy_location acl on acl.id = ac.location
  135. where ac.circ_modifier in ('21 DAY LEASE','14 DAY LEASE','7 DAY LEASE','28 DAY','14 DAY','21 DAY','7 DAY','RENTAL')
  136. and acl.name not ilike '%audio%' and acl.name not ilike '%audio%' and acl.name not ilike '%video%'
  137. and acl.name not ilike '%equipment%' and acl.name not ilike '%dvd%' and acl.name not ilike '%books on cd%'
  138. and acl.name not ilike '%books on cassette%' and acl.name not ilike '%music cd%' and
  139. acl.name not ilike '%adult 360%' and acl.name not ilike '%adult ps2%'
  140. order by 1, 2;
  141.  
  142. alter table rogan.action_circulation add column adult boolean default true;
  143.  
  144. update rogan.action_circulation set adult = false where target_copy in (
  145. select ac.id from asset.copy ac join rogan.action_circulation rcirc on rcirc.target_copy = ac.id
  146. join asset.copy_location acl on acl.id = ac.location
  147. where acl.name ilike '%juv%' or acl.name ilike '%young%'
  148. );
  149.  
  150. SELECT juv_a.shortname as "Library",
  151. juv_a.circs as "Juvenile Print Circs - H2", juv_not_a.circs as "Juvenile Non-Print Circs - H3",
  152. juv_a.circs+juv_not_a.circs as "Total Juvenile Circs - H4",
  153. adult_a.circs+coalesce(non.circs,0) as "Adult Print Circs - H5", adult_not_a.circs as "Adult Non-Print Circs - H6",
  154. adult_a.circs+adult_not_a.circs+coalesce(non.circs,0) as "Total Adult Circs - H7"
  155. FROM (
  156. SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  157. FROM rogan.action_circulation circ
  158. JOIN actor.org_unit org ON org.id = circ.circ_lib
  159. JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  160. WHERE circ.print = true and circ.adult = false
  161. GROUP BY 2
  162. ) juv_a
  163. left join (
  164. SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  165. FROM rogan.action_circulation circ
  166. JOIN actor.org_unit org ON org.id = circ.circ_lib
  167. JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  168. WHERE circ.print = true and circ.adult = true
  169. GROUP BY 2
  170. ) adult_a on adult_a.shortname = juv_a.shortname
  171. left join (
  172. SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  173. FROM rogan.action_circulation circ
  174. JOIN actor.org_unit org ON org.id = circ.circ_lib
  175. JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  176. WHERE circ.print = false and circ.adult = false
  177. GROUP BY 2
  178. ) juv_not_a on juv_not_a.shortname = juv_a.shortname
  179. left join (
  180. SELECT COUNT(circ.id) AS circs, org2.shortname AS shortname
  181. FROM rogan.action_circulation circ
  182. JOIN actor.org_unit org ON org.id = circ.circ_lib
  183. JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  184. WHERE circ.print = false and circ.adult = true
  185. GROUP BY 2
  186. ) adult_not_a on adult_not_a.shortname = juv_a.shortname
  187. left join ( SELECT coalesce(count(circ.id),0) AS circs, org2.shortname AS shortname
  188. FROM action.non_cataloged_circulation circ
  189. left JOIN actor.org_unit org ON org.id = circ.circ_lib
  190. JOIN actor.org_unit org2 ON org2.id = org.parent_ou
  191. where date(circ.circ_time) >= '2014-07-01' AND date(circ.circ_time) <= '2015-06-30'
  192. GROUP BY 2
  193. ) non on non.shortname = juv_a.shortname
  194. ;
  195.  
  196.  
  197.  
  198. /*
  199.  
  200. Interlibrary Loans
  201. H14 Provided to another library__________________________
  202. H15 Received from another library__________________________
  203.  
  204. */
  205.  
  206. /*
  207. -- borrowers at other libraries, these are like reciprocal borrowers
  208. select parent.shortname as "Borrowing Library", count(circ.id) as "circs" from action.circulation circ
  209. join actor.usr au on au.id = circ.usr
  210. join actor.org_unit aou on aou.id = au.home_ou
  211. join actor.org_unit parent on parent.id = aou.parent_ou
  212. join actor.org_unit aou2 on aou2.id = circ.circ_lib
  213. join actor.org_unit parent2 on parent2.id = aou2.parent_ou
  214. WHERE date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30' and parent.id != parent2.id
  215. group by 1 order by 1
  216. ;
  217. */
  218.  
  219. select loaners.shortname, loaners.loans as "Provided to another library - H14", borrowers.borrowers as "Received from another library - H15"
  220. from ( SELECT copyparent.shortname, COUNT(circ.id) as "loans"
  221. FROM ACTION.circulation circ
  222. JOIN asset.COPY ac ON ac.id = circ.target_copy
  223. JOIN actor.org_unit copychild ON copychild.id = ac.circ_lib
  224. JOIN actor.org_unit copyparent ON copyparent.id = copychild.parent_ou
  225. JOIN actor.org_unit circchild ON circchild.id = circ.circ_lib
  226. JOIN actor.org_unit circparent ON circparent.id = circchild.parent_ou
  227. WHERE copyparent.id != circparent.id AND date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30'
  228. GROUP BY 1
  229. ) loaners
  230. join (
  231. SELECT circparent.shortname, COUNT(circ.id) as "borrowers"
  232. FROM ACTION.circulation circ
  233. JOIN asset.COPY ac ON ac.id = circ.target_copy
  234. JOIN actor.org_unit copychild ON copychild.id = ac.circ_lib
  235. JOIN actor.org_unit copyparent ON copyparent.id = copychild.parent_ou
  236. JOIN actor.org_unit circchild ON circchild.id = circ.circ_lib
  237. JOIN actor.org_unit circparent ON circparent.id = circchild.parent_ou
  238. WHERE copyparent.id != circparent.id AND date(circ.xact_start) >= '2014-07-01' AND date(circ.xact_start) <= '2015-06-30'
  239. GROUP BY 1
  240. ) borrowers on borrowers.shortname = loaners.shortname
  241. order by 1
  242. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement