mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15: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
@@ -0,0 +1,78 @@
|
||||
require "test_helper"
|
||||
|
||||
class EngineDataParserTest < ActiveSupport::TestCase
|
||||
def fixture(name) = Rails.root.join("test/fixtures/files/engine_data", name).read
|
||||
def recording = @recording ||= EngineDataParser.new(fixture("cgr30p.csv"), filename: "Flt0144.csv").parse
|
||||
|
||||
test "reads CGR-30P metadata and converts local stamps to UTC" do
|
||||
assert_equal "N12345", recording.metadata[:aircraft_id]
|
||||
assert_equal "144", recording.metadata[:flight_number]
|
||||
assert_equal(-4.hours.to_i, recording.utc_offset)
|
||||
assert_equal Time.utc(2025, 7, 14, 12, 11, 45), recording.started_at
|
||||
assert_equal Time.utc(2025, 7, 14, 8, 11, 45), recording.local(recording.started_at)
|
||||
end
|
||||
|
||||
test "skips the partial row and maps channels by column name" do
|
||||
assert_equal 10, recording.samples
|
||||
assert_equal 4, recording.cylinders
|
||||
assert_equal %i[egt1 egt2 egt3 egt4], recording.egt_keys
|
||||
assert_equal 2530.0, recording.max(:rpm)[0] # the "RPM" column, not RPMLEFT
|
||||
refute recording.channels.key?(:map) # not on this unit
|
||||
end
|
||||
|
||||
test "spreads samples within a second" do
|
||||
second_18 = recording.times.select { _1.to_i == Time.utc(2025, 7, 14, 12, 12, 18).to_i }
|
||||
assert_equal 2, second_18.size
|
||||
assert_in_delta 0.5, second_18.last - second_18.first, 0.001
|
||||
end
|
||||
|
||||
test "summary: engine run, hours, peaks" do
|
||||
assert_equal Time.utc(2025, 7, 14, 12, 12, 17), recording.engine_start
|
||||
assert_equal 519, recording.run_time.to_i # 08:12:17 → 08:20:56
|
||||
assert_equal [ 7149.77, 7149.81 ], [ recording.first(:tach), recording.last(:tach) ]
|
||||
assert_equal [ 436.9, 437.03 ], [ recording.first(:engine_hours), recording.last(:engine_hours) ]
|
||||
assert_equal 0.0, recording.last(:flight_hours)
|
||||
assert_equal({ value: 1261.0, cylinder: 4, at: Time.utc(2025, 7, 14, 12, 17, 41) }, recording.hottest(:egt))
|
||||
assert_equal 265.0, recording.hottest(:cht)[:value]
|
||||
# CHT after shutdown (269 at 08:21:04) doesn't count as a running peak
|
||||
assert_operator recording.fuel_burned, :>, 0
|
||||
end
|
||||
|
||||
test "integrates fuel flow, not across gaps" do
|
||||
r = EngineDataParser.new(<<~CSV).parse
|
||||
CGR-30P Flight Data Recording
|
||||
Local Time: 2025/07/14 08:00:00
|
||||
Zulu Time.: 2025/07/14 12:00:00
|
||||
|
||||
TIME,RPM;***,FLOW;GPH
|
||||
08:00:00,2400,10.0
|
||||
08:00:01,2400,10.0
|
||||
08:00:02,2400,10.0
|
||||
08:05:00,2400,10.0
|
||||
CSV
|
||||
assert_in_delta 10.0 * 2 / 3600, r.fuel_burned, 1e-9
|
||||
end
|
||||
|
||||
test "rolls past midnight" do
|
||||
r = EngineDataParser.new(<<~CSV).parse
|
||||
CGR-30P Flight Data Recording
|
||||
Local Time: 2025/07/14 23:59:59
|
||||
|
||||
TIME,RPM;***
|
||||
23:59:59,2400
|
||||
00:00:00,2400
|
||||
CSV
|
||||
assert_equal Time.utc(2025, 7, 15), r.ended_at
|
||||
end
|
||||
|
||||
test "chart series are thinned and skip blanks" do
|
||||
series = recording.chart(:cht1, :rpm, :nope)
|
||||
assert_equal [ "CHT 1", "RPM" ], series.map { _1[:name] }
|
||||
assert_equal [ recording.started_at, 51.0 ], series.first[:data].first
|
||||
end
|
||||
|
||||
test "rejects other files" do
|
||||
assert_raises(EngineDataParser::Error) { EngineDataParser.new("lat,lon\n1,2\n").parse }
|
||||
assert_raises(EngineDataParser::Error) { EngineDataParser.new("CGR-30P\nLocal Time: 2025/07/14 08:00:00\nTIME,RPM;***\n").parse }
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user