Visualizing Data:
Sierra SQL API and Plotly


2018 SCIUG Conference at Chapman University
(October 23)

Presented by Seong Heon Lee, Systems & Technology Librarian Hugh & Hazel Darling Law Library, Chapman University

Suggested Proposal Topics

  • III Customer Support / new functionality
  • Weeding
  • More Polaris presentations
  • MySQL workshop / SQL report-writing
  • 3rd-party tools w/III products
  • Best practices
  • User experiences (migration)
  • ERMS
  • Encore Duet
  • Sierra APIs
  • Stats / create lists / other ways of reporting
  • Linked Data
  • Electronic ordering
  • Access/User Services issues
  • Interlibrary Loan topics (ex. ILL basics/update)
  • Technology / marketing ideas and the library

Final Product Preview

Circulation Transaction Report

Why?

Sierra has Web Management Reports

  • How many of you are using WMR?
  • What is your user exprience?
  • Decision Center

Why? (continued)

Who uses what?

  • Compare resource usages by libraries
  • Compare by the following criteria:
    • locations
    • patron types
    • item types
    • transaction times
    • etc...

Why? (continued)

Why not?

  • Plenty of data visualization tools (Open Source)
  • Open Library Stacks (Direct SQL & REST API)
  • Customize a data report as you wish

Exploring data
is
fun!

Contents

  1. Plotly (Online & Offline)
  2. Sierra SQL API
  3. Actual Reports (Sierra & Plotly Offline)
  4. Web App (Sierra & Plotly)

What is Plotly?

  • A data analytics and visualization tool
  • Charts & Dashboard
  • Online and Offline
  • Open Source
  • Support multiple languages (Python, JavaScript, R, MATLAB, etc)
  • D3.js(SVG) and stack.gl (WebGL) for web graphics
  • Great API Documentation & Examples

Plotly Online

  • Plotly examples
  • Plotly Create page
    1. Import data: File Upload, URL Link, SQL DB Connector
    2. Select a chart type (bar/pie/scatter) and attibutes (X, Y axes)
    3. Adjust chart styles
    4. Multiple traces in scatter plot (data)

Plotly Offline

Plotly Offline (continued)

How to embed charts in a html?

  • Follow the same rules
  • Use div for output_type, instead of filename
  • Hold a chart in a variable
  • Pass the variable to a template (Jinja2 engine)
  • A template file will receive multiple chart variables

Plotly Offline (continued)

Plotly: Summary

  • Online & Offline
  • Various types of charts
  • Data, Layout, Other attributes
  • Interactive
  • Offline
    • plotly.offline.plot() function
    • output_type='div'
    • template engine (Jinja2) and a template html

Sierra SQL API

  • PostgreSQL relational database
  • Sierra_view schema & 348 tables (read only)
  • User permission to "Sierra SQL Access" required
  • Access to:
    • bibliographic data (bib, item, holding)
    • transactional data (circ_trans, fine, patron)
    • system parameters (location, custom codes, loanrule, properties)
  • By default, 5 concurrent connections per user

PGAdmin, Destkop SQL Client

  • Version 4
  • Connect to database
  • Run SQL queries
  • Show results in tables
  • Creating/testing SQL queries

Setup PGAdmin

Know Sierra Database

  • SierraDNA
  • Learn the structure of Sierra database
  • Find a table in category and search
  • Detailed view of a table
  • ERD (Entity Relationship Diagram) view
  • Example: Transactions > Circulation > checkout

Find Checkouts

(PGAdmin Demo)

					-- Search for checkedout
					SELECT pv.home_library_code, pv.ptype_code, c.checkout_gmt, c.renewal_count, pv.barcode, c.item_record_id 
					FROM sierra_view.checkout AS c
					JOIN sierra_view.patron_view AS pv ON pv.id = c.patron_record_id
					WHERE NOW() - c.checkout_gmt <= interval '3 hours'
					AND pv.home_library_code = 'lhome'
					

Plotly & Sierra

Transactions by Patron Home Library

  • Reuse an offline script
  • Use Sierra data, not a dummy one
  • New things:
    • Connection & query: psycopg2
    • Transform Sierra data to plotly data

Sierra SQL Output

Plotly X Y Axes

Embed Sierra Charts

Can we embed multiple charts in one HTML page?

  • Use the same SQL output from circ_trans
  • Run data transformations on each column
  • Plotly option: output_type='div'
  • Pass chart outputs to the template engine
  • Multiple charts will be embedded as instructed in a template file

Interactive Program

Can we specify days and transaction types?

  • Python sys.argv - read user inputs from terminal
  • User Inputs:
    • days
    • transaction types(o i f r)
    • ouput filename
python sierra_chart_embed.py 60 oi sierra_interactive.html

Sierra SQL API & Plotly: Summary

  • Plotly Python Offline
  • SierraDNA to learn Sierra database
  • PGAdmin to run test queries
  • Python database adapter (psycopg2)
  • Transform data for Plotly
  • Template engine Jinga2 to embed multiple charts
  • Interactive program with user inputs

More Ideas...

  • Create the reports of special purposes
  • Automatically run and deliver reports (scheduler, clone)
  • Explore more data from Sierra (collections, circulation, acquisition)
  • Collect non-Sierra data (counter, space usages, research/reference)
  • Data from other APIs (Googlesheet, LibGuides)
  • Plotly's different charts (map, bubble, heatmap)

What is next?

[ Library Data Group ]

Seong Heon Lee, selee@chapman.edu

THANK YOU.