Skip to content

Instantly share code, notes, and snippets.

@rayvoelker
rayvoelker / original_circ.md
Last active January 10, 2023 19:22
some notes on finding "orginal circ"

Finding Original Circulation

finding checkouts without any paired "filled hold" transactions will be how we define an "original circ".

the idea is that we match a "filled hold" with a 'checkout' based on 4 points of data op_code, patron_record_id, item_record_id, transaction_gmt

@rayvoelker
rayvoelker / spec.json
Created February 20, 2021 04:46
Vega-Lite spec from Fri Feb 19 2021
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"layer": [
{
"mark": {"type": "bar", "color": "#0090bd"},
"encoding": {
"tooltip": [
{"type": "nominal", "field": "median_income_range"},
{"type": "quantitative", "field": "percent_over_10usd"},
{"type": "quantitative", "field": "total_patrons"},
@rayvoelker
rayvoelker / spec.json
Created October 14, 2020 16:28
Vega-Lite spec from Wed Oct 14 2020
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"vconcat": [
{
"data": {"name": "data-465faa1de7ff9354eb5c0b9c2a57536b"},
"mark": "line",
"encoding": {
"color": {"type": "quantitative", "field": "overdue_count"},
"x": {"type": "ordinal", "field": "iso8601_week"},
"y": {
@rayvoelker
rayvoelker / find_checkouts_with_hold_filled.sql
Created July 30, 2020 18:10
link checkouts to a filled hold checkout
-- EXPLAIN QUERY PLAN
with ops as (
with variables as (
SELECT
'2020-07-19' as min_date,
'2020-07-26' as max_date,
'1' as location_code
)
@rayvoelker
rayvoelker / spec.json
Created July 28, 2020 12:47
2019-2020 Accumulated Circulations by Week
{
"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}},
"vconcat": [
{
"data": {"name": "data-c73cbde8aa602c2cd52c8984bda1552f"},
"mark": "bar",
"encoding": {
"color": {"type": "nominal", "field": "circ_op"},
"tooltip": [
{"type": "ordinal", "field": "date"},
@rayvoelker
rayvoelker / export_circ_trans_in_date_range.sql
Last active July 9, 2020 18:21
export circulation transactions from a date range from the data snapshots
-- first import the weekly circ_trans data into an sqlite database
-- next adjust the date range
-- export the data into another .csv
-- NOTE: date range is calendar week ... NOT ISO WEEK
with id_range as (
select
min(id) as min_id,
max(id) as max_id
@rayvoelker
rayvoelker / 2020-07-01-sierra_fines_purged.sql
Last active July 7, 2020 12:28
from sierra, produce a list of fines purged from a date range
-- find all the "fines purged" in the fines_paid table by specific date.
-- group them by
DROP TABLE IF EXISTS temp_patron_purge_amts;
CREATE TEMP TABLE temp_patron_purge_amts AS
SELECT
date(p.paid_date_gmt) as date_purged,
case cast( charge_type_code as text)
@rayvoelker
rayvoelker / fines_purged_by_date_and_charge_type.sql
Created July 3, 2020 01:36
find all the "fines purged" in the fines_paid table by specific date. group them by the charge type
-- find all the "fines purged" in the fines_paid table by specific date.
-- group them by the charge type
DROP TABLE IF EXISTS temp_patron_purge_amts;
CREATE TEMP TABLE temp_patron_purge_amts AS
SELECT
date(p.paid_date_gmt) as date_purged,
case cast( charge_type_code as text)
@rayvoelker
rayvoelker / find_backdated_checkin_transactions_SQLite.sql
Created June 22, 2020 19:17
This will find backdated checkin transactions from the circ_trans table, and will attempt to place a date onto that transaction close-to the ACTUAL date of the transaction
-- explain query plan
with backdate_trans as
(
select
c.id,
c.transaction_gmt as backdate_transaction_gmt,
(
with min_id as (
select
max(id) as id
@rayvoelker
rayvoelker / find_backdated_checkin_transactions.sql
Created June 9, 2020 14:10
This will find backdated checkin transactions from the circ_trans table, and will attempt to place a date onto that transaction close-to the ACTUAL date of the transaction
-- this will find backdated checkin transactions from the circ_trans table, and
-- will attempt to place a date that transaction with an ACTUAL date
DROP TABLE IF EXISTS temp_stat_groups;
CREATE TEMP TABLE temp_stat_groups AS
SELECT
s.code AS stat_group_code_num,
s.location_code AS location_code,
s.name as name
FROM