Skip to content

Commit

Permalink
fix: fix empty cells detection
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtouch committed Aug 1, 2024
1 parent b35026d commit 427545c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions lib/mork/mimage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mork/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Mork
VERSION = '0.15.1'
VERSION = '0.15.2'
end
7 changes: 6 additions & 1 deletion spec/mork/sheet_omr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 427545c

Please sign in to comment.