mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-12 02:01:39 -05:00
Add test for parsing speed from Garmin GPX files
This commit is contained in:
parent
39f9180413
commit
00619837df
3 changed files with 48 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
31
spec/fixtures/files/gpx/garmin_example.gpx
vendored
Normal file
31
spec/fixtures/files/gpx/garmin_example.gpx
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gpx version="1.1" creator="GPSLogger 131 - http://gpslogger.mendhak.com/"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1"
|
||||
xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v2"
|
||||
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd
|
||||
http://www.garmin.com/xmlschemas/TrackPointExtension/v2 https://www8.garmin.com/xmlschemas/TrackPointExtensionv2.xsd
|
||||
">
|
||||
<metadata>
|
||||
<time>2024-11-03T16:30:11.331+07:00</time>
|
||||
</metadata>
|
||||
<trk>
|
||||
<name>20241103</name>
|
||||
<trkseg>
|
||||
<trkpt lat="10.758321212464024" lon="106.64234449272531">
|
||||
<ele>17.634344400269068</ele>
|
||||
<time>2024-11-03T16:30:11.331+07:00</time>
|
||||
<extensions>
|
||||
<gpxtpx:TrackPointExtension>
|
||||
<gpxtpx:speed>2.8</gpxtpx:speed>
|
||||
</gpxtpx:TrackPointExtension>
|
||||
</extensions>
|
||||
<geoidheight>-1.6</geoidheight>
|
||||
<src>gps</src>
|
||||
<sat>3</sat>
|
||||
<hdop>1.9</hdop>
|
||||
<vdop>8.6</vdop>
|
||||
<pdop>8.8</pdop>
|
||||
</trkpt>
|
||||
</trkseg>
|
||||
</trk>
|
||||
</gpx>
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue