use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip-plus by jamorham.
the class WatchUpdaterService method sendSensorData.
private boolean sendSensorData() {
// KS
try {
if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
googleApiClient.connect();
}
if (googleApiClient != null) {
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
if (wear_integration) {
DataMap dataMap = new DataMap();
Log.d(TAG, "Sensor sendSensorData uuid=" + sensor.uuid + " started_at=" + sensor.started_at + " active=" + Sensor.isActive() + " battery=" + sensor.latest_battery_level + " location=" + sensor.sensor_location + " stopped_at=" + sensor.stopped_at);
String json = sensor.toS();
Log.d(TAG, "dataMap sendSensorData GSON: " + json);
// MOST IMPORTANT LINE FOR TIMESTAMP
dataMap.putLong("time", new Date().getTime());
// KS
dataMap.putString("dex_txid", mPrefs.getString("dex_txid", "ABCDEF"));
dataMap.putLong("started_at", sensor.started_at);
dataMap.putString("uuid", sensor.uuid);
dataMap.putInt("latest_battery_level", sensor.latest_battery_level);
dataMap.putString("sensor_location", sensor.sensor_location);
new SendToDataLayerThread(WEARABLE_SENSOR_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
return true;
}
} else
Log.e(TAG, "sendSensorData current sensor is null!");
} else {
Log.e(TAG, "sendSensorData No connection to wearable available for send Sensor!");
return false;
}
} catch (NullPointerException e) {
Log.e(TAG, "Nullpointer exception in sendWearCalibrationData: " + e);
return false;
}
return true;
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip-plus by jamorham.
the class Home method naturalLanguageRecognition.
private void naturalLanguageRecognition(String allWords) {
if (searchWords == null) {
Toast.makeText(getApplicationContext(), "Word lexicon not loaded!", Toast.LENGTH_LONG).show();
return;
}
Log.d(TAG, "Processing speech input allWords: " + allWords);
thisuuid = "";
int end = allWords.indexOf(" uuid ");
if (end > 0) {
thisuuid = (end > 0 ? allWords.substring(0, end) : "");
allWords = allWords.substring(end + 6, allWords.length());
}
allWords = allWords.trim();
// fix real times
allWords = allWords.replaceAll(":", ".");
// fix like 22mm
allWords = allWords.replaceAll("(\\d)([a-zA-Z])", "$1 $2");
// fix multi number order like blood 3.622 grams
allWords = allWords.replaceAll("([0-9]\\.[0-9])([0-9][0-9])", "$1 $2");
allWords = allWords.toLowerCase();
Log.d(TAG, "Processing speech input allWords second: " + allWords + " UUID: " + thisuuid);
if (allWords.contentEquals("delete last treatment") || allWords.contentEquals("cancel last treatment") || allWords.contentEquals("erase last treatment")) {
Treatments.delete_last(true);
updateCurrentBgInfo("delete last treatment");
} else if ((allWords.contentEquals("delete all treatments")) || (allWords.contentEquals("delete all treatment"))) {
Treatments.delete_all(true);
updateCurrentBgInfo("delete all treatment");
} else if (allWords.contentEquals("delete last calibration") || allWords.contentEquals("clear last calibration")) {
Calibration.clearLastCalibration();
} else if (allWords.contentEquals("force google reboot")) {
SdcardImportExport.forceGMSreset();
} else if (allWords.contentEquals("enable engineering mode")) {
Pref.setBoolean("engineering_mode", true);
JoH.static_toast(getApplicationContext(), "Engineering mode enabled - be careful", Toast.LENGTH_LONG);
} else if (get_engineering_mode() && allWords.contentEquals("enable fake data source")) {
Pref.setString(DexCollectionType.DEX_COLLECTION_METHOD, DexCollectionType.Mock.toString());
JoH.static_toast_long("YOU ARE NOW USING FAKE DATA!!!");
} else if (allWords.contentEquals("reset heart rate sync")) {
PersistentStore.setLong("nightscout-rest-heartrate-synced-time", 0);
JoH.static_toast_long("Cleared heart rate sync data");
} else if (allWords.contentEquals("reset step count sync")) {
PersistentStore.setLong("nightscout-rest-steps-synced-time", 0);
JoH.static_toast_long("Cleared step count sync data");
} else if (allWords.contentEquals("reset motion count sync")) {
PersistentStore.setLong("nightscout-rest-motion-synced-time", 0);
JoH.static_toast_long("Cleared motion count sync data");
} else if (allWords.contentEquals("vehicle mode test")) {
ActivityRecognizedService.spoofActivityRecogniser(mActivity, JoH.tsl() + "^" + 0);
staticRefreshBGCharts();
} else if (allWords.contentEquals("vehicle mode quit")) {
ActivityRecognizedService.spoofActivityRecogniser(mActivity, JoH.tsl() + "^" + 3);
staticRefreshBGCharts();
} else if (allWords.contentEquals("vehicle mode walk")) {
ActivityRecognizedService.spoofActivityRecogniser(mActivity, JoH.tsl() + "^" + 2);
staticRefreshBGCharts();
} else if (allWords.contentEquals("delete all glucose data")) {
deleteAllBG(null);
LibreAlarmReceiver.clearSensorStats();
} else if (allWords.contentEquals("delete selected glucose meter") || allWords.contentEquals("delete selected glucose metre")) {
Pref.setString("selected_bluetooth_meter_address", "");
} else if (allWords.contentEquals("delete all finger stick data") || (allWords.contentEquals("delete all fingerstick data"))) {
BloodTest.cleanup(-100000);
} else if (allWords.contentEquals("delete all persistent store")) {
SdcardImportExport.deletePersistentStore();
} else if (allWords.contentEquals("delete uploader queue")) {
UploaderQueue.emptyQueue();
} else if (allWords.contentEquals("clear battery warning")) {
try {
final Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
sensor.latest_battery_level = 0;
sensor.save();
}
} catch (Exception e) {
// do nothing
}
}
// reset parameters for new speech
watchkeypad = false;
watchkeypadset = false;
glucoseset = false;
insulinset = false;
carbsset = false;
timeset = false;
thisnumber = -1;
thisword = "";
final String[] wordsArray = allWords.split(" ");
for (int i = 0; i < wordsArray.length; i++) {
// per word in input stream
try {
double thisdouble = Double.parseDouble(wordsArray[i]);
// if no exception
thisnumber = thisdouble;
handleWordPair();
} catch (NumberFormatException nfe) {
// detection of number or not
final String result = classifyWord(wordsArray[i]);
if (result != null)
thisword = result;
handleWordPair();
if (thisword.equals("note")) {
String note_text = "";
for (int j = i + 1; j < wordsArray.length; j++) {
if (note_text.length() > 0)
note_text += " ";
note_text += wordsArray[j];
}
if (note_text.length() > 0) {
// TODO respect historic timeset?
Treatments.create_note(note_text, JoH.tsl());
staticRefreshBGCharts();
// don't process any more
break;
}
}
}
}
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip-plus by jamorham.
the class ListenerService method syncSensorData.
private void syncSensorData(DataMap dataMap, Context context) {
// KS
Log.d(TAG, "syncSensorData");
if (dataMap != null) {
String uuid = dataMap.getString("uuid");
Log.d(TAG, "syncSensorData add Sensor for uuid=" + uuid);
long started_at = dataMap.getLong("started_at");
Integer latest_battery_level = dataMap.getInt("latest_battery_level");
String sensor_location = dataMap.getString("sensor_location");
// ensure database has already been initialized
Sensor.InitDb(context);
if (uuid != null && !uuid.isEmpty()) {
Log.d(TAG, "syncSensorData add Sensor for uuid=" + uuid + " timestamp=" + started_at + " timeString=" + JoH.dateTimeText(started_at));
Sensor sensor = Sensor.getByUuid(uuid);
if (sensor == null) {
Log.d(TAG, "syncSensorData createUpdate new Sensor...");
Sensor.createUpdate(started_at, 0, latest_battery_level, sensor_location, uuid);
Sensor newsensor = Sensor.currentSensor();
if (newsensor != null) {
Log.d(TAG, "syncSensorData createUpdate Sensor with uuid=" + uuid + " started at=" + started_at);
} else
Log.d(TAG, "syncSensorData Failed to createUpdate new Sensor for uuid=" + uuid);
} else
Log.d(TAG, "syncSensorData Sensor already exists with uuid=" + uuid);
}
}
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip-plus by jamorham.
the class ListenerService method syncCalibrationData.
private synchronized void syncCalibrationData(DataMap dataMap, Context context) {
// KS
Log.d(TAG, "syncCalibrationData");
boolean changed = false;
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
if (entries != null) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
Log.d(TAG, "syncCalibrationData add Calibration Table entries count=" + entries.size());
// ensure database has already been initialized
Sensor.InitDb(context);
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
for (DataMap entry : entries) {
if (entry != null) {
String bgrecord = entry.getString("bgs");
if (bgrecord != null) {
Calibration bgData = gson.fromJson(bgrecord, Calibration.class);
Calibration exists = Calibration.findByUuid(bgData.uuid);
bgData.sensor = sensor;
if (exists != null) {
Log.d(TAG, "syncCalibrationData Calibration exists for uuid=" + bgData.uuid + " bg=" + bgData.bg + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
if (exists.slope != bgData.slope || exists.slope_confidence != bgData.slope_confidence || exists.timestamp != bgData.timestamp || exists.bg != bgData.bg) {
// slope* indicates if shown on graph
changed = true;
}
exists.adjusted_raw_value = bgData.adjusted_raw_value;
exists.bg = bgData.bg;
exists.check_in = bgData.check_in;
exists.distance_from_estimate = bgData.distance_from_estimate;
exists.estimate_bg_at_time_of_calibration = bgData.estimate_bg_at_time_of_calibration;
exists.estimate_raw_at_time_of_calibration = bgData.estimate_raw_at_time_of_calibration;
exists.first_decay = bgData.first_decay;
exists.first_intercept = bgData.first_intercept;
exists.first_scale = bgData.first_scale;
exists.first_slope = bgData.first_slope;
exists.intercept = bgData.intercept;
exists.possible_bad = bgData.possible_bad;
exists.raw_timestamp = bgData.raw_timestamp;
exists.raw_value = bgData.raw_value;
exists.second_decay = bgData.second_decay;
exists.second_intercept = bgData.second_intercept;
exists.second_scale = bgData.second_scale;
exists.second_slope = bgData.second_slope;
exists.sensor = sensor;
exists.sensor_age_at_time_of_estimation = bgData.sensor_age_at_time_of_estimation;
exists.sensor_confidence = bgData.sensor_confidence;
exists.sensor_uuid = bgData.sensor_uuid;
exists.slope = bgData.slope;
exists.slope_confidence = bgData.slope_confidence;
exists.timestamp = bgData.timestamp;
exists.save();
} else {
changed = true;
bgData.save();
// final boolean adjustPast = mPrefs.getBoolean("rewrite_history", true);
Log.d(TAG, "syncCalibrationData Calibration does not exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
// Calibration.adjustRecentBgReadings(adjustPast ? 30 : 2);
}
exists = Calibration.findByUuid(bgData.uuid);
if (exists != null)
Log.d(TAG, "syncCalibrationData Calibration GSON saved BG: " + exists.toS());
else
Log.d(TAG, "syncCalibrationData Calibration GSON NOT saved");
}
}
}
} else {
Log.d(TAG, "syncCalibrationData No Active Sensor!! Request WEARABLE_INITDB_PATH");
sendData(WEARABLE_INITDB_PATH, null);
}
if (changed) {
showTreatments(context, "cals");
}
}
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip-plus by jamorham.
the class ListenerService method syncBgData.
private synchronized void syncBgData(DataMap dataMap, Context context) {
// KS
Log.d(TAG, "syncBGData");
boolean changed = false;
int battery = dataMap.getInt("battery");
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
Log.d(TAG, "syncBGData add BgReading Table battery=" + battery);
if (entries != null) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
Log.d(TAG, "syncBGData add BgReading Table entries count=" + entries.size());
// ensure database has already been initialized
Sensor.InitDb(context);
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
for (DataMap entry : entries) {
if (entry != null) {
String bgrecord = entry.getString("bgs");
if (bgrecord != null) {
BgReading bgData = gson.fromJson(bgrecord, BgReading.class);
/* // TODO this is a hack to use display glucose but it is incomplete regarding delta
if (bgData.dg_mgdl > 0) {
bgData.calculated_value = bgData.dg_mgdl;
bgData.calculated_value_slope = bgData.dg_slope;
// TODO delta missing???
}
*/
BgReading exists = BgReading.getForTimestampExists(bgData.timestamp);
exists = exists != null ? exists : BgReading.findByUuid(bgData.uuid);
String calibrationUuid = entry.getString("calibrationUuid");
if (exists != null) {
Log.d(TAG, "syncBGData BG already exists for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
Log.d(TAG, "syncBGData exists timeString=" + JoH.dateTimeText(exists.timestamp) + " exists.calibration.uuid=" + exists.calibration.uuid + " exists=" + exists.toS());
exists.filtered_calculated_value = bgData.filtered_calculated_value;
exists.calculated_value = bgData.calculated_value;
exists.hide_slope = bgData.hide_slope;
exists.filtered_data = bgData.filtered_data;
exists.raw_data = bgData.raw_data;
exists.raw_calculated = bgData.raw_calculated;
exists.calculated_value_slope = bgData.calculated_value_slope;
exists.age_adjusted_raw_value = bgData.age_adjusted_raw_value;
exists.calibration_flag = bgData.calibration_flag;
exists.ignoreForStats = bgData.ignoreForStats;
exists.time_since_sensor_started = bgData.time_since_sensor_started;
exists.ra = bgData.ra;
exists.rb = bgData.rb;
exists.rc = bgData.rc;
exists.a = bgData.a;
exists.b = bgData.b;
exists.c = bgData.c;
exists.noise = bgData.noise;
exists.time_since_sensor_started = bgData.time_since_sensor_started;
Calibration calibration = Calibration.byuuid(calibrationUuid);
calibration = calibration != null ? calibration : Calibration.byuuid(exists.calibration_uuid);
if (calibration != null) {
exists.calibration = calibration;
exists.calibration_uuid = calibration.uuid;
exists.sensor = sensor;
exists.sensor_uuid = sensor.uuid;
if (exists.calculated_value != bgData.calculated_value) {
changed = true;
}
exists.save();
} else {
Log.e(TAG, "syncBGData existing BgReading calibrationUuid not found by byuuid; calibrationUuid=" + calibrationUuid + " bgData.calibration_uuid=" + bgData.calibration_uuid + " bgData.uuid=" + bgData.uuid + " timeString=" + JoH.dateTimeText(bgData.timestamp));
}
} else {
Calibration calibration = Calibration.byuuid(calibrationUuid);
calibration = calibration != null ? calibration : Calibration.byuuid(bgData.calibration_uuid);
if (calibration != null) {
Log.d(TAG, "syncBGData add BG; does NOT exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
bgData.calibration = calibration;
bgData.calibration_uuid = calibration.uuid;
bgData.sensor = sensor;
bgData.sensor_uuid = sensor.uuid;
changed = true;
bgData.save();
} else {
Log.e(TAG, "syncBGData new BgReading calibrationUuid not found by byuuid; calibrationUuid=" + calibrationUuid + " bgData.calibration_uuid=" + bgData.calibration_uuid + " bgData.uuid=" + bgData.uuid + " timeString=" + JoH.dateTimeText(bgData.timestamp));
}
}
}
}
}
} else {
Log.d(TAG, "syncBGData No Active Sensor!! Request WEARABLE_INITDB_PATH");
sendData(WEARABLE_INITDB_PATH, null);
}
}
if (changed) {
// otherwise, wait for doBackground ACTION_RESEND
Log.d(TAG, "syncBGData BG data has changed, refresh watchface, phone battery=" + battery);
resendData(getApplicationContext(), battery);
CustomComplicationProviderService.refresh();
} else
Log.d(TAG, "syncBGData BG data has NOT changed, do not refresh watchface, phone battery=" + battery);
}
Aggregations