mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Add engine monitor data (CGR-30P/CGR-30C) to flight logs
Attach a CGR-30 flight recording when logging a flight or later from the flight page. The flight page shows engine run time, fuel burned, tach and engine hours, peak RPM/EGT/CHT/oil/fuel flow, and charts per cylinder. Unreadable files are rejected; recordings from another tail are flagged. Also replace the real tail number in test data with N12345. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86aadfcf6c
commit
6c6e7af8e6
12 files changed
+561
-6
No files matched your search
@@ -8,11 +8,13 @@ class FlightLog < ApplicationRecord
|
||||
before_destroy :remember_air_trail_flights, prepend: true
|
||||
has_many :air_trail_syncs, dependent: :delete_all
|
||||
has_one_attached :track_log
|
||||
has_one_attached :engine_data # engine monitor recording (CGR-30P CSV)
|
||||
|
||||
validates :date, presence: true
|
||||
validates :tach_time, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
validates :hobbs_time, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
||||
validates_uploads :track_log
|
||||
validates_uploads :track_log, :engine_data
|
||||
validate :engine_data_readable
|
||||
before_validation :derive_times
|
||||
normalizes :departure_location, :destination_location, with: ->(code) { code.strip.upcase.presence }
|
||||
after_commit :push_to_air_trail, on: %i[create update]
|
||||
@@ -26,6 +28,19 @@ class FlightLog < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
# Reject files the engine data parser can't read, before they're stored.
|
||||
def engine_data_readable
|
||||
change = attachment_changes["engine_data"]
|
||||
io = change.attachable if change.is_a?(ActiveStorage::Attached::Changes::CreateOne)
|
||||
io = io[:io] if io.is_a?(Hash)
|
||||
return unless io.respond_to?(:read)
|
||||
content = io.read
|
||||
io.rewind
|
||||
EngineDataParser.new(content, filename: engine_data.filename.to_s).parse
|
||||
rescue EngineDataParser::Error => e
|
||||
errors.add(:engine_data, e.message)
|
||||
end
|
||||
|
||||
def push_to_air_trail
|
||||
AirTrailPushJob.perform_later(id) if user_id && AirTrailConnection.active.exists?(user_id: user_id)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user