diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..af70a54 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: CI + +on: + pull_request: + push: + branches: [ main ] + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + ruby: ['3.0', '3.1', '3.2', '3.3'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install package dependencies + run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS" + env: + APT_DEPS: "imagemagick" + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby}} + bundler-cache: true + + - name: Run tests + run: bundle exec rspec diff --git a/lib/mork/mimage.rb b/lib/mork/mimage.rb index 2f71d1e..dc00e49 100644 --- a/lib/mork/mimage.rb +++ b/lib/mork/mimage.rb @@ -51,12 +51,14 @@ def choice_mean_darkness end def marked - @marked_choices ||= begin - choice_mean_darkness.map do |cho| - [].tap do |choices| - cho.map.with_index do |drk, c| - choices << c if drk < choice_threshold - end + @marked_choices ||= + choice_mean_darkness + # We use the unmarked X cells to compute the reference darkness for each row + .zip(@grom.calibration_cell_areas.map { |c| reg_pixels.average c }.cycle) + .map do |cho, ref| + [].tap do |choices| + cho.map.with_index do |drk, c| + choices << c if drk < [ref * 0.95, choice_threshold].min end end end diff --git a/lib/mork/version.rb b/lib/mork/version.rb index 3ad696b..e164042 100644 --- a/lib/mork/version.rb +++ b/lib/mork/version.rb @@ -1,3 +1,3 @@ module Mork - VERSION = '0.15.1' + VERSION = '0.15.2' end diff --git a/spec/mork/sheet_omr_spec.rb b/spec/mork/sheet_omr_spec.rb index c2b9aa9..7bc5ae5 100644 --- a/spec/mork/sheet_omr_spec.rb +++ b/spec/mork/sheet_omr_spec.rb @@ -13,7 +13,7 @@ module Mork describe 'trying to process a corrupted file' do it 'throws an IO error' do fn = sample_img('corrupted-pdf').image_path - expect { SheetOMR.new fn}.to raise_error(IOError, 'Invalid image. File may have been damaged') + expect { SheetOMR.new fn }.to raise_error(IOError) end end end @@ -190,6 +190,7 @@ module Mork let(:barr0) { SheetOMR.new 'spec/samples/syst/barr0.jpg', choices: [5]*100, layout: 'spec/samples/syst/layout.yml'} let(:barr1) { SheetOMR.new 'spec/samples/syst/barr1.jpg', choices: [5]*100, layout: 'spec/samples/syst/layout.yml'} let(:barr2) { SheetOMR.new 'spec/samples/syst/barr2.jpg', choices: [5]*100, layout: 'spec/samples/syst/layout.yml'} + let(:default) {SheetOMR.new 'spec/samples/standard.png', choices: [5] * 120, layout: 'spec/samples/syst/layout.yml'} it 'checks bila' do expect(bila0.marked_letters.flatten).to eq(bila) @@ -229,6 +230,10 @@ module Mork expect(barr1.marked_letters.flatten).to eq(barr) expect(barr2.marked_letters.flatten).to eq(barr) end + + it 'checks default is unchecked' do + expect(default.marked_letters).to eq(Array.new(120, [])) + end end # context "multi-page pdf" do # before(:all) do