Skip to content

Commit

Permalink
work with wax cli, new progress scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
mnyrop committed Sep 26, 2023
1 parent f2b38a7 commit dc76324
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.2
3.2.2
37 changes: 16 additions & 21 deletions lib/wax_iiif/builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_relative 'utilities'

require 'pathname'
require 'progress_bar'
require 'parallel'

module WaxIiif
Expand Down Expand Up @@ -65,35 +64,27 @@ def load(data)
#
# @return [Void]
#
def process_data(thread_count: Parallel.processor_count)
puts Rainbow("Running on #{thread_count} threads.").blue

def process_data
return nil if @data.nil? # do nothing without data.

@manifests = []

data = @data.group_by(&:manifest_id)
bar = ProgressBar.new(data.length)
bar.write

data.each do |key, value|
@manifests = Parallel.map(data, in_threads: Parallel.processor_count, progress: { format: Rainbow("\t⏵ %e %B %c/%u %P% Complete").skyblue, length: 80 }) do |key, value|
manifest_id = key
image_records = value
resources = process_image_records(image_records,
thread_count: thread_count)
resources = process_image_records(image_records)
results = []

# Generate the manifest
if manifest_id.to_s.empty?
resources.each do |_key, val|
manifests.push generate_manifest(val, @config)
results.push generate_manifest(val, @config)
end
else
manifests.push generate_manifest(image_records, @config)
results.push generate_manifest(image_records, @config)
end

bar.increment!
bar.write
end
results
end.flatten

generate_collection
end
Expand All @@ -104,6 +95,12 @@ def generate_collection
collection.save
end

def results
results = {}
manifests.each { |manifest| results[manifest.base_id] = manifest.path }
results
end

# Creates the required directories for exporting to the file system.
#
# @return [Void]
Expand Down Expand Up @@ -240,12 +237,11 @@ def generate_variants(data, config)
obj
end

def process_image_records(image_records,
thread_count: Parallel.processor_count)
def process_image_records(image_records)
resources = {}

# genrate the images
Parallel.each(image_records, in_threads: thread_count) do |image_record|
image_records.each do |image_record|
# It attempts to load the info files and skip generation - not currently working.
info_file = image_info_file_name(image_record)
if File.exist?(info_file)
Expand All @@ -260,7 +256,6 @@ def process_image_records(image_records,
resources[image_record.id] ||= []
resources[image_record.id].push image_record
end

resources
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/wax_iiif/image_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def path=(path)
@path = path
end


# The name of the section this image is contained in.
# Currently used to id the canvas for this image.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/wax_iiif/image_tile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(data, config, tile)
def resize(_width = nil, _height = nil)
return if @tile[:width] == 0
@image = @image.crop @tile[:x], @tile[:y], @tile[:width], @tile[:height]
@image = @image.thumbnail_image(@tile[:xSize], { height: @tile[:ySize] })
@image = @image.thumbnail_image @tile[:xSize], height: @tile[:ySize]
end

def region
Expand Down
4 changes: 4 additions & 0 deletions lib/wax_iiif/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def initialize(image_records, config, opts = {})
@sequences = build_sequence(image_records)
end

def path
@id.gsub(@config.base_url, @config.output_dir)
end

#
# @return [String] the JSON-LD representation of the manifest as a string.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/wax_iiif/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module WaxIiif
VERSION = '0.3.0'
VERSION = '1.0.0'
end
17 changes: 8 additions & 9 deletions wax_iiif.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/minicomp/wax_iiif'
spec.license = 'MIT'

spec.required_ruby_version = '>= 2.4'
spec.required_ruby_version = '>= 3.0'
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.requirements << 'libvips'

spec.add_development_dependency 'dotenv', '~> 2.7'
spec.add_development_dependency 'rspec', '~> 3.8'
spec.add_development_dependency 'simplecov', '~> 0.16'
spec.add_development_dependency 'dotenv'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'simplecov'

spec.add_runtime_dependency 'ruby-vips', '~> 2.1'
spec.add_runtime_dependency 'parallel', '~> 1.17'
spec.add_runtime_dependency 'pdf-reader', '~> 2.4'
spec.add_runtime_dependency 'progress_bar', '~> 1.3'
spec.add_runtime_dependency 'rainbow', '~> 3.0'
spec.add_runtime_dependency 'ruby-vips'
spec.add_runtime_dependency 'parallel'
spec.add_runtime_dependency 'pdf-reader'
spec.add_runtime_dependency 'rainbow'
end

0 comments on commit dc76324

Please sign in to comment.