Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

Commit af6baea

Browse files
pstorchdennisguse
authored andcommitted
fix #2104 csv export altitude above 1000m
1 parent 9b4d3a4 commit af6baea

File tree

3 files changed

+73
-51
lines changed

3 files changed

+73
-51
lines changed

src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import androidx.test.ext.junit.runners.AndroidJUnit4;
1919
import androidx.test.filters.LargeTest;
2020
import androidx.test.platform.app.InstrumentationRegistry;
21+
import androidx.test.rule.GrantPermissionRule;
2122
import androidx.test.rule.ServiceTestRule;
2223

2324
import org.junit.After;
@@ -45,6 +46,7 @@
4546
import java.util.stream.Collectors;
4647

4748
import de.dennisguse.opentracks.R;
49+
import de.dennisguse.opentracks.TestUtil;
4850
import de.dennisguse.opentracks.TimezoneRule;
4951
import de.dennisguse.opentracks.content.data.TestDataUtil;
5052
import de.dennisguse.opentracks.data.ContentProviderUtils;
@@ -87,6 +89,9 @@ public class ExportImportTest {
8789
@Rule
8890
public final ServiceTestRule mServiceRule = ServiceTestRule.withTimeout(5, TimeUnit.SECONDS);
8991

92+
@Rule
93+
public GrantPermissionRule mGrantPermissionRule = TestUtil.createGrantPermissionRule();
94+
9095
//For csv_export_only() as we the timezone is hardcoded in the expectation.
9196
@Rule
9297
public TimezoneRule timezoneRule = new TimezoneRule(TimeZone.getTimeZone("Europe/Berlin"));
@@ -144,7 +149,7 @@ public void setUp() throws TimeoutException {
144149

145150
Distance sensorDistance = Distance.of(10); // recording distance interval
146151

147-
sendLocation(trackPointCreator, "2020-02-02T02:02:03Z", 3, 14, 10, 13, 15, 10, 1f);
152+
sendLocation(trackPointCreator, "2020-02-02T02:02:03Z", 3.1234567, 14.0014567, 10, 13, 15, 1020.25, 1f);
148153
contentProviderUtils.insertMarker(new Marker(trackId, service.getLastStoredTrackPointWithLocation(), "Marker 1", "Marker 1 desc", "Marker 1 category", null, null));
149154

150155
// A sensor-only TrackPoint
@@ -155,11 +160,10 @@ public void setUp() throws TimeoutException {
155160
mockSensorData(trackPointCreator, 15f, null, 67f, 3f, 50f, null);
156161
trackPointCreator.setClock("2020-02-02T02:02:15Z");
157162
mockSensorData(trackPointCreator, null, null, 68f, 3f, 50f, null);
158-
159163
trackPointCreator.setClock("2020-02-02T02:02:16Z");
160164
mockSensorData(trackPointCreator, 5f, Distance.of(2), 69f, 3f, 50f, null); // Distance will be added to next TrackPoint
161165

162-
sendLocation(trackPointCreator, "2020-02-02T02:02:17Z", 3, 14.001, 10, 13, 15, 10, 0f);
166+
sendLocation(trackPointCreator, "2020-02-02T02:02:17Z", 3.1234567, 14.0014567, 10, 13, 15, 1020.25, 0f);
163167
contentProviderUtils.insertMarker(new Marker(trackId, service.getLastStoredTrackPointWithLocation(), "Marker 2", "Marker 2 desc", "Marker 2 category", null, null));
164168

165169
trackPointCreator.setClock("2020-02-02T02:02:18Z");
@@ -169,14 +173,14 @@ public void setUp() throws TimeoutException {
169173
trackPointCreator.setClock("2020-02-02T02:03:20Z");
170174
service.resumeTrack(trackId);
171175

172-
sendLocation(trackPointCreator, "2020-02-02T02:03:21Z", 3, 14.002, 10, 13, 15, 10, 0f);
176+
sendLocation(trackPointCreator, "2020-02-02T02:03:21Z", 3.1234567, 14.0024567, 10, 13, 15, 999.123, 0f);
173177

174-
sendLocation(trackPointCreator, "2020-02-02T02:03:22Z", 3, 16, 10, 13, 15, 10, 0f);
178+
sendLocation(trackPointCreator, "2020-02-02T02:03:22Z", 3.1234567, 16, 10, 13, 15, 999.123, 0f);
175179

176180
trackPointCreator.setClock("2020-02-02T02:03:30Z");
177181
service.getTrackRecordingManager().onIdle();
178182

179-
sendLocation(trackPointCreator, "2020-02-02T02:03:50Z", 3, 16.001, 10, 27, 15, 10, 0f);
183+
sendLocation(trackPointCreator, "2020-02-02T02:03:50Z", 3.1234567, 16.001, 10, 27, 15, 999.123, 0f);
180184

181185
trackPointCreator.getSensorManager().sensorDataSet = new SensorDataSet(trackPointCreator);
182186
trackPointCreator.setClock("2020-02-02T02:04:00Z");
@@ -209,16 +213,16 @@ public void track() throws TimeoutException {
209213
assertEquals(Duration.ofSeconds(26), trackStatistics.getMovingTime()); //TODO Likely too low
210214

211215
// Distance
212-
assertEquals(222125.53125, trackStatistics.getTotalDistance().toM(), 0.01); //TODO Too low
216+
assertEquals(222049.34375, trackStatistics.getTotalDistance().toM(), 0.01); //TODO Too low
213217

214218
// Speed
215-
assertEquals(8543.29, trackStatistics.getMaxSpeed().toMPS(), 0.01);
216-
assertEquals(3966.52, trackStatistics.getAverageSpeed().toMPS(), 0.01);
217-
assertEquals(8543.28, trackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
219+
assertEquals(8540.359, trackStatistics.getMaxSpeed().toMPS(), 0.01);
220+
assertEquals(3965.166, trackStatistics.getAverageSpeed().toMPS(), 0.01);
221+
assertEquals(8540.359, trackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
218222

219223
// Altitude
220-
assertEquals(10, trackStatistics.getMinAltitude(), 0.01);
221-
assertEquals(10, trackStatistics.getMaxAltitude(), 0.01);
224+
assertEquals(999.122, trackStatistics.getMinAltitude(), 0.01);
225+
assertEquals(1020.25, trackStatistics.getMaxAltitude(), 0.01);
222226

223227
assertEquals(2, trackStatistics.getTotalAltitudeGain(), 0.01);
224228
assertEquals(2, trackStatistics.getTotalAltitudeLoss(), 0.01);
@@ -229,8 +233,8 @@ public void track() throws TimeoutException {
229233
new TrackPoint(TrackPoint.Type.TRACKPOINT,
230234
new Position(
231235
Instant.parse("2020-02-02T02:02:03Z"),
232-
3d, 14d, Distance.of(10),
233-
Altitude.WGS84.of(10), null,
236+
3.123456, 14.001456, Distance.of(10),
237+
Altitude.WGS84.of(1020.25), null,
234238
null,
235239
Speed.of(15)))
236240
.setAltitudeLoss(1f)
@@ -251,8 +255,8 @@ public void track() throws TimeoutException {
251255
new TrackPoint(TrackPoint.Type.TRACKPOINT,
252256
new Position(
253257
Instant.parse("2020-02-02T02:02:17Z"),
254-
3d, 14.001, Distance.of(10),
255-
Altitude.WGS84.of(10), null,
258+
3.123456, 14.001456, Distance.of(10),
259+
Altitude.WGS84.of(1020.25), null,
256260
null,
257261
Speed.of(5)))
258262
.setSensorDistance(Distance.of(2))
@@ -266,16 +270,16 @@ public void track() throws TimeoutException {
266270
new TrackPoint(TrackPoint.Type.TRACKPOINT,
267271
new Position(
268272
Instant.parse("2020-02-02T02:03:21Z"),
269-
3d, 14.002d, Distance.of(10),
270-
Altitude.WGS84.of(10), null,
273+
3.123456, 14.002456, Distance.of(10),
274+
Altitude.WGS84.of(999.1229858398438), null,
271275
null,
272276
Speed.of(15)))
273277
.setAltitudeLoss(0f)
274278
.setAltitudeGain(0f),
275279
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
276280
new Position(Instant.parse("2020-02-02T02:03:22Z"),
277-
3d, 16d, Distance.of(10),
278-
Altitude.WGS84.of(10), null,
281+
3.123456, 16d, Distance.of(10),
282+
Altitude.WGS84.of(999.1229858398438), null,
279283
null,
280284
Speed.of(15)))
281285
.setAltitudeLoss(0f)
@@ -286,8 +290,8 @@ public void track() throws TimeoutException {
286290
new TrackPoint(TrackPoint.Type.TRACKPOINT,
287291
new Position(
288292
Instant.parse("2020-02-02T02:03:50Z"),
289-
3d, 16.001, Distance.of(10),
290-
Altitude.WGS84.of(10), null,
293+
3.123456, 16.001, Distance.of(10),
294+
Altitude.WGS84.of(999.1229858398438), null,
291295
null, Speed.of(15)))
292296
.setAltitudeLoss(0f)
293297
.setAltitudeGain(0f),
@@ -334,7 +338,26 @@ public void kmz_with_trackdetail_and_sensordata() throws TimeoutException, IOExc
334338

335339
// Time
336340
assertEquals(track.getZoneOffset(), importedTrack.getZoneOffset());
337-
assertEquals(track.getTrackStatistics(), importedTrackStatistics);
341+
assertEquals(Instant.parse("2020-02-02T02:02:02Z"), importedTrackStatistics.getStartTime());
342+
assertEquals(Instant.parse("2020-02-02T02:04:00Z"), importedTrackStatistics.getStopTime());
343+
344+
assertEquals(Duration.ofSeconds(56), importedTrackStatistics.getTotalTime());
345+
assertEquals(Duration.ofSeconds(26), importedTrackStatistics.getMovingTime());
346+
347+
// Distance
348+
assertEquals(222049.421, importedTrackStatistics.getTotalDistance().toM(), 0.01);
349+
350+
// Speed
351+
assertEquals(8540.362, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
352+
assertEquals(3965.168, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
353+
assertEquals(8540.362, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
354+
355+
// Altitude
356+
assertEquals(999.122, importedTrackStatistics.getMinAltitude(), 0.01);
357+
assertEquals(1020.25, importedTrackStatistics.getMaxAltitude(), 0.01);
358+
assertEquals(2, importedTrackStatistics.getTotalAltitudeGain(), 0.01);
359+
assertEquals(2, importedTrackStatistics.getTotalAltitudeLoss(), 0.01);
360+
338361

339362
// 4. markers
340363
assertMarkers();
@@ -406,17 +429,17 @@ public void gpx() throws TimeoutException, IOException {
406429
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
407430
new Position(
408431
Instant.parse("2020-02-02T02:02:03Z"),
409-
3d, 14d, Distance.of(10),
410-
Altitude.WGS84.of(10), null,
432+
3.123456, 14.001456d, Distance.of(10),
433+
Altitude.WGS84.of(1020.2), null,
411434
null,
412435
Speed.of(15)))
413436
.setAltitudeLoss(1f)
414437
.setAltitudeGain(1f),
415438
new TrackPoint(TrackPoint.Type.TRACKPOINT,
416439
new Position(
417440
Instant.parse("2020-02-02T02:02:17Z"),
418-
3d, 14.001, Distance.of(10),
419-
Altitude.WGS84.of(10), null,
441+
3.123456, 14.001456, Distance.of(10),
442+
Altitude.WGS84.of(1020.2), null,
420443
null,
421444
Speed.of(5)))
422445
.setAltitudeLoss(1f)
@@ -428,26 +451,26 @@ public void gpx() throws TimeoutException, IOException {
428451
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
429452
new Position(
430453
Instant.parse("2020-02-02T02:03:21Z"),
431-
3d, 14.002, Distance.of(10),
432-
Altitude.WGS84.of(10), null,
454+
3.123456, 14.002456, Distance.of(10),
455+
Altitude.WGS84.of(999.0999755859375), null,
433456
null,
434457
Speed.of(15)))
435458
.setAltitudeLoss(0f)
436459
.setAltitudeGain(0f),
437460
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
438461
new Position(
439462
Instant.parse("2020-02-02T02:03:22Z"),
440-
3d, 16d, Distance.of(10),
441-
Altitude.WGS84.of(10), null,
463+
3.123456, 16d, Distance.of(10),
464+
Altitude.WGS84.of(999.0999755859375), null,
442465
null,
443466
Speed.of(15)))
444467
.setAltitudeLoss(0f)
445468
.setAltitudeGain(0f),
446469
new TrackPoint(TrackPoint.Type.TRACKPOINT,
447470
new Position(
448471
Instant.parse("2020-02-02T02:03:50Z"),
449-
3d, 16.001, Distance.of(10),
450-
Altitude.WGS84.of(10), null,
472+
3.123456, 16.001, Distance.of(10),
473+
Altitude.WGS84.of(999.0999755859375), null,
451474
null,
452475
Speed.of(10)))
453476
.setAltitudeLoss(0f)
@@ -467,16 +490,16 @@ public void gpx() throws TimeoutException, IOException {
467490
assertEquals(Duration.ofSeconds(107), importedTrackStatistics.getMovingTime());
468491

469492
// Distance
470-
assertEquals(222347.85, importedTrackStatistics.getTotalDistance().toM(), 0.01);
493+
assertEquals(222271.734, importedTrackStatistics.getTotalDistance().toM(), 0.01);
471494

472495
// Speed
473-
assertEquals(2078.01, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
474-
assertEquals(2078.01, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
475-
assertEquals(2078.01, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
496+
assertEquals(2077.305, importedTrackStatistics.getMaxSpeed().toMPS(), 0.01);
497+
assertEquals(2077.305, importedTrackStatistics.getAverageSpeed().toMPS(), 0.01);
498+
assertEquals(2077.305, importedTrackStatistics.getAverageMovingSpeed().toMPS(), 0.01);
476499

477500
// Altitude
478-
assertEquals(10, importedTrackStatistics.getMinAltitude(), 0.01);
479-
assertEquals(10, importedTrackStatistics.getMaxAltitude(), 0.01);
501+
assertEquals(999.099, importedTrackStatistics.getMinAltitude(), 0.01);
502+
assertEquals(1020.2, importedTrackStatistics.getMaxAltitude(), 0.01);
480503
assertEquals(2, importedTrackStatistics.getTotalAltitudeGain(), 0.01);
481504
assertEquals(2, importedTrackStatistics.getTotalAltitudeLoss(), 0.01);
482505

@@ -614,7 +637,7 @@ private void mockAltitudeChange(TrackPointCreator trackPointCreator, Float altit
614637
}
615638
}
616639

617-
private void sendLocation(TrackPointCreator trackPointCreator, String time, double latitude, double longitude, float accuracy, float verticalAccuracy, float speed, float altitude, Float altitudeGain) {
640+
private void sendLocation(TrackPointCreator trackPointCreator, String time, double latitude, double longitude, float accuracy, float verticalAccuracy, float speed, double altitude, Float altitudeGain) {
618641
Location location = new Location("mock");
619642
location.setLatitude(latitude);
620643
location.setLongitude(longitude);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#time,trackpoint_type,latitude,longitude,altitude,accuracy_horizontal,accuracy_vertical,speed,altitude_gain,altitude_loss,sensor_distance,heartrate,cadence,power
22
"2020-02-02T03:02:02+01:00","SEGMENT_START_MANUAL",,,,,,,,,,,,
3-
"2020-02-02T03:02:03+01:00","TRACKPOINT",3,14,10,10,,54,1,1,,,,
3+
"2020-02-02T03:02:03+01:00","TRACKPOINT",3.123456,14.001456,1020.2,10,,54,1,1,,,,
44
"2020-02-02T03:02:04+01:00","TRACKPOINT",,,,,,54,1,1,10,66,3,50
55
"2020-02-02T03:02:15+01:00","TRACKPOINT",,,,,,,,,,68,3,50
6-
"2020-02-02T03:02:17+01:00","TRACKPOINT",3,14.001,10,10,,18,0,0,2,69,3,50
6+
"2020-02-02T03:02:17+01:00","TRACKPOINT",3.123456,14.001456,1020.2,10,,18,0,0,2,69,3,50
77
"2020-02-02T03:02:18+01:00","SEGMENT_END_MANUAL",,,,,,,,,,,,
88
"2020-02-02T03:03:20+01:00","SEGMENT_START_MANUAL",,,,,,,,,,,,
9-
"2020-02-02T03:03:21+01:00","TRACKPOINT",3,14.002,10,10,,54,0,0,,,,
10-
"2020-02-02T03:03:22+01:00","SEGMENT_START_AUTOMATIC",3,16,10,10,,54,0,0,,,,
9+
"2020-02-02T03:03:21+01:00","TRACKPOINT",3.123456,14.002456,999.1,10,,54,0,0,,,,
10+
"2020-02-02T03:03:22+01:00","SEGMENT_START_AUTOMATIC",3.123456,16,999.1,10,,54,0,0,,,,
1111
"2020-02-02T03:03:30+01:00","IDLE",,,,,,,0,0,,,,
12-
"2020-02-02T03:03:50+01:00","TRACKPOINT",3,16.001,10,10,,54,0,0,,,,
12+
"2020-02-02T03:03:50+01:00","TRACKPOINT",3.123456,16.001,999.1,10,,54,0,0,,,,
1313
"2020-02-02T03:04:00+01:00","SEGMENT_END_MANUAL",,,,,,,,,,,,

src/main/java/de/dennisguse/opentracks/io/file/exporter/CSVTrackExporter.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public class CSVTrackExporter implements TrackExporter {
6060
ALTITUDE_FORMAT.setGroupingUsed(false);
6161

6262
COORDINATE_FORMAT.setMaximumFractionDigits(6);
63-
COORDINATE_FORMAT.setMaximumIntegerDigits(3);
6463
COORDINATE_FORMAT.setGroupingUsed(false);
6564

6665
SPEED_FORMAT.setMaximumFractionDigits(2);
@@ -94,17 +93,17 @@ public boolean writeTrack(@NonNull List<Track> tracks, @NonNull OutputStream out
9493
new Column("trackpoint_type", t -> quote(t.getType().name())),
9594
new Column("latitude", t -> t.hasLocation() ? COORDINATE_FORMAT.format(t.getLatitude()) : ""),
9695
new Column("longitude", t -> t.hasLocation() ? COORDINATE_FORMAT.format(t.getLongitude()) : ""),
97-
new Column("altitude", t -> t.hasAltitude() ? COORDINATE_FORMAT.format(t.getAltitude().toM()) : ""),
96+
new Column("altitude", t -> t.hasAltitude() ? ALTITUDE_FORMAT.format(t.getAltitude().toM()) : ""),
9897
new Column("accuracy_horizontal", t -> t.hasHorizontalAccuracy() ? DISTANCE_FORMAT.format(t.getHorizontalAccuracy().toM()) : ""),
9998
new Column("accuracy_vertical", t -> t.hasVerticalAccuracy() ? DISTANCE_FORMAT.format(t.getVerticalAccuracy().toM()) : ""),
10099

101100
new Column("speed", t -> t.hasSpeed() ? SPEED_FORMAT.format(t.getSpeed().toKMH()) : ""),
102-
new Column("altitude_gain", t -> t.hasAltitudeGain() ? DISTANCE_FORMAT.format(t.getAltitudeGain()) : ""),
103-
new Column("altitude_loss", t -> t.hasAltitudeLoss() ? DISTANCE_FORMAT.format(t.getAltitudeLoss()) : ""),
101+
new Column("altitude_gain", t -> t.hasAltitudeGain() ? ALTITUDE_FORMAT.format(t.getAltitudeGain()) : ""),
102+
new Column("altitude_loss", t -> t.hasAltitudeLoss() ? ALTITUDE_FORMAT.format(t.getAltitudeLoss()) : ""),
104103
new Column("sensor_distance", t -> t.hasSensorDistance() ? DISTANCE_FORMAT.format(t.getSensorDistance().toM()) : ""),
105104
new Column("heartrate", t -> t.hasHeartRate() ? HEARTRATE_FORMAT.format(t.getHeartRate().getBPM()) : ""),
106105
new Column("cadence", t -> t.hasCadence() ? CADENCE_FORMAT.format(t.getCadence().getRPM()) : ""),
107-
new Column("power", t -> t.hasPower() ? ALTITUDE_FORMAT.format(t.getPower().getW()) : ""));
106+
new Column("power", t -> t.hasPower() ? POWER_FORMAT.format(t.getPower().getW()) : ""));
108107

109108
try {
110109
prepare(outputStream);
@@ -136,7 +135,7 @@ private void writeTrackPoints(List<Column> columns, Track track) throws Interrup
136135
while (trackPointIterator.hasNext()) {
137136
if (Thread.interrupted()) throw new InterruptedException();
138137

139-
writeTrackPoint(columns, trackPointIterator.next());
138+
writeTrackPoint(columns, trackPointIterator.next());
140139
}
141140
}
142141
}

0 commit comments

Comments
 (0)