-
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.
Wear: more preparations for ob1 updates
- Loading branch information
Showing
10 changed files
with
178 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,8 @@ public static void sendBridgeBattery(int i) { | |
|
||
} | ||
|
||
public static void requestSensorCalibrationsUpdate() { | ||
|
||
} | ||
|
||
} |
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
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
52 changes: 52 additions & 0 deletions
52
wear/src/main/java/com/eveningoutpost/dexdrip/Models/SensorSanity.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,52 @@ | ||
package com.eveningoutpost.dexdrip.Models; | ||
|
||
import com.eveningoutpost.dexdrip.utils.DexCollectionType; | ||
|
||
/** | ||
* Created by jamorham on 02/03/2018. | ||
* | ||
* Checks for whether sensor data is within a sane range | ||
* | ||
*/ | ||
|
||
public class SensorSanity { | ||
|
||
public static final double DEXCOM_MIN_RAW = 5; // raw values below this will be treated as error | ||
public static final double DEXCOM_MAX_RAW = 1000; // raw values above this will be treated as error | ||
|
||
public static final double LIBRE_MIN_RAW = 5; // raw values below this will be treated as error | ||
|
||
private static final String TAG = "SensorSanity"; | ||
|
||
public static boolean isRawValueSane(double raw_value) { | ||
return isRawValueSane(raw_value, DexCollectionType.getDexCollectionType()); | ||
} | ||
|
||
public static boolean isRawValueSane(double raw_value, DexCollectionType type) { | ||
// passes by default! | ||
boolean state = true; | ||
|
||
// checks for each type of data source | ||
|
||
if (DexCollectionType.hasDexcomRaw(type)) { | ||
if (raw_value != BgReading.SPECIAL_G5_PLACEHOLDER) { | ||
if (raw_value < DEXCOM_MIN_RAW) state = false; | ||
else if (raw_value > DEXCOM_MAX_RAW) state = false; | ||
} | ||
|
||
} else if (DexCollectionType.hasLibre(type)) { | ||
if (raw_value < LIBRE_MIN_RAW) state = false; | ||
} | ||
|
||
if (!state) { | ||
if (JoH.ratelimit("sanity-failure", 20)) { | ||
final String msg = "Sensor Raw Data Sanity Failure: " + raw_value; | ||
UserError.Log.e(TAG, msg); | ||
JoH.static_toast_long(msg); | ||
} | ||
} | ||
|
||
return state; | ||
} | ||
|
||
} |
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
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
87 changes: 87 additions & 0 deletions
87
wear/src/main/java/com/eveningoutpost/dexdrip/utils/SqliteRejigger.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,87 @@ | ||
package com.eveningoutpost.dexdrip.utils; | ||
|
||
// created by jamorham | ||
|
||
import android.database.Cursor; | ||
import android.database.SQLException; | ||
import android.database.sqlite.SQLiteDatabase; | ||
|
||
import com.activeandroid.Cache; | ||
import com.eveningoutpost.dexdrip.Models.UserError; | ||
|
||
import lombok.NonNull; | ||
|
||
|
||
/* Wouldn't it be nice if you could search and replace inside an sqlite schema? | ||
* That is what the SqliteRejigger is for! | ||
*/ | ||
|
||
public class SqliteRejigger { | ||
|
||
private static final String TAG = SqliteRejigger.class.getSimpleName(); | ||
private static final boolean d = false; | ||
|
||
public static synchronized boolean rejigSchema(@NonNull String table_name, @NonNull String search, @NonNull String replace) { | ||
|
||
final String temp_table = table_name + "_temp"; | ||
|
||
final String existing_schema = getSchema(table_name); | ||
|
||
if (d) UserError.Log.d(TAG, existing_schema); | ||
|
||
if (existing_schema.contains(search)) { | ||
final String sql = | ||
"PRAGMA foreign_keys=off;\n" + | ||
"BEGIN TRANSACTION;\n" + | ||
"DROP TABLE IF EXISTS " + temp_table + ";\n" + | ||
"ALTER TABLE " + table_name + " RENAME TO " + temp_table + ";\n" + | ||
existing_schema.replace(search, replace).replace("CREATE INDEX index_", "CREATE INDEX index__") + | ||
"INSERT INTO " + table_name + " SELECT * FROM " + temp_table + ";\n" + | ||
"DROP TABLE " + temp_table + ";\n" + | ||
"COMMIT;\n" + | ||
"PRAGMA foreign_keys=on;\n"; | ||
if (d) UserError.Log.d(TAG, sql); | ||
try { | ||
executeBatchSQL(sql); | ||
UserError.Log.d(TAG, "Rejig probably successful for " + table_name + " " + replace); | ||
return true; | ||
} catch (SQLException e) { | ||
UserError.Log.e(TAG, "Unable to rejig " + e + " on " + table_name + " " + replace); | ||
return false; | ||
} | ||
|
||
} else { | ||
UserError.Log.d(TAG, search + " not found in schema for " + table_name + " presumably this patch has already been applied"); | ||
return false; | ||
} | ||
|
||
} | ||
|
||
private static void executeBatchSQL(String batch) throws SQLException { | ||
final String[] statements = batch.split("\n"); | ||
final SQLiteDatabase db = Cache.openDatabase(); | ||
db.beginTransaction(); | ||
try { | ||
for (String query : statements) { | ||
db.execSQL(query); | ||
} | ||
db.setTransactionSuccessful(); | ||
} finally { | ||
db.endTransaction(); | ||
} | ||
} | ||
|
||
private static String getSchema(String table_name) { | ||
final StringBuilder sb = new StringBuilder(); | ||
final Cursor cursor = Cache.openDatabase().rawQuery("select sql from sqlite_master where type in ('table', 'index') and tbl_name = ?", new String[]{table_name}); | ||
while (cursor.moveToNext()) { | ||
final String line = cursor.getString(0); | ||
if (line != null) { | ||
sb.append(line); | ||
sb.append(";\n"); | ||
} | ||
} | ||
cursor.close(); | ||
return sb.toString(); | ||
} | ||
} |
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