Blackstone oil analysis, .sam.zip export/import, AI logbook transcription

- Oil analysis: Blackstone PDF import (20 elements, oil properties, universal
  averages), results stored per element, oil type, "leave out of trends",
  the original app's statuses; AvLab fixes (multi-line comments, unrelated
  labels no longer steal values). Existing records migrate.
- Aircraft archives in the original app's .sam.zip format (schema v2): export
  from Access & Sharing, background import from the Fleet page, rake tasks.
  Archives move both ways between this app and the original.
- Scanned logbook pages (images or PDFs) upload as a document; with
  ANTHROPIC_API_KEY set, Claude transcribes them into logbook entries.
- Fix: deleting a component or aircraft failed when AD compliances or
  inspection records pointed at a component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-06 21:05:19 -05:00
1 parent 2d068e1a63
commit 1c6c2f88c0
54 files changed
+2794 -286

No files matched your search

@@ -0,0 +1,58 @@
# Oil analysis results go from one column per AvLab element to per-element
# hashes, so labs that test more elements (Blackstone reports 20) fit. Adds oil
# type, oil properties (viscosity, flash point…) and "exclude from averages",
# and switches to the original app's statuses (normal / monitor / action required).
class MoveOilAnalysisResultsToJson < ActiveRecord::Migration[8.1]
ELEMENTS = %w[iron copper nickel chromium silver magnesium aluminum lead silicon titanium tin molybdenum].freeze
STATUS_UP = { "elevated" => "monitor", "high" => "action_required" }.freeze
class Row < ActiveRecord::Base
self.table_name = "oil_analyses"
end
def up
add_column :oil_analyses, :elements, :json, null: false, default: {}
add_column :oil_analyses, :element_averages, :json, null: false, default: {}
add_column :oil_analyses, :oil_properties, :json, null: false, default: {}
add_column :oil_analyses, :oil_type, :string
add_column :oil_analyses, :excluded_from_averages, :boolean, null: false, default: false
change_column_null :oil_analyses, :status, true
change_column_default :oil_analyses, :status, from: "normal", to: nil
Row.reset_column_information
Row.find_each do |row|
row.update_columns(
elements: ELEMENTS.to_h { [ _1, row[_1]&.to_f ] }.compact,
element_averages: ELEMENTS.to_h { [ _1, row["#{_1}_avg"]&.to_f ] }.compact,
status: STATUS_UP.fetch(row.status, row.status)
)
end
ELEMENTS.each do |el|
remove_column :oil_analyses, el
remove_column :oil_analyses, :"#{el}_avg"
end
end
def down
ELEMENTS.each do |el|
add_column :oil_analyses, el, :decimal, precision: 8, scale: 1
add_column :oil_analyses, :"#{el}_avg", :decimal, precision: 8, scale: 1
end
Row.reset_column_information
Row.find_each do |row|
values = ELEMENTS.to_h { [ _1, row.elements[_1] ] }
averages = ELEMENTS.to_h { [ "#{_1}_avg", row.element_averages[_1] ] }
row.update_columns(values.merge(averages).merge(status: STATUS_UP.invert.fetch(row.status, row.status || "normal")))
end
change_column_default :oil_analyses, :status, from: nil, to: "normal"
change_column_null :oil_analyses, :status, false
remove_column :oil_analyses, :elements
remove_column :oil_analyses, :element_averages
remove_column :oil_analyses, :oil_properties
remove_column :oil_analyses, :oil_type
remove_column :oil_analyses, :excluded_from_averages
end
end
@@ -0,0 +1,19 @@
# One upload of an aircraft archive (.sam.zip) and the background job importing it.
class CreateAircraftImports < ActiveRecord::Migration[8.1]
def change
create_table :aircraft_imports do |t|
t.references :user, foreign_key: true
t.references :aircraft, foreign_key: { on_delete: :nullify }
t.string :status, null: false, default: "queued" # queued, running, done, failed
t.string :filename
t.string :tail_number # the tail the aircraft will be created with
t.string :source # where the archive came from (manifest source_instance)
t.json :counts, null: false, default: {}
t.json :warnings, null: false, default: []
t.text :error
t.datetime :started_at
t.datetime :finished_at
t.timestamps
end
end
end
@@ -0,0 +1,23 @@
# Scanned logbook pages uploaded as a document, optionally transcribed into
# logbook entries by Claude (LogbookTranscriptionJob).
class CreateLogbookImports < ActiveRecord::Migration[8.1]
def change
create_table :logbook_imports do |t|
t.references :aircraft, null: false, foreign_key: true
t.references :user, foreign_key: { on_delete: :nullify }
t.references :document, foreign_key: { on_delete: :nullify }
t.string :status, null: false, default: "queued" # queued, running, done, failed
t.boolean :transcribe, null: false, default: true
t.string :log_type # force every entry to this log; nil = Claude decides
t.string :model
t.integer :pages_total, null: false, default: 0
t.integer :pages_done, null: false, default: 0
t.integer :entries_created, null: false, default: 0
t.json :warnings, null: false, default: []
t.text :error
t.datetime :started_at
t.datetime :finished_at
t.timestamps
end
end
end