Skip to content

Commit

Permalink
Idle: introduced TrackPoint for marking idle.
Browse files Browse the repository at this point in the history
Part of #1187.
  • Loading branch information
dennisguse committed Aug 8, 2023
1 parent 8bc781a commit c69f1e1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CustomSQLiteOpenHelper extends SQLiteOpenHelper {

private static final String TAG = CustomSQLiteOpenHelper.class.getSimpleName();

private static final int DATABASE_VERSION = 34;
private static final int DATABASE_VERSION = 35;

public CustomSQLiteOpenHelper(Context context) {
this(context, ((Startup) context.getApplicationContext()).getDatabaseName());
Expand Down Expand Up @@ -72,6 +72,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
case 32 -> upgradeFrom31to32(db);
case 33 -> upgradeFrom32to33(db);
case 34 -> upgradeFrom33to34(db);
case 35 -> upgradeFrom34to35(db);
default -> throw new RuntimeException("Not implemented: upgrade to " + toVersion);
}
}
Expand All @@ -93,6 +94,7 @@ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
case 31 -> downgradeFrom32to31(db);
case 32 -> downgradeFrom33to32(db);
case 33 -> downgradeFrom34to33(db);
case 34 -> downgradeFrom35to34(db);
default -> throw new RuntimeException("Not implemented: downgrade to " + toVersion);
}
}
Expand Down Expand Up @@ -493,7 +495,7 @@ private void downgradeFrom34to33(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)), sensor_distance FLOAT, FOREIGN KEY (trackid) REFERENCES tracks(_id) ON UPDATE CASCADE ON DELETE CASCADE)");
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, 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 FROM trackpoints_old");
db.execSQL("DROP TABLE trackpoints_old");

Expand All @@ -502,4 +504,32 @@ private void downgradeFrom34to33(SQLiteDatabase db) {
db.setTransactionSuccessful();
db.endTransaction();
}

private void upgradeFrom34to35(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, 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 downgradeFrom35to34(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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum Type {
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
IDLE(3), //Device became idle

SEGMENT_END_MANUAL(1); //End of a segment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)), "
+ TYPE + " TEXT CHECK(type IN (-2, -1, 0, 1, 2, 3)), "
+ SENSOR_DISTANCE + " FLOAT, "
+ VERTICAL_ACCURACY + " FLOAT, "
+ "FOREIGN KEY (" + TRACKID + ") REFERENCES " + TracksColumns.TABLE_NAME + "(" + TracksColumns._ID + ") ON UPDATE CASCADE ON DELETE CASCADE"
Expand Down

0 comments on commit c69f1e1

Please sign in to comment.