mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-30 22:12:55 +01:00
Allow to change stored samples converting only certain old types
This commit is contained in:
parent
b1a93c430d
commit
a49335fa67
@ -275,6 +275,24 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind, SampleProvider provider) {
|
||||
try (SQLiteDatabase db = this.getReadableDatabase()) {
|
||||
String sql = "UPDATE " + TABLE_GBACTIVITYSAMPLES + " SET " + KEY_TYPE + "= ? WHERE "
|
||||
+ KEY_TYPE + " = ? AND "
|
||||
+ KEY_PROVIDER + " = ? AND "
|
||||
+ KEY_TIMESTAMP + " >= ? AND " + KEY_TIMESTAMP + " < ? ;"; //do not use BETWEEN because the range is inclusive in that case!
|
||||
|
||||
SQLiteStatement statement = db.compileStatement(sql);
|
||||
statement.bindLong(1, toKind);
|
||||
statement.bindLong(2, fromKind);
|
||||
statement.bindLong(3, provider.getID());
|
||||
statement.bindLong(4, timestampFrom);
|
||||
statement.bindLong(5, timestampTo);
|
||||
statement.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fetchLatestTimestamp(SampleProvider provider) {
|
||||
try (SQLiteDatabase db = this.getReadableDatabase()) {
|
||||
|
@ -32,6 +32,8 @@ public interface DBHandler {
|
||||
|
||||
void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider);
|
||||
|
||||
void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind, SampleProvider provider);
|
||||
|
||||
int fetchLatestTimestamp(SampleProvider provider);
|
||||
|
||||
}
|
||||
|
@ -74,9 +74,12 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
||||
for (SleepRecord84 sleepRecord : sleepRecords) {
|
||||
if (latestTimestamp < (sleepRecord.timestampStart + sleepRecord.durationSeconds))
|
||||
return false;
|
||||
int activityType = sleepRecord.type == 2 ? sampleProvider.toRawActivityKind(ActivityKind.TYPE_DEEP_SLEEP) : sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP);
|
||||
if (sleepRecord.type == 2) {
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.timestampStart, (sleepRecord.timestampStart + sleepRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_DEEP_SLEEP), sampleProvider);
|
||||
} else {
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.timestampStart, (sleepRecord.timestampStart + sleepRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
||||
}
|
||||
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.timestampStart, (sleepRecord.timestampStart + sleepRecord.durationSeconds), activityType, sampleProvider);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.debug(ex.getMessage());
|
||||
@ -125,7 +128,7 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
||||
for (SleepRecord83 sleepRecord : sleepRecords) {
|
||||
if (latestTimestamp < sleepRecord.bedTimeEnd)
|
||||
return false;
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.debug(ex.getMessage());
|
||||
|
Loading…
Reference in New Issue
Block a user