mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Unverified transcriptions, PM templates, ICA inspections, W&B, AD watch
- Entries transcribed by Claude are unverified (with Claude's confidence) until an owner checks them against the scan: badge, filter, "mark verified" stepping through the rest - Preventive maintenance templates on new logbook entries, keyed to Part 43 Appendix A(c), setting the entry type and pilot certificate (43.3(g)) - An STC's ICA can become a tracked recurring inspection, linked from its major record - Weight & balance: history of empty weight/CG (linked to the 337 that changed them), loading stations and CG envelope from the POH, and a live calculator for takeoff and landing weight/CG; shown on the status report - New ADs: weekly Federal Register search per aircraft (aircraft, engine and propeller models, or custom terms); track or dismiss each; included in the weekly reminder - Archives carry the new records; brakeman: explicit params, reviewed About-page links Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bed07386ef
commit
6cab81332e
49 files changed
+1197
-35
No files matched your search
@@ -0,0 +1,36 @@
|
||||
# An AD published in the Federal Register that may apply to an aircraft,
|
||||
# waiting for the owner to track it (as an AD to comply with) or dismiss it.
|
||||
class AdAlert < ApplicationRecord
|
||||
STATUSES = %w[new tracked dismissed].freeze
|
||||
|
||||
belongs_to :aircraft
|
||||
belongs_to :airworthiness_directive, optional: true
|
||||
|
||||
validates :fr_document_number, presence: true, uniqueness: { scope: :aircraft_id }
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
|
||||
scope :pending, -> { where(status: "new").order(publication_date: :desc) }
|
||||
|
||||
# Tracks it: the AD (shared across aircraft, matched by number) is linked
|
||||
# to this aircraft, so it counts against airworthiness until complied with.
|
||||
def track!
|
||||
transaction do
|
||||
ad = AirworthinessDirective.find_by(name: ad_number) if ad_number.present?
|
||||
ad ||= AirworthinessDirective.create!(
|
||||
name: ad_number.presence || fr_document_number, short_description: summary, effective_date: effective_on,
|
||||
document_url: html_url, docket_number: amendment, required_action: abstract.to_s.truncate(2000)
|
||||
)
|
||||
ad.aircraft << aircraft unless ad.aircraft.include?(aircraft)
|
||||
update!(status: "tracked", airworthiness_directive: ad)
|
||||
ad
|
||||
end
|
||||
end
|
||||
|
||||
def dismiss! = update!(status: "dismissed")
|
||||
|
||||
# "Requires …" from the abstract, else the title without its prefix.
|
||||
def summary
|
||||
requires = abstract.to_s[/This AD requires ([^.]+)\./, 1]
|
||||
(requires ? "Requires #{requires}" : title.to_s.delete_prefix("Airworthiness Directives; ")).truncate(250)
|
||||
end
|
||||
end
|
||||
@@ -25,6 +25,8 @@ class Aircraft < ApplicationRecord
|
||||
has_many :flight_logs, dependent: :destroy
|
||||
has_many :consumable_records, dependent: :destroy
|
||||
has_many :oil_analyses, dependent: :destroy
|
||||
has_many :weight_balance_records, dependent: :destroy
|
||||
has_many :ad_alerts, dependent: :destroy
|
||||
has_and_belongs_to_many :inspection_types
|
||||
has_and_belongs_to_many :airworthiness_directives
|
||||
|
||||
@@ -52,6 +54,9 @@ class Aircraft < ApplicationRecord
|
||||
end
|
||||
|
||||
def hobbs? = time_basis == "hobbs"
|
||||
|
||||
def current_weight_balance = weight_balance_records.recent_first.first
|
||||
def loading_setup = LoadingSetup.from_aircraft(self)
|
||||
def time_basis_label = TIME_BASES[time_basis]
|
||||
|
||||
def airworthiness
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# Loading stations (name, arm, maximum, fuel or not) and the CG envelope
|
||||
# (weight/CG points in order around the boundary), as entered from the POH.
|
||||
class LoadingSetup
|
||||
include ActiveModel::Model
|
||||
|
||||
Station = Data.define(:name, :arm, :max, :fuel)
|
||||
|
||||
attr_accessor :stations, :envelope, :fuel_lb_per_gal
|
||||
|
||||
def self.from_aircraft(aircraft)
|
||||
data = aircraft.loading_stations.is_a?(Hash) ? aircraft.loading_stations : {}
|
||||
new(stations: Array(data["stations"]).map { Station.new(name: _1["name"], arm: _1["arm"].to_d, max: _1["max"]&.to_d, fuel: _1["fuel"] == true) },
|
||||
envelope: Array(aircraft.cg_envelope).map { [ _1[0].to_d, _1[1].to_d ] },
|
||||
fuel_lb_per_gal: (data["fuel_lb_per_gal"] || 6).to_d)
|
||||
end
|
||||
|
||||
# From the edit form: blank rows are ignored.
|
||||
def self.from_params(p)
|
||||
rows = Array(p["stations"]&.values).reject { _1["name"].to_s.strip.empty? && _1["arm"].to_s.strip.empty? }
|
||||
points = Array(p["envelope"]&.values).reject { _1["weight"].to_s.strip.empty? && _1["cg"].to_s.strip.empty? }
|
||||
setup = new(fuel_lb_per_gal: p["fuel_lb_per_gal"].presence&.to_d || 6, stations: [], envelope: [])
|
||||
setup.instance_variable_set(:@raw_stations, rows)
|
||||
setup.instance_variable_set(:@raw_envelope, points)
|
||||
setup.stations = rows.filter_map do |r|
|
||||
next unless numeric?(r["arm"])
|
||||
Station.new(name: r["name"].to_s.strip.first(40), arm: r["arm"].to_d, max: numeric?(r["max"]) ? r["max"].to_d : nil, fuel: r["fuel"] == "1")
|
||||
end
|
||||
setup.envelope = points.filter_map { numeric?(_1["weight"]) && numeric?(_1["cg"]) ? [ _1["weight"].to_d, _1["cg"].to_d ] : nil }
|
||||
setup
|
||||
end
|
||||
|
||||
def self.numeric?(v) = v.to_s.strip.match?(/\A-?\d+(\.\d+)?\z/)
|
||||
|
||||
validate do
|
||||
raw_s = @raw_stations || []
|
||||
raw_e = @raw_envelope || []
|
||||
errors.add(:base, "Every station needs a name and a numeric arm (inches)") if raw_s.size != stations.size || stations.any? { _1.name.blank? }
|
||||
errors.add(:base, "Every envelope point needs a numeric weight and CG") if raw_e.size != envelope.size
|
||||
errors.add(:base, "The CG envelope needs at least 3 points, or none") if envelope.size.between?(1, 2)
|
||||
errors.add(:base, "Fuel weight per gallon must be between 4 and 9 lb") unless fuel_lb_per_gal.to_d.between?(4, 9)
|
||||
end
|
||||
|
||||
def stations_json
|
||||
{ "fuel_lb_per_gal" => fuel_lb_per_gal.to_f,
|
||||
"stations" => stations.map { { "name" => _1.name, "arm" => _1.arm.to_f, "max" => _1.max&.to_f, "fuel" => _1.fuel } } }
|
||||
end
|
||||
|
||||
def configured? = stations.any?
|
||||
end
|
||||
@@ -33,6 +33,7 @@ class LogbookEntry < ApplicationRecord
|
||||
normalizes :signoff_certificate_type, :inspection_result, :signoff_certificate_number, with: ->(v) { v.strip.presence }
|
||||
|
||||
scope :recent_first, -> { order(date: :desc, created_at: :desc) }
|
||||
scope :unverified, -> { where(verified: false) }
|
||||
|
||||
def self.search(q)
|
||||
return all if q.blank?
|
||||
|
||||
@@ -6,6 +6,9 @@ class MajorRecord < ApplicationRecord
|
||||
belongs_to :form_337_document, class_name: "Document", optional: true
|
||||
belongs_to :stc_document, class_name: "Document", optional: true
|
||||
belongs_to :logbook_entry, optional: true
|
||||
# The recurring inspection this STC's Instructions for Continued
|
||||
# Airworthiness call for (owners must follow ICAs: 91.403(c), 43.13(a)).
|
||||
belongs_to :ica_inspection_type, class_name: "InspectionType", optional: true
|
||||
|
||||
validates :title, :date_performed, presence: true
|
||||
validates :record_type, inclusion: { in: RECORD_TYPES.keys }
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# Logbook wording for common preventive maintenance a pilot-owner may do
|
||||
# (14 CFR 43.3(g)), keyed to Part 43 Appendix A paragraph (c). The item
|
||||
# descriptions are paraphrased; the rule sets each item's limits.
|
||||
module PreventiveMaintenance
|
||||
Item = Data.define(:key, :paragraphs, :label, :work)
|
||||
|
||||
ITEMS = [
|
||||
Item.new("oil_change", %w[(c)(6) (c)(23)], "Oil and filter change", "Drained engine oil and replaced the oil filter. Cut open and inspected the filter: no metal found. Refilled with __ qt of __. Ran engine and checked for leaks."),
|
||||
Item.new("tire", %w[(c)(1)], "Tire removal, installation or repair", "Removed and replaced the __ tire and tube. Inflated to __ psi."),
|
||||
Item.new("strut", %w[(c)(3)], "Servicing landing gear shock struts", "Serviced the __ shock strut with __."),
|
||||
Item.new("bearings", %w[(c)(4)], "Servicing wheel bearings", "Cleaned, inspected and repacked the __ wheel bearings with __ grease."),
|
||||
Item.new("safety_wire", %w[(c)(5)], "Replacing safety wire or cotter keys", "Replaced defective safety wire / cotter key at __."),
|
||||
Item.new("lubrication", %w[(c)(6)], "Lubrication", "Lubricated __ per the maintenance manual."),
|
||||
Item.new("hydraulic", %w[(c)(8)], "Replenishing hydraulic fluid", "Replenished the hydraulic reservoir with __."),
|
||||
Item.new("upholstery", %w[(c)(11)], "Repairing upholstery", "Repaired the upholstery of __."),
|
||||
Item.new("fairings", %w[(c)(12)], "Small repairs to fairings or cowlings", "Made a small repair to the __ (non-structural, contour unchanged)."),
|
||||
Item.new("seat_belts", %w[(c)(14)], "Replacing safety belts", "Replaced the __ safety belt with P/N __."),
|
||||
Item.new("landing_light_wiring", %w[(c)(16)], "Repairing landing light circuits", "Troubleshot and repaired a broken circuit in the landing light wiring."),
|
||||
Item.new("lights", %w[(c)(17)], "Replacing light bulbs, reflectors or lenses", "Replaced the __ position/landing light bulb with P/N __. Checked operation."),
|
||||
Item.new("cowling", %w[(c)(19)], "Replacing a cowling", "Removed and reinstalled the __ cowling."),
|
||||
Item.new("spark_plugs", %w[(c)(20)], "Cleaning or replacing spark plugs", "Removed, cleaned, gapped and rotated the spark plugs. Reinstalled and torqued to __."),
|
||||
Item.new("hoses", %w[(c)(21)], "Replacing hose connections (not hydraulic)", "Replaced the __ hose with P/N __."),
|
||||
Item.new("fuel_lines", %w[(c)(22)], "Replacing prefabricated fuel lines", "Replaced the prefabricated fuel line __ with P/N __."),
|
||||
Item.new("filters", %w[(c)(23)], "Cleaning or replacing fuel/oil strainers or filters", "Cleaned / replaced the __ strainer / filter element."),
|
||||
Item.new("battery", %w[(c)(24)], "Replacing or servicing the battery", "Replaced the battery with P/N __ / serviced the battery."),
|
||||
Item.new("fasteners", %w[(c)(26)], "Replacing non-structural fasteners", "Replaced non-structural standard fasteners at __."),
|
||||
Item.new("chip_detector", %w[(c)(29)], "Checking magnetic chip detectors", "Removed, checked and reinstalled the magnetic chip detector: no particles found."),
|
||||
Item.new("nav_database", %w[(c)(31)], "Updating the navigation database", "Updated the __ navigation database to cycle __."),
|
||||
Item.new("nav_com", %w[(c)(32)], "Swapping a tray-mounted nav/com unit", "Removed and reinstalled the tray-mounted __ unit. Checked operation.")
|
||||
].freeze
|
||||
|
||||
module_function
|
||||
|
||||
def text_for(item)
|
||||
"#{item.work} Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph #{item.paragraphs.to_sentence}."
|
||||
end
|
||||
end
|
||||
@@ -19,11 +19,12 @@ class SystemInfo
|
||||
"unknown"
|
||||
end
|
||||
|
||||
def repository_url = REPOSITORY_URL.chomp("/")
|
||||
# Only an http(s) address is linked (it comes from the environment).
|
||||
def repository_url = REPOSITORY_URL.match?(%r{\Ahttps?://[^\s"'<>]+\z}) ? REPOSITORY_URL.chomp("/") : nil
|
||||
|
||||
# The running commit on the repository host, when the revision is known.
|
||||
def revision_url
|
||||
"#{repository_url}/commit/#{revision}" if revision.match?(/\A\h{7,40}\z/)
|
||||
"#{repository_url}/commit/#{revision}" if repository_url && revision.match?(/\A\h{7,40}\z/)
|
||||
end
|
||||
|
||||
def built_at
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# One weight & balance report: the aircraft's empty weight and CG as of a
|
||||
# date, usually after weighing or an equipment change (each alteration that
|
||||
# changes them needs a new one; its 337 can be linked).
|
||||
class WeightBalanceRecord < ApplicationRecord
|
||||
belongs_to :aircraft
|
||||
belongs_to :major_record, optional: true
|
||||
belongs_to :document, optional: true
|
||||
|
||||
validates :date, presence: true
|
||||
validates :empty_weight, numericality: { greater_than: 0 }
|
||||
validates :empty_arm, numericality: true
|
||||
validates :max_gross_weight, numericality: { greater_than: 0 }, allow_nil: true
|
||||
validate { errors.add(:max_gross_weight, "must be more than the empty weight") if max_gross_weight && empty_weight && max_gross_weight <= empty_weight }
|
||||
|
||||
scope :recent_first, -> { order(date: :desc, created_at: :desc) }
|
||||
|
||||
def empty_moment = empty_weight * empty_arm
|
||||
def useful_load = max_gross_weight && max_gross_weight - empty_weight
|
||||
end
|
||||
Reference in new issue
Block a user