-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Support for Pebble2 and Pebble Health
- Loading branch information
Showing
12 changed files
with
502 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/eveningoutpost/dexdrip/Models/HeartRate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.eveningoutpost.dexdrip.Models; | ||
|
||
import android.provider.BaseColumns; | ||
|
||
import com.activeandroid.Model; | ||
import com.activeandroid.annotation.Column; | ||
import com.activeandroid.annotation.Table; | ||
import com.activeandroid.query.Select; | ||
import com.activeandroid.util.SQLiteUtils; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.annotations.Expose; | ||
|
||
/** | ||
* Created by jamorham on 01/11/2016. | ||
*/ | ||
|
||
|
||
@Table(name = "HeartRate", id = BaseColumns._ID) | ||
public class HeartRate extends Model { | ||
|
||
private static boolean patched = false; | ||
private final static String TAG = "HeartRate"; | ||
|
||
@Expose | ||
@Column(name = "timestamp", unique = true, onUniqueConflicts = Column.ConflictAction.IGNORE) | ||
public long timestamp; | ||
|
||
@Expose | ||
@Column(name = "bpm") | ||
public int bpm; | ||
|
||
|
||
// patches and saves | ||
public Long saveit() { | ||
fixUpTable(); | ||
return save(); | ||
} | ||
|
||
public String toS() { | ||
final Gson gson = new GsonBuilder() | ||
.excludeFieldsWithoutExposeAnnotation() | ||
.create(); | ||
return gson.toJson(this); | ||
} | ||
|
||
public static HeartRate last() { | ||
try { | ||
return new Select() | ||
.from(HeartRate.class) | ||
.orderBy("timestamp desc") | ||
.executeSingle(); | ||
} catch (android.database.sqlite.SQLiteException e) { | ||
fixUpTable(); | ||
return null; | ||
} | ||
} | ||
|
||
// create the table ourselves without worrying about model versioning and downgrading | ||
private static void fixUpTable() { | ||
if (patched) return; | ||
String[] patchup = { | ||
"CREATE TABLE HeartRate (_id INTEGER PRIMARY KEY AUTOINCREMENT);", | ||
"ALTER TABLE HeartRate ADD COLUMN timestamp INTEGER;", | ||
"ALTER TABLE HeartRate ADD COLUMN bpm INTEGER;", | ||
"CREATE UNIQUE INDEX index_HeartRate_timestamp on HeartRate(timestamp);"}; | ||
|
||
for (String patch : patchup) { | ||
try { | ||
SQLiteUtils.execSql(patch); | ||
// UserError.Log.e(TAG, "Processed patch should not have succeeded!!: " + patch); | ||
} catch (Exception e) { | ||
// UserError.Log.d(TAG, "Patch: " + patch + " generated exception as it should: " + e.toString()); | ||
} | ||
} | ||
patched = true; | ||
} | ||
} | ||
|
||
|
||
|
128 changes: 128 additions & 0 deletions
128
app/src/main/java/com/eveningoutpost/dexdrip/Models/PebbleMovement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.eveningoutpost.dexdrip.Models; | ||
|
||
import android.provider.BaseColumns; | ||
|
||
import com.activeandroid.Model; | ||
import com.activeandroid.annotation.Column; | ||
import com.activeandroid.annotation.Table; | ||
import com.activeandroid.query.Select; | ||
import com.activeandroid.util.SQLiteUtils; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.annotations.Expose; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by jamorham on 01/11/2016. | ||
*/ | ||
|
||
|
||
@Table(name = "PebbleMovement", id = BaseColumns._ID) | ||
public class PebbleMovement extends Model { | ||
|
||
private static boolean patched = false; | ||
private final static String TAG = "PebbleMovement"; | ||
|
||
@Expose | ||
@Column(name = "timestamp", unique = true, onUniqueConflicts = Column.ConflictAction.IGNORE) | ||
public long timestamp; | ||
|
||
@Expose | ||
@Column(name = "metric") | ||
public int metric; | ||
|
||
|
||
// patches and saves | ||
public Long saveit() { | ||
fixUpTable(); | ||
return save(); | ||
} | ||
|
||
public String toS() { | ||
final Gson gson = new GsonBuilder() | ||
.excludeFieldsWithoutExposeAnnotation() | ||
.create(); | ||
return gson.toJson(this); | ||
} | ||
|
||
|
||
// static methods | ||
|
||
public static PebbleMovement last() { | ||
try { | ||
return new Select() | ||
.from(PebbleMovement.class) | ||
.orderBy("timestamp desc") | ||
.executeSingle(); | ||
} catch (android.database.sqlite.SQLiteException e) { | ||
fixUpTable(); | ||
return null; | ||
} | ||
} | ||
|
||
public static List<PebbleMovement> latestForGraph(int number, double startTime) { | ||
return latestForGraph(number, (long) startTime, Long.MAX_VALUE); | ||
} | ||
|
||
public static List<PebbleMovement> latestForGraph(int number, long startTime) { | ||
return latestForGraph(number, startTime, Long.MAX_VALUE); | ||
} | ||
|
||
public static List<PebbleMovement> latestForGraph(int number, long startTime, long endTime) { | ||
return new Select() | ||
.from(PebbleMovement.class) | ||
.where("timestamp >= " + Math.max(startTime, 0)) | ||
.where("timestamp <= " + endTime) | ||
.orderBy("timestamp asc") // warn asc! | ||
.limit(number) | ||
.execute(); | ||
} | ||
|
||
// expects pre-sorted in asc order? | ||
public static List<PebbleMovement> deltaListFromMovementList(List<PebbleMovement> mList) { | ||
int last_metric = -1; | ||
int temp_metric = -1; | ||
for (PebbleMovement pm : mList) { | ||
// first item in list | ||
if (last_metric == -1) { | ||
last_metric = pm.metric; | ||
pm.metric = 0; | ||
} else { | ||
// normal incrementing calculate delta | ||
if (pm.metric >= last_metric) { | ||
temp_metric = pm.metric - last_metric; | ||
last_metric = pm.metric; | ||
pm.metric = temp_metric; | ||
} else { | ||
last_metric = pm.metric; | ||
} | ||
} | ||
} | ||
return mList; | ||
} | ||
|
||
|
||
// create the table ourselves without worrying about model versioning and downgrading | ||
private static void fixUpTable() { | ||
if (patched) return; | ||
String[] patchup = { | ||
"CREATE TABLE PebbleMovement (_id INTEGER PRIMARY KEY AUTOINCREMENT);", | ||
"ALTER TABLE PebbleMovement ADD COLUMN timestamp INTEGER;", | ||
"ALTER TABLE PebbleMovement ADD COLUMN metric INTEGER;", | ||
"CREATE UNIQUE INDEX index_PebbleMovement_timestamp on PebbleMovement(timestamp);"}; | ||
|
||
for (String patch : patchup) { | ||
try { | ||
SQLiteUtils.execSql(patch); | ||
// UserError.Log.e(TAG, "Processed patch should not have succeeded!!: " + patch); | ||
} catch (Exception e) { | ||
// UserError.Log.d(TAG, "Patch: " + patch + " generated exception as it should: " + e.toString()); | ||
} | ||
} | ||
patched = true; | ||
} | ||
} | ||
|
||
|
||
|
Oops, something went wrong.