mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
AirTrail (https://github.com/johanohly/AirTrail): - File export (Flights → Export for AirTrail) in AirTrail's import format, validated against its schema; same-day repeat legs get leg numbers so AirTrail's de-duplication doesn't merge them. - Automatic sync through AirTrail's REST API (Profile → AirTrail sync): per-user connection with an encrypted API key and scope check; flights are created/updated/deleted in background jobs; a full sync first links flights already in AirTrail (e.g. from a file import) instead of duplicating them; airports are resolved and cached, with manual mapping for unknown codes. - GPS tracks: GPX, KML and CSV track logs are converted to AirTrail's track format for both sync and export; the flight page shows a summary. - Aircraft ICAO type (e.g. C150) for AirTrail's aircraft type. Airport database (OurAirports, the source AirTrail uses): - Managed like AirTrail: downloaded in the background on first start, updated in place from Admin → Airports (adds, changes, removes; ids stable), with admin-managed custom airports that updates never touch. - Each airport carries AirTrail's code, so logged codes translate to AirTrail's exactly (1B9 → K1B9, 4MB → K5M3). - From/To autocomplete on new flights (airports this aircraft has used rank first); From is pre-filled with the last flight's destination; codes are normalized to uppercase. - Flights → Standardize airport codes: rewrite logged codes to the standard code, and fix codes not in the database (typos such as 0R8 → 08R are suggested). Also: admin pages grouped under an Admin dropdown menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.2 KiB
Ruby
53 lines
2.2 KiB
Ruby
require "test_helper"
|
|
|
|
class TrackParserTest < ActiveSupport::TestCase
|
|
def parse(name) = TrackParser.new(file_fixture_path.join("tracks", name).read, filename: name).parse
|
|
def file_fixture_path = Rails.root.join("test/fixtures/files")
|
|
|
|
test "GPX: [lon, lat, alt_m] with epoch-second times" do
|
|
t = parse("flight.gpx")
|
|
assert_equal "gpx", t.source_format
|
|
assert_equal [ -71.412028, 41.597139, 5.2 ], t.coordinates.first
|
|
assert_equal 3, t.points
|
|
assert_equal Time.utc(2026, 10, 24, 14).to_i, t.times.first
|
|
assert_equal 2500, t.max_altitude_ft # 762 m
|
|
json = t.as_air_trail_json
|
|
assert_equal %i[coordinates sourceFormat sourceName times], json.keys.sort
|
|
assert_equal "flight.gpx", json[:sourceName]
|
|
end
|
|
|
|
test "KML gx:Track and LineString" do
|
|
t = parse("flight.kml")
|
|
assert_equal [ [ -71.412028, 41.597139, 5.2 ], [ -71.5, 41.42, 762.0 ] ], t.coordinates
|
|
assert_equal 2, t.times.size
|
|
line = parse("linestring.kml")
|
|
assert_equal 3, line.points
|
|
assert_nil line.times
|
|
end
|
|
|
|
test "CSV: altitude in feet, millisecond timestamps" do
|
|
t = parse("flight.csv")
|
|
assert_equal "csv", t.source_format
|
|
assert_equal [ -71.5, 41.42, 762.0 ], t.coordinates[1] # 2500 ft
|
|
assert_equal 1_793_023_200, t.times.first
|
|
end
|
|
|
|
test "sniffs the format when the extension doesn't say" do
|
|
gpx = Rails.root.join("test/fixtures/files/tracks/flight.gpx").read
|
|
assert_equal "gpx", TrackParser.new(gpx, filename: "track.xml").parse.source_format
|
|
end
|
|
|
|
test "downsamples huge tracks to AirTrail's limit, keeping the last point" do
|
|
rows = (0..100_200).map { |i| "#{41 + i * 1e-6},-71,1000" }
|
|
t = TrackParser.new("lat,lon,alt\n#{rows.join("\n")}", filename: "big.csv").parse
|
|
assert_operator t.points, :<=, TrackParser::MAX_POINTS + 1
|
|
assert_in_delta 41 + 100_200 * 1e-6, t.coordinates.last[1], 1e-6
|
|
end
|
|
|
|
test "rejects unusable tracks" do
|
|
assert_raises(TrackParser::Error) { TrackParser.new("hello", filename: "x.txt").parse }
|
|
assert_raises(TrackParser::Error) { TrackParser.new("lat,lon\n41,-71\n", filename: "one.csv").parse }
|
|
assert_raises(TrackParser::Error) { TrackParser.new("a,b\n1,2\n3,4\n", filename: "x.csv").parse }
|
|
end
|
|
end
|