diff --git a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java index 5c11b2b776..cde14386fc 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java @@ -280,7 +280,7 @@ public void testRecording_blesensor_only_no_distance() { // then new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), - new TrackPoint(TrackPoint.Type.SENSORPOINT, Instant.parse(sensor3)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor3)) .setAltitudeGain(0f) .setAltitudeLoss(0f) .setHeartRate(HeartRate.of(7)), @@ -867,7 +867,7 @@ public void testRecording_gpsAndSensor_gpsIdleMoving_sensorMoving() { // then new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), - new TrackPoint(TrackPoint.Type.SENSORPOINT, Instant.parse(sensor2)) //First moving TrackPoint: store as the time might be interesting. + new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor2)) //First moving TrackPoint: store as the time might be interesting. .setSpeed(Speed.of(5)) .setSensorDistance(Distance.of(2)), new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) @@ -876,7 +876,7 @@ public void testRecording_gpsAndSensor_gpsIdleMoving_sensorMoving() { .setHorizontalAccuracy(Distance.of(1)) .setSpeed(Speed.of(5)) .setSensorDistance(Distance.of(0)), - new TrackPoint(TrackPoint.Type.SENSORPOINT, Instant.parse(sensor3)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor3)) .setSpeed(Speed.of(5)) .setSensorDistance(Distance.of(10)), new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) diff --git a/src/androidTest/res/raw/csv_export.csv b/src/androidTest/res/raw/csv_export.csv index 62b3b75c2c..bc32fdb45c 100644 --- a/src/androidTest/res/raw/csv_export.csv +++ b/src/androidTest/res/raw/csv_export.csv @@ -1,9 +1,9 @@ #time,trackpoint_type,latitude,longitude,altitude,accuracy_horizontal,accuracy_vertical,speed,altitude_gain,altitude_loss,sensor_distance,heartrate,cadence,power "2020-02-02T03:02:02+01:00","SEGMENT_START_MANUAL",,,,,,,,,,,, "2020-02-02T03:02:03+01:00","TRACKPOINT",3,14,10,10,,54,1,1,,,, -"2020-02-02T03:02:04+01:00","SENSORPOINT",,,,,,54,1,1,10,66,3,50 -"2020-02-02T03:02:15+01:00","SENSORPOINT",,,,,,,,,,68,3,50 -"2020-02-02T03:02:16+01:00","SENSORPOINT",,,,,,18,,,2,69,3,50 +"2020-02-02T03:02:04+01:00","TRACKPOINT",,,,,,54,1,1,10,66,3,50 +"2020-02-02T03:02:15+01:00","TRACKPOINT",,,,,,,,,,68,3,50 +"2020-02-02T03:02:16+01:00","TRACKPOINT",,,,,,18,,,2,69,3,50 "2020-02-02T03:02:17+01:00","TRACKPOINT",3,14.001,10,10,,18,0,0,2,69,3,50 "2020-02-02T03:02:18+01:00","SEGMENT_END_MANUAL",,,,,,,,,,,, "2020-02-02T03:03:20+01:00","SEGMENT_START_MANUAL",,,,,,,,,,,, diff --git a/src/main/java/de/dennisguse/opentracks/data/CustomSQLiteOpenHelper.java b/src/main/java/de/dennisguse/opentracks/data/CustomSQLiteOpenHelper.java index e9d637a75b..a92e2119ac 100644 --- a/src/main/java/de/dennisguse/opentracks/data/CustomSQLiteOpenHelper.java +++ b/src/main/java/de/dennisguse/opentracks/data/CustomSQLiteOpenHelper.java @@ -28,7 +28,7 @@ public class CustomSQLiteOpenHelper extends SQLiteOpenHelper { private static final String TAG = CustomSQLiteOpenHelper.class.getSimpleName(); - private static final int DATABASE_VERSION = 35; + private static final int DATABASE_VERSION = 36; public CustomSQLiteOpenHelper(Context context) { this(context, ((Startup) context.getApplicationContext()).getDatabaseName()); @@ -73,6 +73,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { case 33 -> upgradeFrom32to33(db); case 34 -> upgradeFrom33to34(db); case 35 -> upgradeFrom34to35(db); + case 36 -> upgradeFrom35to36(db); default -> throw new RuntimeException("Not implemented: upgrade to " + toVersion); } } @@ -95,6 +96,7 @@ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { case 32 -> downgradeFrom33to32(db); case 33 -> downgradeFrom34to33(db); case 34 -> downgradeFrom35to34(db); + case 35 -> downgradeFrom36to35(db); default -> throw new RuntimeException("Not implemented: downgrade to " + toVersion); } } @@ -532,4 +534,32 @@ private void downgradeFrom35to34(SQLiteDatabase db) { db.setTransactionSuccessful(); db.endTransaction(); } + + private void upgradeFrom35to36(SQLiteDatabase db) { + db.beginTransaction(); + + db.execSQL("ALTER TABLE trackpoints RENAME TO trackpoints_old"); + db.execSQL("CREATE TABLE trackpoints (_id INTEGER PRIMARY KEY AUTOINCREMENT, trackid INTEGER NOT NULL, longitude INTEGER, latitude INTEGER, time INTEGER, elevation FLOAT, accuracy FLOAT, speed FLOAT, bearing FLOAT, sensor_heartrate FLOAT, sensor_cadence FLOAT, sensor_power FLOAT, elevation_gain FLOAT, elevation_loss FLOAT, type TEXT CHECK(type IN (-2, -1, 0, 1, 3)), sensor_distance FLOAT, accuracy_vertical FLOAT, FOREIGN KEY (trackid) REFERENCES tracks(_id) ON UPDATE CASCADE ON DELETE CASCADE)"); + db.execSQL("INSERT INTO trackpoints SELECT _id, trackid, longitude, latitude, time, elevation, accuracy, speed, bearing, sensor_heartrate, sensor_cadence, sensor_power, elevation_gain, elevation_gain, type, sensor_distance, accuracy_vertical FROM trackpoints_old"); + db.execSQL("DROP TABLE trackpoints_old"); + + db.execSQL("CREATE INDEX trackpoints_trackid_index ON trackpoints(trackid)"); + + db.setTransactionSuccessful(); + db.endTransaction(); + } + + private void downgradeFrom36to35(SQLiteDatabase db) { + db.beginTransaction(); + + db.execSQL("ALTER TABLE trackpoints RENAME TO trackpoints_old"); + db.execSQL("CREATE TABLE trackpoints (_id INTEGER PRIMARY KEY AUTOINCREMENT, trackid INTEGER NOT NULL, longitude INTEGER, latitude INTEGER, time INTEGER, elevation FLOAT, accuracy FLOAT, speed FLOAT, bearing FLOAT, sensor_heartrate FLOAT, sensor_cadence FLOAT, sensor_power FLOAT, elevation_gain FLOAT, elevation_loss FLOAT, type TEXT CHECK(type IN (-2, -1, 0, 1, 2)), sensor_distance FLOAT, accuracy_vertical FLOAT, FOREIGN KEY (trackid) REFERENCES tracks(_id) ON UPDATE CASCADE ON DELETE CASCADE)"); + db.execSQL("INSERT INTO trackpoints SELECT _id, trackid, longitude, latitude, time, elevation, accuracy, speed, bearing, sensor_heartrate, sensor_cadence, sensor_power, elevation_gain, elevation_gain, type, sensor_distance, accuracy_vertical FROM trackpoints_old"); + db.execSQL("DROP TABLE trackpoints_old"); + + db.execSQL("CREATE INDEX trackpoints_trackid_index ON trackpoints(trackid)"); + + db.setTransactionSuccessful(); + db.endTransaction(); + } } diff --git a/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java b/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java index c4f9fa98f0..ef954bb0da 100644 --- a/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java +++ b/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java @@ -55,8 +55,11 @@ public enum Type { SEGMENT_START_MANUAL(-2), //Start of a segment due to user interaction (start, resume) SEGMENT_START_AUTOMATIC(-1), //Start of a segment due to too much distance from previous TrackPoint - TRACKPOINT(0), //Just GPS data and may contain BLE sensor data - SENSORPOINT(2), //Just BLE sensor data; may have speed and sensorDistance + TRACKPOINT(0), //Was created due to sensor data (may contain GPS or other BLE data) + + // Was used to distinguish the source (i.e., GPS vs BLE sensor), but this was too complicated. Everything is now a TRACKPOINT again. + @Deprecated + SENSORPOINT(2), IDLE(3), //Device became idle SEGMENT_END_MANUAL(1); //End of a segment diff --git a/src/main/java/de/dennisguse/opentracks/data/tables/TrackPointsColumns.java b/src/main/java/de/dennisguse/opentracks/data/tables/TrackPointsColumns.java index 7462c72190..5c5656c4fd 100644 --- a/src/main/java/de/dennisguse/opentracks/data/tables/TrackPointsColumns.java +++ b/src/main/java/de/dennisguse/opentracks/data/tables/TrackPointsColumns.java @@ -78,7 +78,7 @@ public interface TrackPointsColumns extends BaseColumns { + SENSOR_POWER + " FLOAT, " + ALTITUDE_GAIN + " FLOAT, " + ALTITUDE_LOSS + " FLOAT, " - + TYPE + " TEXT CHECK(type IN (-2, -1, 0, 1, 2, 3)), " + + TYPE + " TEXT CHECK(type IN (-2, -1, 0, 1, 3)), " + SENSOR_DISTANCE + " FLOAT, " + VERTICAL_ACCURACY + " FLOAT, " + "FOREIGN KEY (" + TRACKID + ") REFERENCES " + TracksColumns.TABLE_NAME + "(" + TracksColumns._ID + ") ON UPDATE CASCADE ON DELETE CASCADE" diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/CSVTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/CSVTrackExporter.java index 360e409f5b..0db17da920 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/CSVTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/CSVTrackExporter.java @@ -136,14 +136,7 @@ private void writeTrackPoints(List columns, Track track) throws Interrup while (trackPointIterator.hasNext()) { if (Thread.interrupted()) throw new InterruptedException(); - TrackPoint trackPoint = trackPointIterator.next(); - - switch (trackPoint.getType()) { - case SEGMENT_START_MANUAL, SEGMENT_END_MANUAL, SEGMENT_START_AUTOMATIC, SENSORPOINT, TRACKPOINT -> - writeTrackPoint(columns, trackPoint); - default -> - throw new RuntimeException("Exporting this TrackPoint type is not implemented: " + trackPoint.getType()); - } + writeTrackPoint(columns, trackPointIterator.next()); } } } diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java index e62750fa2d..a2354f8614 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java @@ -158,15 +158,18 @@ private void writeTrackPoints(Track track) throws InterruptedException { sensorPoints.add(trackPoint); } } - case SENSORPOINT -> sensorPoints.add(trackPoint); case TRACKPOINT -> { if (!wroteSegment) { // Might happen for older data (pre v3.15.0) writeOpenSegment(); wroteSegment = true; } - trackDistance = trackDistance.plus(writeTrackPoint(track.getZoneOffset(), trackPoint, sensorPoints, trackDistance)); - sensorPoints.clear(); + if (trackPoint.hasLocation()) { + trackDistance = trackDistance.plus(writeTrackPoint(track.getZoneOffset(), trackPoint, sensorPoints, trackDistance)); + sensorPoints.clear(); + } else { + sensorPoints.add(trackPoint); + } } default -> throw new RuntimeException("Exporting this TrackPoint type is not implemented: " + trackPoint.getType()); diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java index 0e999856b7..3de5f615a7 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java @@ -177,7 +177,7 @@ private void writeLocations(Track track) throws InterruptedException { writeCloseSegment(); wroteSegment = false; } - case SENSORPOINT, TRACKPOINT -> { + case TRACKPOINT -> { if (!wroteSegment) { // Might happen for older data (pre v3.15.0) writeOpenSegment(); diff --git a/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java b/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java index 19abd056d9..9dce6b4070 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java @@ -308,9 +308,8 @@ private void onTrackSegmentEnd() { Instant time = whenList.get(i); Location location = locationList.get(i); - TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.SENSORPOINT, time); + TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, time); if (location != null) { - trackPoint.setType(TrackPoint.Type.TRACKPOINT); trackPoint.setLocation(location); } diff --git a/src/main/java/de/dennisguse/opentracks/services/handlers/TrackPointCreator.java b/src/main/java/de/dennisguse/opentracks/services/handlers/TrackPointCreator.java index 635313055d..40b76d0038 100644 --- a/src/main/java/de/dennisguse/opentracks/services/handlers/TrackPointCreator.java +++ b/src/main/java/de/dennisguse/opentracks/services/handlers/TrackPointCreator.java @@ -81,7 +81,7 @@ public synchronized void onChange(@NonNull Location location) { * Got a new TrackPoint from Bluetooth only; contains no GPS location. */ public synchronized void onChange(@NonNull SensorDataSet unused) { - onNewTrackPoint(new TrackPoint(TrackPoint.Type.SENSORPOINT, createNow())); + onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, createNow())); } @VisibleForTesting