mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
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:
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
|
||||
Generated
+52
-26
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.1].define(version: 2026_11_06_170000) do
|
||||
ActiveRecord::Schema[8.1].define(version: 2026_11_06_180800) do
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
@@ -140,6 +140,24 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_06_170000) do
|
||||
t.index ["user_id"], name: "index_aircraft_events_on_user_id"
|
||||
end
|
||||
|
||||
create_table "aircraft_imports", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "aircraft_id"
|
||||
t.string "status", default: "queued", null: false
|
||||
t.string "filename"
|
||||
t.string "tail_number"
|
||||
t.string "source"
|
||||
t.json "counts", default: {}, null: false
|
||||
t.json "warnings", default: [], null: false
|
||||
t.text "error"
|
||||
t.datetime "started_at"
|
||||
t.datetime "finished_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["aircraft_id"], name: "index_aircraft_imports_on_aircraft_id"
|
||||
t.index ["user_id"], name: "index_aircraft_imports_on_user_id"
|
||||
end
|
||||
|
||||
create_table "aircraft_inspection_types", id: false, force: :cascade do |t|
|
||||
t.integer "aircraft_id", null: false
|
||||
t.integer "inspection_type_id", null: false
|
||||
@@ -397,6 +415,28 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_06_170000) do
|
||||
t.index ["document_id"], name: "index_logbook_entries_on_document_id"
|
||||
end
|
||||
|
||||
create_table "logbook_imports", force: :cascade do |t|
|
||||
t.integer "aircraft_id", null: false
|
||||
t.integer "user_id"
|
||||
t.integer "document_id"
|
||||
t.string "status", default: "queued", null: false
|
||||
t.boolean "transcribe", default: true, null: false
|
||||
t.string "log_type"
|
||||
t.string "model"
|
||||
t.integer "pages_total", default: 0, null: false
|
||||
t.integer "pages_done", default: 0, null: false
|
||||
t.integer "entries_created", default: 0, null: false
|
||||
t.json "warnings", default: [], null: false
|
||||
t.text "error"
|
||||
t.datetime "started_at"
|
||||
t.datetime "finished_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["aircraft_id"], name: "index_logbook_imports_on_aircraft_id"
|
||||
t.index ["document_id"], name: "index_logbook_imports_on_document_id"
|
||||
t.index ["user_id"], name: "index_logbook_imports_on_user_id"
|
||||
end
|
||||
|
||||
create_table "major_records", force: :cascade do |t|
|
||||
t.integer "aircraft_id", null: false
|
||||
t.integer "component_id"
|
||||
@@ -434,35 +474,16 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_06_170000) do
|
||||
t.decimal "oil_hours", precision: 6, scale: 1
|
||||
t.decimal "filter_hours", precision: 6, scale: 1
|
||||
t.decimal "oil_added", precision: 6, scale: 2
|
||||
t.string "status", default: "normal", null: false
|
||||
t.string "status"
|
||||
t.text "lab_comments"
|
||||
t.text "notes"
|
||||
t.decimal "iron", precision: 8, scale: 1
|
||||
t.decimal "iron_avg", precision: 8, scale: 1
|
||||
t.decimal "copper", precision: 8, scale: 1
|
||||
t.decimal "copper_avg", precision: 8, scale: 1
|
||||
t.decimal "nickel", precision: 8, scale: 1
|
||||
t.decimal "nickel_avg", precision: 8, scale: 1
|
||||
t.decimal "chromium", precision: 8, scale: 1
|
||||
t.decimal "chromium_avg", precision: 8, scale: 1
|
||||
t.decimal "silver", precision: 8, scale: 1
|
||||
t.decimal "silver_avg", precision: 8, scale: 1
|
||||
t.decimal "magnesium", precision: 8, scale: 1
|
||||
t.decimal "magnesium_avg", precision: 8, scale: 1
|
||||
t.decimal "aluminum", precision: 8, scale: 1
|
||||
t.decimal "aluminum_avg", precision: 8, scale: 1
|
||||
t.decimal "lead", precision: 8, scale: 1
|
||||
t.decimal "lead_avg", precision: 8, scale: 1
|
||||
t.decimal "silicon", precision: 8, scale: 1
|
||||
t.decimal "silicon_avg", precision: 8, scale: 1
|
||||
t.decimal "titanium", precision: 8, scale: 1
|
||||
t.decimal "titanium_avg", precision: 8, scale: 1
|
||||
t.decimal "tin", precision: 8, scale: 1
|
||||
t.decimal "tin_avg", precision: 8, scale: 1
|
||||
t.decimal "molybdenum", precision: 8, scale: 1
|
||||
t.decimal "molybdenum_avg", precision: 8, scale: 1
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.json "elements", default: {}, null: false
|
||||
t.json "element_averages", default: {}, null: false
|
||||
t.json "oil_properties", default: {}, null: false
|
||||
t.string "oil_type"
|
||||
t.boolean "excluded_from_averages", default: false, null: false
|
||||
t.index ["aircraft_id", "sample_date"], name: "index_oil_analyses_on_aircraft_id_and_sample_date"
|
||||
t.index ["aircraft_id"], name: "index_oil_analyses_on_aircraft_id"
|
||||
t.index ["component_id"], name: "index_oil_analyses_on_component_id"
|
||||
@@ -530,6 +551,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_06_170000) do
|
||||
add_foreign_key "air_trail_syncs", "flight_logs"
|
||||
add_foreign_key "aircraft_events", "aircraft"
|
||||
add_foreign_key "aircraft_events", "users", on_delete: :nullify
|
||||
add_foreign_key "aircraft_imports", "aircraft", on_delete: :nullify
|
||||
add_foreign_key "aircraft_imports", "users"
|
||||
add_foreign_key "aircraft_notes", "aircraft"
|
||||
add_foreign_key "aircraft_notes", "users", on_delete: :nullify
|
||||
add_foreign_key "aircraft_roles", "aircraft"
|
||||
@@ -552,6 +575,9 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_06_170000) do
|
||||
add_foreign_key "inspection_records", "logbook_entries", on_delete: :nullify
|
||||
add_foreign_key "logbook_entries", "aircraft"
|
||||
add_foreign_key "logbook_entries", "documents", on_delete: :nullify
|
||||
add_foreign_key "logbook_imports", "aircraft"
|
||||
add_foreign_key "logbook_imports", "documents", on_delete: :nullify
|
||||
add_foreign_key "logbook_imports", "users", on_delete: :nullify
|
||||
add_foreign_key "major_records", "aircraft"
|
||||
add_foreign_key "major_records", "components", on_delete: :nullify
|
||||
add_foreign_key "major_records", "documents", column: "form_337_document_id", on_delete: :nullify
|
||||
|
||||
Reference in new issue
Block a user