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
+26
@@ -0,0 +1,26 @@
|
||||
Electronics International Inc
|
||||
CGR-30P Flight Data Recording
|
||||
Aircraft ID....: N12345
|
||||
Unit ID........: 10000000
|
||||
EDC Models.....: P-4-6-H,,
|
||||
SW Version.....: 1.2
|
||||
Tracking Number: 1
|
||||
Local Time: 2025/07/14 08:11:45
|
||||
Zulu Time.: 2025/07/14 12:11:45
|
||||
Flight Number: 144
|
||||
Engine Hours.: 436.90 hrs
|
||||
Tach Time....: 7149.77 hrs
|
||||
Data Logging Interval: 0.3 sec
|
||||
|
||||
TIME,SEL TANK QTY,RPMLEFT;RPM,RPMRIGHT;RPM,RPM;***,TEMP COMP;*F,VOLTS;V,VOLTS ANN;V,AMPS;A,FLOW;GPH,EGT1;*F,EGT2;*F,EGT3;*F,EGT4;*F,EGT:;***,EGT-D:;***,EGT-H:;***,CHT1;*F,CHT2;*F,CHT3;*F,CHT4;*F,CHT:;***,CHT-D:;***,CHT-H:;***,FUEL L;GAL,FUEL L ANN;GAL,FUEL R;GAL,FUEL R ANN;GAL,OIL P;PSI,OIL T;*F,OIL T ANN;*F,FLT;HRS,TACH;HRS,ENG;HRS,EST TOTAL;GAL,EST F;GAL,RANGE;NM,TO DEST;NM,AT DEST;NM,REMAIN;GAL,TO DEST;GAL,AT DEST;GAL,TO EMPTY;H:M,TO DEST;H:M,AT DEST;H:M,DISTANCE;NM,TIME;H:M,QUANTITY;GAL,FLIGHT;GAL,SINCE ADD;GAL,ECONOMY;MPG,ENGINE;GPH,SWITCH IN;H:M,SWTCH ANN; ,FUEL ANN; ,GPS Altitude,Gnd Speed,Wpt,Dist to Wpt,Dist to Dest,Latitude,Longitude
|
||||
08:11:45,TOTAL : 14.79,0,0,0,58,12.5,12.5,-3.6,0.0,58,57,58,57,51,1,51,51,51,51,51,43,0,43,2.8,2.8,0.0,0.0,0,51,51, 0.00,7149.77,436.90,14.8,14.8,0.0,0.0,0.0,14.8,0.0,0.0, 99:59, 0:00, 0:00,0.0, 99:59,0.0,0.0,7.5,0.0,0.0,359940.0,100.0,14.8, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:11:46,TOTAL : 14.79,0,0,0,65,12.5,12.5,-4.0,0.0,65,64,65,64,58,1,58,58,58,58,58,51,0,51,3.1,3.1,1.5,1.5,0,58,58, 0.00,7149.77,436.90,14.8,14.8,0.0,0.0,0.0,14.8,0.0,0.0, 99:59, 0:00, 0:00,0.0, 99:59,0.0,0.0,7.5,0.0,0.0,359940.0,100.0,14.8, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:12:17,TOTAL : 14.79,710,720,720,65,11.3,11.3,-7.7,0.7,65,64,67,64,65,1,65,65,65,65,65,65,0,65,9.9,9.9,4.8,4.8,0,65,65, 0.00,7149.77,436.90,14.8,14.8,0.0,0.0,0.0,14.8,0.0,0.0, 99:59, 0:00, 0:00,0.0, 99:59,0.0,0.0,7.5,0.0,0.7,59.0,100.0,14.8, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:12:18,TOTAL : 14.79,970,970,970,65,11.7,11.7,-5.8,2.0,68,64,70,64,67,3,67,65,65,65,65,65,0,65,9.9,9.9,4.9,4.9,0,65,65, 0.00,7149.77,436.90,14.8,14.8,0.0,0.0,0.0,14.8,0.0,0.0, 21:51, 0:00, 0:00,0.0, 21:51,0.0,0.0,7.5,0.0,2.0,59.0,100.0,14.8, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:12:18,TOTAL : 14.79,850,850,850,65,12.0,12.0,-3.4,2.4,71,68,70,65,70,6,70,65,65,65,65,65,0,65,9.9,9.9,4.9,4.9,0,65,65, 0.00,7149.77,436.90,14.8,14.8,0.0,0.0,0.0,14.8,0.0,0.0, 7:17, 0:00, 0:00,0.0, 7:17,0.0,0.0,7.5,0.0,2.4,59.0,100.0,14.8, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:17:38,TOTAL : 14.72,2450,2490,2490,66,14.6,14.6,8.8,6.8,1059,1165,1180,1226,1217,165,1217,187,198,174,201,201,27,201,9.5,9.5,5.0,5.0,42,78,78, 0.00,7149.78,436.97,14.7,14.7,0.0,0.0,0.0,14.7,0.0,0.0, 2:10, 0:00, 0:00,0.0, 2:10,0.0,0.0,7.6,0.0,6.8,59.0,100.0,14.7, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:17:41,TOTAL : 14.71,2530,2530,2530,66,14.6,14.6,7.9,7.8,1116,1212,1222,1261,1257,148,1257,189,197,174,204,203,29,203,9.4,9.4,5.0,5.0,42,78,78, 0.00,7149.78,436.97,14.7,14.7,0.0,0.0,0.0,14.7,0.0,0.0, 1:58, 0:00, 0:00,0.0, 1:58,0.0,0.0,7.6,0.0,7.8,59.0,100.0,14.7, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:20:56,TOTAL : 14.59,330,330,330,66,13.2,13.2,-4.0,0.3,830,898,816,850,901,82,901,237,234,232,265,265,33,265,10.1,10.1,3.7,3.7,31,94,94, 0.00,7149.81,437.02,14.6,14.6,0.0,0.0,0.0,14.6,0.0,0.0, 43:08, 0:00, 0:00,0.0, 43:08,0.0,0.0,7.7,0.0,0.3,59.0,100.0,14.6, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:20:57,TOTAL : 14.59,0,0,0,66,13.2,13.2,-4.5,0.0,820,883,802,835,888,82,888,237,234,234,265,265,32,265,9.9,9.9,3.8,3.8,25,94,94, 0.00,7149.81,437.03,14.6,14.6,0.0,0.0,0.0,14.6,0.0,0.0, 43:08, 0:00, 0:00,0.0, 43:08,0.0,0.0,7.7,0.0,0.0,359940.0,100.0,14.6, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
4.6, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
08:21:04,TOTAL : 14.59,0,0,0,66,13.1,13.1,-4.0,0.0,761,811,736,760,813,74,813,241,238,242,270,269,32,269,9.4,9.4,4.3,4.3,6,95,95, 0.00,7149.81,437.03,14.6,14.6,0.0,0.0,0.0,14.6,0.0,0.0, 99:59, 0:00, 0:00,0.0, 99:59,0.0,0.0,7.7,0.0,0.0,359940.0,100.0,14.6, 0, 0, , 0.0, 0.0, 00 0.00, 000 0.00
|
||||
|
@@ -0,0 +1,71 @@
|
||||
require "test_helper"
|
||||
|
||||
class EngineDataFlowTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@owner = create_user
|
||||
@pilot = create_user
|
||||
@other_pilot = create_user
|
||||
@aircraft = create_aircraft(owner: @owner, pilot: @pilot, tail_number: "N12345", tach_time: 7149.7)
|
||||
@aircraft.roles.create!(user: @other_pilot, role: "pilot")
|
||||
end
|
||||
|
||||
def upload(name = "cgr30p.csv") = fixture_file_upload("engine_data/#{name}", "text/csv")
|
||||
|
||||
test "pilot logs a flight with engine data and sees the summary and charts" do
|
||||
sign_in @pilot
|
||||
post aircraft_flight_logs_path(@aircraft), params: { flight_log: { date: "2025-07-14", tach_out: 7149.7, tach_in: 7149.8, engine_data: upload } }
|
||||
flight = @aircraft.flight_logs.last
|
||||
assert flight.engine_data.attached?
|
||||
|
||||
get aircraft_flight_logs_path(@aircraft)
|
||||
assert_includes response.body, "Engine data attached"
|
||||
|
||||
get aircraft_flight_log_path(@aircraft, flight)
|
||||
assert_response :success
|
||||
assert_includes response.body, "8m 39s"
|
||||
assert_includes response.body, "7149.77 → 7149.81 (0.04)"
|
||||
assert_includes response.body, "EGT (cyl 4)"
|
||||
assert_includes response.body, "No (ground run)"
|
||||
assert_includes response.body, "Chartkick"
|
||||
refute_includes response.body, "This recording is from"
|
||||
end
|
||||
|
||||
test "an unreadable file is rejected when logging" do
|
||||
sign_in @pilot
|
||||
post aircraft_flight_logs_path(@aircraft), params: { flight_log: { date: "2025-07-14", tach_time: 0.1,
|
||||
engine_data: fixture_file_upload("flights.csv", "text/csv") } }
|
||||
assert_response :unprocessable_entity
|
||||
assert_includes response.body, "Not a recognized engine monitor file"
|
||||
assert_equal 0, @aircraft.flight_logs.count
|
||||
end
|
||||
|
||||
test "attach to and remove from an existing flight; only owners or the flight's pilot" do
|
||||
flight = @aircraft.flight_logs.create!(date: Date.current, tach_time: 0.1, user: @pilot)
|
||||
|
||||
sign_in @other_pilot
|
||||
patch engine_data_aircraft_flight_log_path(@aircraft, flight), params: { flight_log: { engine_data: upload } }
|
||||
assert_redirected_to aircraft_flight_log_path(@aircraft, flight)
|
||||
refute flight.reload.engine_data.attached?
|
||||
get aircraft_flight_log_path(@aircraft, flight)
|
||||
refute_includes response.body, "Attach engine monitor data"
|
||||
|
||||
sign_in @pilot
|
||||
get aircraft_flight_log_path(@aircraft, flight)
|
||||
assert_includes response.body, "Attach engine monitor data"
|
||||
patch engine_data_aircraft_flight_log_path(@aircraft, flight), params: { flight_log: { engine_data: upload } }
|
||||
assert flight.reload.engine_data.attached?
|
||||
|
||||
sign_in @owner
|
||||
delete engine_data_aircraft_flight_log_path(@aircraft, flight)
|
||||
perform_enqueued_jobs
|
||||
refute flight.reload.engine_data.attached?
|
||||
end
|
||||
|
||||
test "warns when the recording is from another aircraft" do
|
||||
@aircraft.update!(tail_number: "N54321")
|
||||
flight = @aircraft.flight_logs.create!(date: Date.current, tach_time: 0.1, engine_data: upload)
|
||||
sign_in @owner
|
||||
get aircraft_flight_log_path(@aircraft, flight)
|
||||
assert_includes response.body, "This recording is from <strong>N12345</strong>"
|
||||
end
|
||||
end
|
||||
@@ -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