<%# Engine monitor recording: summary and charts. Locals: flight_log, recording, error %>

Engine data

<% if flight_log.engine_data.attached? %>
<%= link_to flight_log.engine_data.filename, rails_blob_path(flight_log.engine_data, disposition: :attachment), class: "link" %> <% if manage_engine_data? %><%= delete_button "Remove", engine_data_aircraft_flight_log_path(@aircraft, flight_log), confirm: "Remove the engine data file from this flight?" %><% end %>
<% end %>
<% if recording %> <% hours_line = ->(key, places) { (a = recording.first(key)) && (b = recording.last(key)) ? "#{number_with_precision(a, precision: places)} → #{number_with_precision(b, precision: places)} (#{number_with_precision(b - a, precision: places)})" : "—" } %> <% egt, cht = recording.hottest(:egt), recording.hottest(:cht) %> <% tail = recording.metadata[:aircraft_id] %> <% if tail.present? && tail.upcase != @aircraft.tail_number.to_s.upcase %>

This recording is from <%= tail %>, not <%= @aircraft.tail_number %>.

<% end %>
Recorded
<%= recording.local(recording.started_at).strftime("%Y-%m-%d %H:%M") %>–<%= recording.local(recording.ended_at).strftime("%H:%M") %> monitor time · <%= recording.format %><%= " flight ##{recording.metadata[:flight_number]}" if recording.metadata[:flight_number] %> · <%= number_with_delimiter(recording.samples) %> samples
Engine run
<%= recording.engine_start ? run_duration(recording.run_time) : "Engine not run" %>
Fuel burned
<%= engine_value(recording.fuel_burned, "gal", precision: 1) %>
Tach
<%= hours_line.(:tach, 2) %>
Engine hrs
<%= hours_line.(:engine_hours, 2) %>
<% if (flt = recording.last(:flight_hours)) %>
Airborne
<%= flt.zero? ? "No (ground run)" : "#{number_with_precision(flt, precision: 2)} hrs" %>
<% end %>
<% peaks = [ [ "RPM", recording.max(:rpm), "rpm" ], [ "Manifold pressure", recording.max(:map), "inHg", 1 ], [ (egt ? "EGT (cyl #{egt[:cylinder]})" : "EGT"), egt && [ egt[:value], egt[:at] ], "°F" ], [ (cht ? "CHT (cyl #{cht[:cylinder]})" : "CHT"), cht && [ cht[:value], cht[:at] ], "°F" ], [ "TIT", recording.max(:tit), "°F" ], [ "Oil temp", recording.max(:oil_t), "°F" ], [ "Oil pressure", recording.max(:oil_p), "psi" ], [ "Fuel flow", recording.max(:fuel_flow), "gph", 1 ], [ "Volts (low)", recording.min(:volts), "V", 1 ] ].select { _2 } %> <% peaks.each do |label, (value, at), unit, places| %> <% end %>
Peak (engine running)ValueAt
<%= label %><%= engine_value(value, unit, precision: places || 0) %> <%= recording.local(at).strftime("%H:%M:%S") %>
<% colors = FlightLogsHelper::CYLINDER_COLORS %> <% [ [ "CHT", recording.cht_keys, "°F", colors ], [ "EGT", recording.egt_keys, "°F", colors ], [ "RPM", [ :rpm ], "rpm" ], [ "Manifold pressure", [ :map ], "inHg" ], [ "Fuel flow", [ :fuel_flow ], "gph" ], [ "Oil temp", [ :oil_t ], "°F" ], [ "Oil pressure", [ :oil_p ], "psi" ], [ "Volts", [ :volts ], "V" ] ].each do |title, keys, unit, palette| %> <% chart = engine_chart(recording, *keys, ytitle: unit, colors: palette) %> <% if chart %>
<%= title %>
<%= chart %>
<% end %> <% end %>
<% elsif error %>

<%= error %>

<% end %> <% if manage_engine_data? && !flight_log.engine_data.attached? %> <%= form_with model: flight_log, url: engine_data_aircraft_flight_log_path(@aircraft, flight_log), method: :patch, class: "card-body flex flex-wrap items-end gap-3" do |f| %> <%= f.field :engine_data, as: :file, label: "Attach engine monitor data", hint: "CGR-30P / CGR-30C flight recording (.csv).", accept: ".csv,text/csv" %> <%= f.submit "Upload", class: "btn-secondary" %> <% end %> <% elsif !flight_log.engine_data.attached? %> <%= empty_state "No engine data for this flight." %> <% end %>