Track oil analysis reports; import AvLab PDFs

New Oil Analysis tab: one record per oil sample with dates, hours, the lab's
verdict and comments, ppm results for 12 wear metals with the lab's averages,
and the report PDF. Shows wear-metal trends, a side-by-side history table,
and flags readings 1.5x or more above the lab average.

AvLab report PDFs can be imported: every sample on the report (current and
previous) is added unless already recorded, the engine is matched by serial
number, and reports for another tail number are refused. The parser reads
positioned text and drops the hidden color-code layer that overlaps results.

Adds the pdf-reader gem. Test fixture is a rebuilt report with a dummy header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-06 06:12:51 -05:00
1 parent 6c6e7af8e6
commit d519aa9aae
24 files changed
+3456 -2

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
require "test_helper"
class OilAnalysisTest < ActiveSupport::TestCase
setup { @a = create_aircraft }
def analysis(**attrs) = @a.oil_analyses.new({ sample_date: Date.current }.merge(attrs))
test "flags readings well above the lab average" do
a = analysis(iron: 60, iron_avg: 35, copper: 10, copper_avg: 20, silicon: 20, silicon_avg: 13.3, tin: 5)
assert a.flagged?("iron")
refute a.flagged?("copper")
assert a.flagged?("silicon") # exactly 1.5×
refute a.flagged?("tin") # no average to compare
assert_equal %w[iron silicon], a.flagged_elements
end
test "validates status, non-negative results, and engine on this aircraft" do
assert analysis.valid?
refute analysis(status: "bad").valid?
refute analysis(iron: -1).valid?
other_engine = create_component(create_aircraft)
a = analysis(component: other_engine)
refute a.valid?
assert_includes a.errors[:component], "must be on this aircraft"
end
end