mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Add flying stats to the Flights tab; drop the DRS search link setting
Flights tab: - Summary cards for the past 30 days, this year, past 12 months and since the first flight (flight hours, flights, tach, fuel). - Flight hours by month (last 24 months) with the past-year monthly average, totals (flights, flight/tach time, average and longest flight, fuel, gal/hr, airports visited, most visited) and a by-year table. - Flight time is Hobbs time where recorded, otherwise tach time. Removed the per-aircraft DRS search link and its "Open in DRS" button: each AD's DRS link already comes from the Excel import. A guarded migration drops the column. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b75fd7cf62
commit
0c4803d717
15 files changed
+221
-23
No files matched your search
@@ -45,18 +45,6 @@ class AdImportFlowTest < ActionDispatch::IntegrationTest
|
||||
assert_equal "GREEN", @aircraft.reload.airworthiness.status
|
||||
end
|
||||
|
||||
test "saved DRS search link shows an Open in DRS button; only drs.faa.gov links allowed" do
|
||||
sign_in @owner
|
||||
url = "https://drs.faa.gov/browse/ADFRAWD/doctypeDetails?Status=Current&Make=Cessna%20Aircraft%20Company&Model=150L#:~:text=Save-,Results"
|
||||
patch aircraft_path(@aircraft), params: { aircraft: { drs_search_url: url } }
|
||||
assert_equal url.sub(/#.*/, ""), @aircraft.reload.drs_search_url
|
||||
get aircraft_airworthiness_directives_path(@aircraft)
|
||||
assert_select "a[href='#{@aircraft.drs_search_url}']", text: "Open in DRS ↗"
|
||||
|
||||
patch aircraft_path(@aircraft), params: { aircraft: { drs_search_url: "https://evil.example/drs.faa.gov" } }
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "pilots cannot import ADs" do
|
||||
sign_in @pilot
|
||||
post aircraft_ad_import_path(@aircraft), params: { file: fixture_file_upload("drs_ads.csv", "text/csv") }
|
||||
|
||||
@@ -82,6 +82,12 @@ class PagesTest < ActionDispatch::IntegrationTest
|
||||
assert_select "a[href='https://drs.faa.gov/browse/excelExternalWindow/ABC.0001']", minimum: 2 # status + history
|
||||
end
|
||||
|
||||
test "flights tab shows flying stats" do
|
||||
get aircraft_flight_logs_path(@a)
|
||||
assert_select "h2", text: "Flight hours by month"
|
||||
assert_select "dt", text: "Airports visited"
|
||||
end
|
||||
|
||||
test "maintenance share link renders without login and shows history" do
|
||||
delete session_path
|
||||
get shared_path(@token.token)
|
||||
|
||||
@@ -180,7 +180,6 @@ class AdImportTest < ActiveSupport::TestCase
|
||||
AdImport::FAA_FIELDS.each_key do |attr|
|
||||
assert_includes AirworthinessDirective.column_names, attr.to_s
|
||||
end
|
||||
assert_includes Aircraft.column_names, "drs_search_url"
|
||||
end
|
||||
|
||||
test "rejects files that aren't DRS exports" do
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
require "test_helper"
|
||||
|
||||
class FlightStatsTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@a = create_aircraft(tach_time: 1000)
|
||||
@today = Date.new(2026, 11, 5)
|
||||
end
|
||||
|
||||
def fly(date, tach, hobbs: nil, from: "KAAA", to: "KBBB", fuel: nil)
|
||||
f = @a.flight_logs.create!(date: date, tach_time: tach, hobbs_time: hobbs,
|
||||
departure_location: from, destination_location: to, fuel_added: fuel)
|
||||
@a.consumable_records.create!(record_type: "fuel", date: date, quantity_added: fuel, flight_hours: 1000, flight_log: f) if fuel
|
||||
f
|
||||
end
|
||||
|
||||
def stats = FlightStats.new(@a, today: @today)
|
||||
|
||||
test "periods use Hobbs time, falling back to tach" do
|
||||
fly Date.new(2024, 6, 1), 2.0, hobbs: 2.4, fuel: 10
|
||||
fly Date.new(2025, 12, 20), 1.0, hobbs: 1.2 # last year, and within past 12 months
|
||||
fly Date.new(2026, 3, 1), 1.5 # no Hobbs: counts 1.5
|
||||
fly Date.new(2026, 10, 20), 0.8, hobbs: 1.0, from: "kccc ", to: "KAAA", fuel: 12.5
|
||||
|
||||
p30, p12, this_year, last_year, all = stats.periods
|
||||
assert_equal [ 1, 1.0, 12.5 ], [ p30.flights, p30.flight, p30.fuel ]
|
||||
assert_equal [ 3, 3.7 ], [ p12.flights, p12.flight ]
|
||||
assert_equal [ 2, 2.5, 2.3 ], [ this_year.flights, this_year.flight, this_year.tach ]
|
||||
assert_equal [ 1, 1.2 ], [ last_year.flights, last_year.flight ]
|
||||
assert_equal [ 4, 6.1, 22.5 ], [ all.flights, all.flight, all.fuel ]
|
||||
assert_equal Date.new(2024, 6, 1), stats.first_date
|
||||
end
|
||||
|
||||
test "totals, airports, monthly series and years" do
|
||||
fly Date.new(2026, 9, 1), 1.0, hobbs: 1.2, from: "KOQU", to: "KBID"
|
||||
fly Date.new(2026, 9, 1), 0.5, hobbs: 0.6, from: "KBID", to: "koqu"
|
||||
fly Date.new(2025, 9, 1), 3.0, hobbs: 3.5, from: "KOQU", to: "KMFD"
|
||||
s = stats
|
||||
assert_equal 3, s.count
|
||||
assert_equal 1.8, s.average_flight
|
||||
assert_equal [ 0.6, 3.5 ], [ s.shortest_flight, s.longest_flight ]
|
||||
assert_equal 3, s.airports_visited
|
||||
assert_equal [ "KOQU", 3 ], s.top_airports.first
|
||||
|
||||
months = s.flight_hours_by_month(24)
|
||||
assert_equal 24, months.size
|
||||
assert_equal 1.8, months["Sep 2026"]
|
||||
assert_equal 0.0, months["Oct 2026"]
|
||||
assert_equal "Nov 2026", months.keys.last
|
||||
assert_equal %w[2026 2025], s.by_year.map(&:label)
|
||||
assert_equal 0.2, s.monthly_average_past_year # 1.8 / 12, rounded
|
||||
end
|
||||
|
||||
test "no flights" do
|
||||
assert_not stats.any?
|
||||
assert_nil stats.average_flight
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user