Skip to content

Instantly share code, notes, and snippets.

@pgwillia
pgwillia / open_access.rb
Created March 14, 2025 22:20
Open access report for ERA
CSV.open('open_access.csv', 'wb') do |csv|
csv << ['year', 'count', 'community', 'collection', 'collection url']
open_access_items = Item.select(:member_of_paths, :created_at)
.where(visibility: JupiterCore::VISIBILITY_PUBLIC)
.group_by { |item| item.created_at.year }
open_access_items.each do |year, items|
items.map(&:member_of_paths).flatten.tally.each do |member_of_path, count|
community_id, collection_id = member_of_path.split('/')
csv << [year, count, Community.find(community_id).title, Collection.find(collection_id).title,
Rails.application.routes.url_helpers.community_collection_url(community_id, collection_id)]
@pgwillia
pgwillia / publishing_datacite_dois.rb
Created March 13, 2025 21:09
Creating a list of publishing doi's from json export files
require 'csv'
require 'json'
CSV.open('publishing_datacite_dois.csv', 'wb') do |csv|
csv << ['doi', 'title', 'url']
["10.18733.json", "10.20360.json", "10.21225.json", "10.21971.json", "10.18740.json", "10.20361.json", "10.21432.json", "10.21991.json", "10.25336.json"].each do |filename|
file = File.open filename
data = JSON.load file
data["data"].each do |doi|
csv << [doi["attributes"]["doi"], doi["attributes"]["titles"][0]["title"], doi["attributes"]["url"]]
@pgwillia
pgwillia / open_access.csv
Last active February 25, 2025 20:42
ERA Open Access report
year count community collection collection url
2025 22 The department of Cat The annals of 'Cat International' http://era.lvh.me:3000/communities/16ebf0dd-19f0-4ee7-a8f5-dfd533652a81/collections/786ee7fe-c345-4a92-8a3e-833724737f62
2025 2 The department of Cat Theses about cats http://era.lvh.me:3000/communities/16ebf0dd-19f0-4ee7-a8f5-dfd533652a81/collections/618912fe-0d3f-470b-bb99-1ee7bacd69a3
2025 22 The department of Unicorn The annals of 'Unicorn International' http://era.lvh.me:3000/communities/d49ff70a-24fd-42a5-97d0-ac1c7747f56e/collections/99df8858-f7bc-4c25-9dc2-cc7181ced3fc
2025 22 Special reports about dogs The annals of 'Dog International' http://era.lvh.me:3000/communities/0917355b-39a7-4484-bdc7-43e9a6a0ee39/collections/2b8f986f-5123-4148-82fb-56794da56cc9
2025 2 Special reports about dogs Theses about dogs http://era.lvh.me:3000/communities/0917355b-39a7-4484-bdc7-43e9a6a0ee39/collections/61618a4e-16a7-4814-bd23-80afbc38f396
2025 2 The department of Unicorn Theses about unicorns http://era.lv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 4.
title,url,change
"The effects of Racer 5 India Pale Ale, Bear Republic Bre on librarians",http://era.lvh.me:3000/items/75304ee2-b398-4f9b-9e3a-ac6184ba575b,"{""visibility""=>[""http://terms.library.ualberta.ca/public"", ""http://terms.library.ualberta.ca/authenticated""], ""updated_at""=>[Wed, 19 Feb 2025 20:18:01.903024000 UTC +00:00, Wed, 19 Feb 2025 21:53:11.875437000 UTC +00:00]}"
The effects of Celebrator Doppelbock on librarians,http://era.lvh.me:3000/items/1114f5e1-1066-4ed4-97cf-f8b9cefbfa18,"{""visibility""=>[""http://terms.library.ualberta.ca/public"", ""http://terms.library.ualberta.ca/authenticated""], ""updated_at""=>[Wed, 19 Feb 2025 20:18:01.972254000 UTC +00:00, Wed, 19 Feb 2025 21:53:11.929598000 UTC +00:00]}"
The effects of Samuel Smith’s Oatmeal Stout on librarians,http://era.lvh.me:3000/items/c158881f-cf20-4b5c-a8f5-e2bc41765e03,"{""visibility""=>[""http://terms.library.ualberta.ca/public"", ""http://terms.library.ualberta.ca/authenticated""], ""updated_at""=>[Wed, 19 Feb 2025 20:18:02.050
builder = Nokogiri::XML::Builder.new do |xml|
xml.send('input-forms') {
xml.send('form-value-pairs') {
CONTROLLED_VOCABULARIES[:jupiter_core].keys.each do |vocab_key|
xml.send('value-pairs') {
xml.send('value-pairs-name', vocab_key.to_s)
if Item.rdf_annotation_for_attr(vocab_key).exists?
xml.send('dc-terms',RDF::URI(Item.rdf_annotation_for_attr(vocab_key).first.predicate).pname.to_s) # TODO acts_as_rdfable
else
xml.send('dc-terms',RDF::URI(Thesis.rdf_annotation_for_attr(vocab_key).first.predicate).pname.to_s) # TODO acts_as_rdfable
@pgwillia
pgwillia / collection_sizes.csv
Last active December 5, 2024 19:45
ERA collections total file sizes
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 4 columns, instead of 2 in line 6.
collection link,collection title,collection size,collection size for humans
http://era.lvh.me:3000/communities/3fab823b-df63-4964-92cd-4d96fb5df3bd/collections/1580d0cc-7c29-44f7-b8ea-983e7588a054,The annals of 'Cat International',132474,129 KB
http://era.lvh.me:3000/communities/3fab823b-df63-4964-92cd-4d96fb5df3bd/collections/336277df-b05f-49c0-856c-b9224642126a,Theses about cats,132474,129 KB
http://era.lvh.me:3000/communities/541e0055-813d-4178-ac36-a94b79cd4127/collections/388bb612-5d5c-4cb9-9f7d-15ccb3f32046,The annals of 'Dog International',132474,129 KB
http://era.lvh.me:3000/communities/541e0055-813d-4178-ac36-a94b79cd4127/collections/808aecb8-c30a-4cdd-b8ad-fea08e45596d,Theses about dogs,132474,129 KB
http://era.lvh.me:3000/communities/11d1643e-0ea8-4b2f-adaa-3a2d2018f803/collections/e9ad79cb-bc09-4fbb-8847-d16711ade4e1,The annals of 'Unicorn International',1323434,1.26 MB
http://era.lvh.me:3000/communities/11d1643e-0ea8-4b2f-adaa-3a2d2018f803/collections/7ffbc573-ff92-4d00-95ee-a60eaf584ca8,Theses a
@pgwillia
pgwillia / destroy_papertrail_report.rb
Last active March 11, 2025 20:56
Reports from ERA/jupiter a) of all destroyed objects tracked by papertrail b) of all items/theses with handles c) items and theses that are drafts or private d) visibility after embargo values d) items and theses with no DOI
CSV.open('destroyed.csv', 'wb') do |csv|
csv << ['item type', 'item id', 'item destroyed at']
PaperTrail::Version.where(event: 'destroy').each do |item|
csv << [item.item_type, item.item_id, item.created_at]
end
end
@pgwillia
pgwillia / docker-compose.yml
Last active July 15, 2024 15:19
Found a openstack swift with keystone. Has potential for testing changes to pmpy. More documentation at https://github.com/kklopfenstein/openstack-swift-keystone-docker. Start with `docker compose up -d`
services:
swift:
# useful if you need to re-run the tests/spec
# https://docs.openstack.org/ocata/cli-reference/swift.html
# manual steps to set environment variables and create container
# swift auth -v -U test:tester -K testing -A http://localhost:8080/auth/v1.0
# swift auth
# swift post ERA
image: kklopfenstein/openstack-swift-keystone-docker
environment:
# Sample configuration file for PushmiPullyu.
# Options here can still be overridden by cmd line args.
# Pass this file at config/pushmi_pullyu.yml and PushmiPullyu will
# pick it up automatically. Or pass this file into pushmi_pullyu on command line
# via `pushmi_pullyu -C path/to/pushmi_pullyu.yml`
# PushmiPullyu will run this file through ERB when reading it so you can
# even put in dynamic logic, like consuming ENV Variables.
require 'application_system_test_case'
class ItemEditTest < ApplicationSystemTestCase
test 'download path is stable after edit' do
admin = users(:user_admin)
item = items(:item_admin)
item.save
# Need to add file to item to be able to go through editing wizard.