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:
rickyandClaude Opus 5.5 committed 2026-11-07 10:49:29 -05:00
1 parent bed07386ef
commit 6cab81332e
49 files changed
+1197 -35

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
require "net/http"
# Looks for newly published ADs that may apply to an aircraft. Every AD is
# published in the Federal Register, whose API is public; this searches its
# full text for each of the aircraft's watch terms (by default the aircraft,
# engine and propeller models). Matches are only possibly applicable: the
# owner reviews them on the ADs tab.
class AdWatch
API = "https://www.federalregister.gov/api/v1/documents.json".freeze
FIELDS = %w[document_number title publication_date effective_on html_url abstract docket_ids].freeze
FIRST_LOOKBACK = 2.years
class Error < StandardError; end
def initialize(aircraft)
@aircraft = aircraft
end
# Model names to search for: the owner's list, or the aircraft, engine and
# propeller models.
def self.default_terms(aircraft)
models = [ aircraft.model ] + aircraft.components.in_use.includes(:component_type)
.select { _1.component_type&.name.to_s.match?(/engine|propell?er|\bprop\b/i) }.map(&:model)
models.compact_blank.map { _1.strip }.uniq
end
def terms
custom = @aircraft.ad_watch_terms.to_s.split(/[,;\n]/).map(&:strip).compact_blank
custom.any? ? custom : self.class.default_terms(@aircraft)
end
# Returns the new AdAlerts.
def check!
since = (@aircraft.ad_watch_checked_at || FIRST_LOOKBACK.ago).to_date - 7 # overlap; duplicates are skipped
known = AirworthinessDirective.pluck(:name).to_set
created = terms.flat_map { |term| search(term, since).filter_map { record(_1, term, known) } }
@aircraft.update_column(:ad_watch_checked_at, Time.current)
created
end
private
def record(doc, term, known)
dockets = Array(doc["docket_ids"])
ad_number = dockets.find { _1.start_with?("AD ") }&.delete_prefix("AD ")
return if ad_number && known.include?(ad_number) && @aircraft.applicable_ads.exists?(name: ad_number)
return if @aircraft.ad_alerts.exists?(fr_document_number: doc["document_number"])
@aircraft.ad_alerts.create!(
fr_document_number: doc["document_number"], ad_number: ad_number,
amendment: dockets.find { _1.start_with?("Amendment ") }&.delete_prefix("Amendment "),
title: doc["title"].to_s.truncate(250), abstract: doc["abstract"], html_url: doc["html_url"],
publication_date: doc["publication_date"], effective_on: doc["effective_on"], matched_term: term
)
end
def search(term, since)
query = [
[ "per_page", "50" ], [ "order", "newest" ],
[ "conditions[agencies][]", "federal-aviation-administration" ], [ "conditions[type][]", "RULE" ],
[ "conditions[term]", %("airworthiness directives" "#{term.delete('"')}") ],
[ "conditions[publication_date][gte]", since.iso8601 ]
] + FIELDS.map { [ "fields[]", _1 ] }
uri = URI(API)
uri.query = URI.encode_www_form(query)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 10, read_timeout: 20) do |http|
http.get(uri.request_uri, "Accept" => "application/json", "User-Agent" => "SimpleAircraftManager")
end
raise Error, "the Federal Register returned #{response.code}" unless response.is_a?(Net::HTTPSuccess)
Array(JSON.parse(response.body)["results"]).select { _1["title"].to_s.start_with?("Airworthiness Directives") }
rescue SocketError, SystemCallError, Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError, JSON::ParserError => e
raise Error, "couldn't reach the Federal Register (#{e.class.name.demodulize})"
end
end
+3 -2
View File
@@ -16,9 +16,10 @@ module AircraftArchive
TOP_LEVEL_KEYS = %w[
schema_version exported_at source_instance aircraft component_types components document_collections
documents document_images logbook_entries squawks inspection_types inspection_records ads ad_compliances
consumable_records major_records notes oil_analysis_reports flight_logs features
consumable_records major_records notes oil_analysis_reports flight_logs features weight_balance_records
].freeze
OPTIONAL_KEYS = %w[features].freeze # and flight_logs before schema v2
# Not in archives from the original app (nor flight_logs before schema v2).
OPTIONAL_KEYS = %w[features weight_balance_records].freeze
MANIFEST_MAX_BYTES = 50.megabytes
FILE_MAX_BYTES = 1.gigabyte # the most Admin → Settings allows for uploads
+10 -3
View File
@@ -81,7 +81,12 @@ module AircraftArchive
date_performed: r.date_performed&.iso8601, performed_by: r.performed_by, component_id: id(r.component_id),
form_337_document_id: id(r.form_337_document_id), stc_number: r.stc_number, stc_holder: r.stc_holder,
stc_document_id: id(r.stc_document_id), logbook_entry_id: id(r.logbook_entry_id), aircraft_hours: dec(r.aircraft_hours),
notes: r.notes, has_ica: r.has_ica, ica_notes: r.ica_notes }
notes: r.notes, has_ica: r.has_ica, ica_notes: r.ica_notes, ica_inspection_type_id: id(r.ica_inspection_type_id) }
end,
weight_balance_records: a.weight_balance_records.map do |w|
{ id: id(w), date: w.date&.iso8601, empty_weight: dec(w.empty_weight), empty_arm: dec(w.empty_arm),
max_gross_weight: dec(w.max_gross_weight), reason: w.reason, notes: w.notes,
major_record_id: id(w.major_record_id), document_id: id(w.document_id) }
end,
notes: a.notes.includes(:user).map do |n|
{ id: id(n), aircraft_id: id(a), text: n.text, public: n.public, added_by_display: n.user&.display_name,
@@ -120,7 +125,8 @@ module AircraftArchive
def aircraft_hash(a)
{ id: id(a), tail_number: a.tail_number, make: a.make, model: a.model, serial_number: a.serial_number,
description: a.description, purchased: a.purchased&.iso8601, status: a.status, time_basis: a.time_basis, tach_time: dec(a.tach_time),
description: a.description, purchased: a.purchased&.iso8601, status: a.status, time_basis: a.time_basis,
loading_stations: a.loading_stations, cg_envelope: a.cg_envelope, ad_watch_terms: a.ad_watch_terms, tach_time: dec(a.tach_time),
tach_time_offset: dec(a.tach_time_offset), hobbs_time: dec(a.hobbs_time), hobbs_time_offset: dec(a.hobbs_time_offset),
picture: file(a.picture, "aircraft_pictures"), icao_type: a.icao_type }
end
@@ -139,7 +145,8 @@ module AircraftArchive
{ id: id(e), aircraft_id: id(e.aircraft_id), log_type: e.log_type, date: e.date&.iso8601, text: e.text,
signoff_person: e.signoff_person, signoff_location: e.signoff_location,
signoff_certificate_type: e.signoff_certificate_type, signoff_certificate_number: e.signoff_certificate_number,
inspection_result: e.inspection_result, log_image_id: id(e.document_id),
inspection_result: e.inspection_result, verified: e.verified, transcription_confidence: e.transcription_confidence,
log_image_id: id(e.document_id),
aircraft_hours_at_entry: dec(e.aircraft_hours_at_entry), component_hours: {}, entry_type: e.entry_type,
page_number: e.page_number, components: [], related_documents: [] }
end
+20 -1
View File
@@ -140,6 +140,8 @@ module AircraftArchive
make: a["make"].to_s, model: a["model"].to_s, serial_number: a["serial_number"].to_s, description: a["description"].to_s,
purchased: date(a["purchased"]), status: Aircraft::STATUSES.key?(a["status"]) ? a["status"] : "AVAILABLE",
time_basis: Aircraft::TIME_BASES.key?(a["time_basis"]) ? a["time_basis"] : "tach",
loading_stations: a["loading_stations"].is_a?(Hash) ? a["loading_stations"] : nil,
cg_envelope: a["cg_envelope"].is_a?(Array) ? a["cg_envelope"] : nil, ad_watch_terms: a["ad_watch_terms"].to_s.first(500).presence,
tach_time: num(a["tach_time"] || a["flight_time"]) || 0, tach_time_offset: num(a["tach_time_offset"]) || 0,
hobbs_time: num(a["hobbs_time"]) || 0, hobbs_time_offset: num(a["hobbs_time_offset"]) || 0,
icao_type: a["icao_type"].to_s.upcase.presence&.then { _1.match?(/\A[A-Z0-9]{1,4}\z/) ? _1 : nil }
@@ -227,6 +229,8 @@ module AircraftArchive
signoff_certificate_type: LogbookEntry::CERTIFICATE_TYPES.key?(data["signoff_certificate_type"]) ? data["signoff_certificate_type"] : nil,
signoff_certificate_number: data["signoff_certificate_number"].to_s.presence,
inspection_result: LogbookEntry::INSPECTION_RESULTS.key?(data["inspection_result"]) ? data["inspection_result"] : nil,
verified: data["verified"] != false,
transcription_confidence: %w[high medium low].include?(data["transcription_confidence"]) ? data["transcription_confidence"] : nil,
aircraft_hours_at_entry: num(data["aircraft_hours_at_entry"]), page_number: data["page_number"],
document_id: @map[:document][data["log_image_id"].to_s]
)
@@ -359,11 +363,26 @@ module AircraftArchive
form_337_document_id: @map[:document][data["form_337_document_id"].to_s], stc_number: data["stc_number"].to_s,
stc_holder: data["stc_holder"].to_s, stc_document_id: @map[:document][data["stc_document_id"].to_s],
logbook_entry_id: @map[:logbook][data["logbook_entry_id"].to_s], aircraft_hours: num(data["aircraft_hours"]),
notes: data["notes"].to_s, has_ica: data["has_ica"] == true, ica_notes: data["ica_notes"]
notes: data["notes"].to_s, has_ica: data["has_ica"] == true, ica_notes: data["ica_notes"],
ica_inspection_type_id: @map[:inspection_type][data["ica_inspection_type_id"].to_s]
)
r.save!(validate: false)
(@map[:major_record] ||= {})[data["id"].to_s] = r.id
tick("major_records")
end
import_weight_balance
end
def import_weight_balance
m("weight_balance_records").each do |data|
w = @aircraft.weight_balance_records.new(
date: date(data["date"]) || Date.new(1900, 1, 1), empty_weight: num(data["empty_weight"]) || 0, empty_arm: num(data["empty_arm"]) || 0,
max_gross_weight: num(data["max_gross_weight"]), reason: data["reason"].to_s.presence, notes: data["notes"].to_s.presence,
major_record_id: (@map[:major_record] || {})[data["major_record_id"].to_s], document_id: @map[:document][data["document_id"].to_s]
)
w.save!(validate: false)
tick("weight_balance_records")
end
end
def import_notes