diff --git a/app/services/gpx/track_parser.rb b/app/services/gpx/track_parser.rb index c9a6414b..65cbc3be 100644 --- a/app/services/gpx/track_parser.rb +++ b/app/services/gpx/track_parser.rb @@ -59,6 +59,8 @@ class Gpx::TrackParser def speed(point) return if point['extensions'].blank? - point.dig('extensions', 'speed').to_f || point.dig('extensions', 'TrackPointExtension', 'speed').to_f + ( + point.dig('extensions', 'speed') || point.dig('extensions', 'TrackPointExtension', 'speed') + ).to_f.round(1) end end diff --git a/spec/fixtures/files/gpx/garmin_example.gpx b/spec/fixtures/files/gpx/garmin_example.gpx new file mode 100644 index 00000000..04c7a6dd --- /dev/null +++ b/spec/fixtures/files/gpx/garmin_example.gpx @@ -0,0 +1,31 @@ + + + + + + + 20241103 + + + 17.634344400269068 + + + + 2.8 + + + -1.6 + gps + 3 + 1.9 + 8.6 + 8.8 + + + + diff --git a/spec/services/gpx/track_parser_spec.rb b/spec/services/gpx/track_parser_spec.rb index 30203852..b1026143 100644 --- a/spec/services/gpx/track_parser_spec.rb +++ b/spec/services/gpx/track_parser_spec.rb @@ -60,5 +60,19 @@ RSpec.describe Gpx::TrackParser do expect(Point.first.velocity).to eq('2.9') end end + + context 'when file exported from Garmin' do + let(:file_path) { Rails.root.join('spec/fixtures/files/gpx/garmin_example.gpx') } + + it 'creates points with correct data' do + parser + + expect(Point.first.latitude).to eq(10.758321.to_d) + expect(Point.first.longitude).to eq(106.642344.to_d) + expect(Point.first.altitude).to eq(17) + expect(Point.first.timestamp).to eq(1_730_626_211) + expect(Point.first.velocity).to eq('2.8') + end + end end end