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

+1
View File
@@ -7,6 +7,7 @@ module AircraftHelper
[ "Squawks", aircraft_squawks_path(aircraft), %w[squawks] ],
[ "Flights", aircraft_flight_logs_path(aircraft), %w[flight_logs flight_imports air_trail_exports airport_codes] ],
[ "Oil & Fuel", aircraft_consumable_records_path(aircraft), %w[consumable_records] ],
[ "Oil Analysis", aircraft_oil_analyses_path(aircraft), %w[oil_analyses] ],
[ "Logbook", aircraft_logbook_entries_path(aircraft), %w[logbook_entries] ],
[ "Inspections", aircraft_inspections_path(aircraft), %w[inspections inspection_types inspection_records] ],
[ "ADs", aircraft_airworthiness_directives_path(aircraft), %w[airworthiness_directives ad_compliances ad_imports] ],
+38
View File
@@ -0,0 +1,38 @@
module OilAnalysesHelper
STATUS_BADGES = { "normal" => "badge-green", "elevated" => "badge-orange", "high" => "badge-red" }.freeze
TREND_COLORS = %w[#0ea5e9 #f97316 #22c55e #a855f7 #eab308 #ec4899 #64748b].freeze
def oil_status_badge(analysis)
tag.span OilAnalysis::STATUSES[analysis.status], class: STATUS_BADGES[analysis.status]
end
def ppm(value)
value.nil? ? "—" : number_with_precision(value, precision: 1, strip_insignificant_zeros: true)
end
# One cell: reading, lab average beneath, highlighted when well above the average.
def ppm_cell(analysis, element)
value = analysis.value(element)
flagged = analysis.flagged?(element)
content = tag.span(ppm(value), class: [ "tabular-nums", ("font-semibold text-red-700" if flagged) ],
title: ("Over #{OilAnalysis::FLAG_RATIO}× the lab average" if flagged))
avg = analysis.average(element)
avg ? safe_join([ content, tag.div("(#{ppm(avg)})", class: "text-xs text-slate-500 tabular-nums") ]) : content
end
# Change in ppm from the previous sample ("+3.2"), blank without one.
def ppm_change(analysis, previous, element)
return "" unless previous && (now = analysis.value(element)) && (before = previous.value(element))
delta = now - before
sign = delta.positive? ? "+" : ""
"#{sign}#{ppm(delta)}"
end
def oil_trend_series(analyses)
chronological = analyses.sort_by(&:sample_date)
OilAnalysis::TREND_ELEMENTS.filter_map do |el|
data = chronological.filter_map { |a| [ a.sample_date, a.value(el).to_f ] if a.value(el) }
{ name: OilAnalysis.element_label(el), data: data } if data.size >= 2
end
end
end